Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

fack.hpp

Go to the documentation of this file.
00001 // Copyright 2004, 2005 Maurizio Colucci.  
00002 //
00003 // This file is part of FACK.  
00004 //
00005 // FACK is free software; you can redistribute it and/or modify it
00006 // under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // FACK is distributed in the hope that it will be useful, but WITHOUT
00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00012 // or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
00013 // License for more details. 
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Foobar; if not, write to the Free Software Foundation,
00017 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018 
00019 #ifndef fack_hpp_already_included
00020 #define fack_hpp_already_included
00021  
00022 #include <SDL.h>  
00023 #include <SDL_image.h>
00024 #include <boost/shared_ptr.hpp>
00025 #include <list>
00026 #include <vector>
00027 #include <string>
00028 #include <map>
00029 #include <math.h>
00030 #include <set>
00031 #include <boost/variant.hpp>
00032 #include <iostream> 
00033 #include <sstream>
00034 #include <fstream>
00035 
00036 #include <guichan.hpp>
00037 #include <guichan/sdl.hpp>
00038 
00039 using boost::shared_ptr;
00040 using std::list;
00041 using std::vector;
00042 using std::string;
00043 using std::ofstream;
00044 using std::ostream;
00045 using std::istream;
00046 using std::ifstream;
00047 
00048 using std::pair;
00049 using std::make_pair;
00050 using std::set;
00051 using std::map;
00052 using std::cout;
00053 using std::cerr;
00054 using std::endl;
00055 using boost::variant;
00056 
00057 using boost::get;
00058 using boost::dynamic_pointer_cast;
00059 
00060 #define pt shared_ptr
00061 #define NEW(x) pt_of(new x)
00062 
00063 #define MATCH_IN_ANY_ORDER(i1, v1, i2, v2) ((i1==v1 && i2 == v2) || (i1==v2 && i2 ==v1))
00064 
00065 
00066 
00078 template <class T>
00079 pt<T>
00080 pt_of(T* t){
00081     return pt<T>(t);
00082 }
00083 
00084 
00085 
00087 #define foreach(i, l)  for((i) = (l).begin(); (i) != (l).end(); (i)++)
00088 
00089 
00090 
00091 
00099 #define setof(X, L, P, OUT)  OUT.clear(); for(X = L.begin(); X != L.end(); X++) { if(P){ OUT.push_back(*X);}}
00100 
00101 
00102 
00110 #define setof_(M, X, L, P, OUT)  OUT.clear(); for(X = L.begin(); X != L.end(); X++) { if(P){ OUT.push_back(M);}}
00111 
00112 
00113 
00114 SDL_Rect
00115 create_rect(
00116     int x1, int y2, int x2, int y2);
00117 
00118 template<class T, class I>
00119 bool 
00120 pt_cast(pt<I> i, pt<T> & i2){
00121     i2 = dynamic_pointer_cast<T>(i);
00122     return i2 != 0;
00123 }
00124 
00125 
00126 
00127 template<class T, class V>
00128 bool 
00129 var_cast(V i, T & i2){
00130     if (typeid(T) == i.type()){
00131         i2 = get<T>(i);
00132         return true;
00133     }
00134     else{
00135         return false;
00136     }
00137 }
00138 
00139 
00140 
00141 
00142 
00145 template<class T>
00146 typename T::value_type 
00147 min(const T & l){
00148     // BEGIN decl.
00149     typename T::const_iterator i;
00150     typename T::value_type smallest;
00151     // END
00152     smallest = *l.begin();
00153     foreach(i, l){
00154         if ( *i  <  smallest){
00155             smallest = *i;}}
00156     return smallest;
00157 }
00158             
00161 template<class T>
00162 typename T::value_type 
00163 max(const T & l){
00164     // BEGIN decl.
00165     typename T::const_iterator i;
00166     typename T::value_type biggest;
00167     // END
00168     biggest = l.front();
00169     foreach(i, l){
00170         if ( *i  >  biggest){
00171             biggest = *i;}}
00172     return biggest;
00173 }
00174 
00177 template<class Map>
00178 typename Map::mapped_type
00179 map_get(const Map & m, typename Map::key_type i)
00180 {
00181     // BEGIN decl
00182     typename Map::const_iterator x;
00183     // END
00184 
00185     x = m.find(i);
00186     assert(x != m.end());
00187     return x->second;
00188 }
00189 
00190 
00191 
00192 
00206 template<class T>
00207 class seq_list : public list<T>{
00208     public:
00209         seq_list<T>& 
00210         operator <<(T item)
00211         {
00212             push_back(item);
00213             return *this;
00214         }
00215 
00216 };
00217 
00218 
00221 template<class T>
00222 seq_list<T>
00223 ulist(T first_el)
00224 {
00225     seq_list<T> ret;
00226     ret << first_el;
00227     return ret;
00228 }
00229 
00230 
00233 template<class T>
00234 pt<vector<typename T::value_type> >
00235 vector_of(const T & l)
00236 {
00237     // BEGIN decl
00238     pt<vector<typename T::value_type> > ret;
00239     typename T::const_iterator i;
00240     int x;
00241     // END
00242   
00243     ret = pt_of(new vector<typename T::value_type>());
00244     ret->resize(l.size());
00245     for(x = 0, i = l.begin(); i != l.end(); x++, i++){
00246         (*ret)[x] = *i;}
00247     return ret;
00248 }
00249 
00250     
00251 template<class T>
00252 pt<set<typename T::value_type> >
00253 set_of(const T & l)
00254 {
00255     // BEGIN decl
00256     pt<set<typename T::value_type> > ret;
00257     typename T::const_iterator i;
00258     int x;
00259     // END
00260 
00261     ret = pt_of(new set<typename T::value_type>());
00262     for( i = l.begin(); i != l.end(); x++, i++)
00263     {
00264         ret->insert(*i);
00265     }
00266     return ret;
00267 }
00268 
00269     
00270 
00272 template<class Set> 
00273 bool 
00274 in( typename Set::key_type i, 
00275     const Set & s)
00276 {
00277     // BEGIN decl
00278     typename Set::const_iterator x;
00279     // END
00280 
00281     x = s.find(i);
00282     return x != s.end();
00283 }
00284 
00286 template<class L> 
00287 bool 
00288 in_list( typename L::value_type el, 
00289     const L & l)
00290 {
00291     // BEGIN decl
00292     typename L::const_iterator it;
00293     // END
00294     for(it = l.begin() ; it != l.end(); it++){
00295         if (*it == el){
00296             return true;}}
00297     return false;
00298 }
00299 
00300 
00301 
00302 
00303 template<class T>
00304 struct vector2{
00305 
00306         vector<T> v;
00307 
00308         int w, h;
00309 
00310         vector2(int w, int h)
00311         {
00312             this->v.resize(w * h);
00313             this->w = w;
00314             this->h = h;
00315         }
00316 
00317         vector2(){}
00318 
00319         T
00320         get(int x, int y) const
00321         {
00322             return v[x + y * w];  
00323         }
00324 
00325         void
00326         set(int x, int y, const T& val)
00327         {
00328             v[x + y * w] = val;  
00329         }
00330 
00331 
00332         void
00333         fill_with(const T & val);
00334 };
00335 
00336 
00337 struct rgb
00338 {
00339         Uint8 r, g, b;
00340 
00341         rgb(
00342             Uint8 r,
00343             Uint8 g, 
00344             Uint8 b)
00345         {
00346             this->r = r;
00347             this->g = g;
00348             this->b = b;
00349         }
00350         rgb(){}
00351 };
00352 
00353 
00354 struct rgbaf{ 
00355         float r; 
00356         float g;
00357         float b; 
00358         float a;
00359         rgbaf(float r_, float g_, float b_, float a_): r(r_), g(g_), b(b_), a(a_) {}
00360         rgbaf(){}
00361 };
00362 
00363 struct int_pair{
00364         int x, y;
00365         int_pair(int x, int y){
00366             this->x = x;
00367             this->y = y;}
00368         int_pair(){}
00369 
00370         bool
00371         operator<(
00372             const int_pair& p) const;
00373 
00374         bool
00375         operator==(
00376             const int_pair& p) const;
00377         
00378         int_pair
00379         operator-(
00380             const int_pair& p) const;
00381 
00382         int_pair
00383         operator+(
00384             const int_pair& p) const;
00385 };
00386 
00388 struct cfsurf{
00389         int offs_x, offs_y;
00390         int apparent_wt, apparent_ht;
00391         int real_wt, real_ht;
00392         vector<rgbaf> pixels;
00393 
00394 
00395         cfsurf(int apparent_wt_, int apparent_ht_, 
00396             int real_wt_, int real_ht_, int offset_x_, int offset_y_);
00397         cfsurf(){}
00398 
00399         cfsurf(const cfsurf& l)
00400         {
00401             apparent_wt = l.apparent_wt;
00402             apparent_ht = l.apparent_ht;
00403             real_wt = l.real_wt;
00404             real_ht = l.real_ht;
00405             offs_y = l.offs_y;
00406             offs_x = l.offs_x;
00407             pixels = l.pixels; 
00408         }
00409 
00410         static
00411         pt<cfsurf> 
00412         from_sdl_surface(SDL_Surface * s);
00413 
00414 
00415         void 
00416         set_pixel(
00417             int x, 
00418             int y, 
00419             rgbaf pix);
00420 
00421         rgbaf
00422         get_pixel(
00423             int x, 
00424             int y)const;
00425 
00426         void
00427         opaque_blit_to_sdl_surface(
00428             SDL_Surface * screen,
00429             SDL_Rect src_rect_to_blit /* this rect will be blitted at 0,0 on the screen */ )const;
00430 
00431 
00432 
00433         void
00434         blit_with_src_alpha(
00435             cfsurf & dest)const;
00436 
00437 
00438 };
00439 
00440 
00441 struct quick_message
00442 {
00443         string text;
00444         float timer;
00445 
00446         quick_message(string text)
00447         {
00448             this->text = text;
00449             this->timer =  text.size() * 0.04f + 1.0f; // @@
00450         }
00451 };
00452 
00453 // struct persistent
00454 // {
00455 //      virtual
00456 //      string
00457 //      get_persistent_id()const = 0;
00458 // };
00459 
00460 enum walk_there_or_not {walk_there_to_look_at, do_not_walk_there_to_look_at};
00461 
00462 struct can_appear_closed_in_inv{
00463         virtual 
00464         SDL_Surface * get_inv_surf() =0;
00465 
00466         virtual
00467         bool can_be_moved_across_containers()const = 0;
00468 
00469 };
00470 
00471 struct obj_or_concept
00472 {
00473         string readable_name;
00474 
00475         virtual
00476         SDL_Surface *
00477         get_inv_surf() const = 0;
00478 
00479         obj_or_concept(
00480             string readable_name)
00481         {
00482             this->readable_name = readable_name;
00483         }
00484 
00485         virtual
00486         bool
00487         can_be_moved_across_containers()const=0;
00488 };
00489 
00490 struct token_of_verb_text
00491 {
00492 
00493         virtual
00494         string
00495         to_string(
00496             const pt<obj_or_concept> o1,
00497             const pt<obj_or_concept> o2)const = 0;
00498 };
00499 
00500 struct TOVT_string : public token_of_verb_text
00501 {
00502         string str;
00503 
00504         TOVT_string(
00505             string str)
00506         {
00507             this->str = str;
00508         }
00509 
00510         string
00511         to_string(
00512             const pt<obj_or_concept> o1,
00513             const pt<obj_or_concept> o2)const
00514         {
00515             return str;
00516         }
00517 
00518 };
00519 
00520 struct TOVT_name_of_first_obj : public token_of_verb_text 
00521 {
00522         string
00523         to_string(
00524             const pt<obj_or_concept> o1,
00525             const pt<obj_or_concept> o2)const
00526         {
00527             return o1->readable_name;
00528         }
00529 };
00530 
00531 struct TOVT_name_of_second_obj : public token_of_verb_text 
00532 {
00533         string
00534         to_string(
00535             const pt<obj_or_concept> o1,
00536             const pt<obj_or_concept> o2)const
00537         {
00538             return o2->readable_name;
00539         }
00540 
00541 };
00542 
00543 struct verb
00544 {
00545         list<pt<token_of_verb_text> > tokens;
00546         rgb color;
00547 
00548         verb(
00549             const list<pt<token_of_verb_text> > & tokens,
00550             rgb color)
00551         {
00552             this->tokens = tokens;
00553             this->color = color;
00554         }
00555 
00556         verb(){}
00557 };
00558 
00559 
00560 
00561 struct concept : public obj_or_concept
00562 {
00563         SDL_Surface* inv_surf;
00564 
00565         concept(
00566             string readable_name,
00567             SDL_Surface * inv_surf)
00568             : obj_or_concept(readable_name)
00569         {
00570             this->inv_surf = inv_surf;
00571         }
00572 
00573 
00574         SDL_Surface *
00575         get_inv_surf() const 
00576         {
00577             return inv_surf;
00578         }
00579 
00580         bool can_be_moved_across_containers() const
00581         {
00582             return true;
00583         }
00584 
00585 };
00586 
00592 struct phys_obj : public obj_or_concept
00593 {
00594         pt<can_appear_closed_in_inv>  pick_up_info;
00595 
00596         phys_obj(
00597             string readable_name,
00598             pt<can_appear_closed_in_inv>  pick_up_info)
00599             : obj_or_concept(readable_name)
00600         {
00601             this->pick_up_info = pick_up_info;
00602             assert(pick_up_info);
00603         }
00604 
00605         SDL_Surface *
00606         get_inv_surf() const 
00607         {
00608             return pick_up_info->get_inv_surf();
00609         }
00610 
00611         bool can_be_moved_across_containers() const;
00612 
00613 };
00614 
00615 struct phys_obj_with_verbs : public phys_obj
00616 {
00617         vector<pt<verb> > verbs;
00618         bool none_of_the_above;
00619 
00620         phys_obj_with_verbs(
00621             const vector<pt<verb> >& verbs,
00622             bool none_of_the_above,
00623             string readable_name,
00624             pt<can_appear_closed_in_inv>  pick_up_info)
00625 
00626             : phys_obj(readable_name, pick_up_info)
00627         {
00628             this->verbs = verbs;
00629             this->none_of_the_above = none_of_the_above;
00630         }
00631 };
00632 
00633 
00634 struct dialog_choice
00635 {
00636         virtual ~dialog_choice(){}
00637 
00638         SDL_Rect rect;
00639 
00640         dialog_choice(
00641             SDL_Rect rect)
00642         {
00643             this->rect = rect;
00644         }
00645 
00646 };
00647 
00648 struct dialog_choice_verb_object : public dialog_choice
00649 {
00650         pt<verb> v; 
00651         pt<phys_obj> obj_for_which_the_verb_was_chosen; 
00652         pt<phys_obj> passive_obj; 
00653         
00654         dialog_choice_verb_object(
00655             pt<verb> v,
00656             pt<phys_obj> obj_for_which_the_verb_was_chosen,
00657             pt<phys_obj> passive_obj,
00658             SDL_Rect rect)
00659 
00660             : dialog_choice(rect)
00661         {
00662             this->v = v;
00663             this->obj_for_which_the_verb_was_chosen = obj_for_which_the_verb_was_chosen;
00664             this->passive_obj = passive_obj;
00665         }
00666 };
00667 
00668 struct dialog_choice_double_other : public dialog_choice
00669 {
00670         dialog_choice_double_other(
00671             SDL_Rect rect)
00672             : dialog_choice(rect)
00673         {}
00674 };
00675 
00676 struct hot_zone
00677 {
00678         virtual bool point_in_zone(int_pair point) const=0;
00679 
00680         pt<obj_or_concept> obj;
00681 
00682         hot_zone(
00683             pt<obj_or_concept> obj)
00684         {
00685             this->obj = obj;
00686         }
00687 };
00688 
00689 struct bg_hot_zone : public hot_zone
00690 {
00691         int y_walkbehind;
00692         bool visible;
00693 
00694         bg_hot_zone(
00695             int y_walkbehind,
00696             bool visible,
00697             pt<obj_or_concept> obj)
00698 
00699             : hot_zone(obj)
00700         {
00701             this->y_walkbehind = y_walkbehind;
00702             this->visible = visible;
00703         }
00704             
00705 };
00706 
00707 struct hot_zone_square : public bg_hot_zone
00708 {
00709         int x1, x2, y1, y2;
00710 
00711         bool point_in_zone(int_pair point) const;
00712 
00713         hot_zone_square(int x1, int y1, int x2, int y2, 
00714                         pt<obj_or_concept> i,
00715                         bool visible, int y_walkbehind)
00716             : bg_hot_zone(y_walkbehind,
00717                           visible,
00718                           i)
00719         {
00720             assert(x1 < x2);
00721             assert(y1 < y2);
00722             this->x1 = x1;
00723             this->y2 = y2;
00724             this->x2 = x2;
00725             this->y1 = y1;
00726         }
00727 
00728 
00729 };
00730 
00731 struct hot_zone_pixel_perfect: public bg_hot_zone
00732 {
00733         pt<cfsurf> surf;
00734 
00735         bool point_in_zone(int_pair point) const;
00736 
00737         hot_zone_pixel_perfect(
00738             pt<cfsurf> surf,
00739             pt<obj_or_concept> i,
00740             bool visible, 
00741             int y_walkbehind)
00742 
00743             : bg_hot_zone( y_walkbehind,
00744                            visible,
00745                            i)
00746         {
00747             this->surf = surf;
00748         }
00749 
00750 };
00751 
00752 struct player_state{
00753         virtual ~player_state(){}
00754 };
00755 
00756 
00757 
00758 
00759 struct anim_frame{
00760         int w, h;
00761         vector<rgbaf> pixels;
00762         int_pair hot_spot;
00763         float duration;
00764 
00765         anim_frame(int w, int h, int_pair hot_spot, float duration)
00766         {
00767             this->w  = w;
00768             this->h = h;
00769             this->hot_spot = hot_spot;
00770             this->duration = duration;
00771             this->pixels.resize(w * h);
00772         }
00773         anim_frame(int w, int h, int_pair hot_spot, float duration, 
00774                    const vector<rgbaf> & pixels)
00775         {
00776             this->w  = w;
00777             this->h = h;
00778             assert(pixels.size() == w * h);
00779             this->duration = duration;
00780             this->hot_spot = hot_spot;
00781             this->pixels = pixels;
00782         }
00783         anim_frame(){}
00784  
00785 
00786         bool 
00787         point_in_surf(
00788             int_pair p,
00789             int_pair pl,
00790             float scaling) const;
00791 
00792 
00793         static
00794         pt<anim_frame> 
00795         from_sdl_surface(
00796             SDL_Surface * s, 
00797             int_pair hot_spot,
00798             float duration);
00799 
00800         void 
00801         set_pixel(
00802             int x, 
00803             int y, 
00804             rgbaf pix);
00805 
00806 
00807         rgbaf
00808         get_pixel(
00809             int x, 
00810             int y) const;
00811 
00812 
00813         rgbaf 
00814         get_pixel_with_interpolation(
00815             float px,
00816             float py) const;
00817 
00818 };
00819 
00820 struct animation
00821 {
00822         vector<pt<anim_frame> > frames;
00823 
00824         animation(
00825             const vector<pt<anim_frame> >& frames)
00826         {
00827 
00828             this->frames = frames;
00829         }
00830         animation(
00831             const list<pt<anim_frame> >& frames)
00832         {
00833 
00834             this->frames = *vector_of(frames);
00835         }
00836 };
00837 
00838 
00839 
00840 struct PS_still_and_parsing : public player_state
00841 {
00842 
00843         pt<animation> anim;
00844         int cur_frame;
00845         float timer;
00846 
00847 
00848         PS_still_and_parsing(
00849             pt<animation> anim,
00850             float timer,
00851             int cur_frame)
00852         {
00853             this->anim = anim;
00854             this->timer = timer;
00855             this->cur_frame = cur_frame; 
00856         }
00857 };
00858 
00859 
00860 
00861 
00862 template<class T>
00863 struct pos_and
00864 {
00865         typedef T value_type;
00866 
00867         int_pair pos;
00868         T o;
00869 
00870         pos_and(const T& o, int_pair pos)
00871         {
00872             this->pos = pos;
00873             this->o = o;
00874         }
00875 
00876         pos_and(){}
00877 
00878         bool
00879         operator==(const pos_and<T>& ob)
00880         {
00881             return o == ob.o /* @@ equality of pointers*/ && pos == ob.pos;
00882         }
00883 
00884 
00885 };
00886 
00887 
00888 struct game_state_t 
00889 {
00890         virtual ~game_state_t(){}
00891 
00892         bool paused;
00893 
00894         game_state_t()
00895         {
00896             paused = false;
00897         }
00898 
00899 };
00900 
00901 struct container_pick_result
00902 {
00903         virtual ~container_pick_result(){}
00904 };
00905 
00906 struct cannot_be_closed{};
00907 
00908 struct popup : public obj_or_concept
00909 {
00910         variant<SDL_Rect, cannot_be_closed> closing_area;
00911         SDL_Surface* picture;
00912         int_pair position_in_screen;
00913         pt<can_appear_closed_in_inv> pick_up_info;
00914 
00915         virtual 
00916         void
00917         render(
00918             SDL_Surface * screen,
00919             const pt<game_state_t> game_state) const = 0;
00920 
00921 
00922         virtual
00923         pt<container_pick_result>
00924         item_at_screen_pos(
00925             int_pair pos,
00926             pt<popup> me_as_a_smart_ptr) const = 0;
00927 
00928         popup(
00929             string readable_name,
00930             variant<SDL_Rect, cannot_be_closed> closing_area,
00931             SDL_Surface* picture,
00932             int_pair position_in_screen,
00933             pt<can_appear_closed_in_inv> pick_up_info)
00934 
00935             : obj_or_concept( readable_name)
00936         {
00937             assert(pick_up_info);
00938             this->closing_area = closing_area;
00939             this->picture = picture;
00940             this->position_in_screen = position_in_screen;
00941             this->pick_up_info = pick_up_info;
00942         }
00943 
00944 
00945 };
00946 
00947 
00948 
00949 struct zoomable_zone : public hot_zone
00950 {
00951         SDL_Rect rect;
00952         bool intersect_rect_and_picture;
00953 
00954         bool
00955         point_in_zone(int_pair point) const;
00956 
00957 
00958         zoomable_zone(
00959             SDL_Rect rect,
00960             bool intersect_rect_and_picture,
00961             pt<obj_or_concept> obj)
00962             : hot_zone(obj)
00963         {
00964             this->rect = rect;
00965             this->intersect_rect_and_picture = intersect_rect_and_picture;
00966         }
00967 
00968 };
00969 
00970 
00971 
00972 
00973 struct zoomable : public popup
00974 {
00975         list<pt<zoomable_zone> > sorted_zones;
00976 
00977 
00978         pt<container_pick_result>
00979         item_at_screen_pos(
00980             int_pair pos,
00981             pt<popup> me_as_a_smart_ptr) const ;
00982 
00983         zoomable(
00984             list<pt<zoomable_zone> > sorted_zones,
00985             string readable_name,
00986             variant<SDL_Rect, cannot_be_closed> closing_area,
00987             SDL_Surface* picture,
00988             int_pair position_in_screen,
00989             pt<can_appear_closed_in_inv> pick_up_info)
00990 
00991             : popup( readable_name,
00992                      closing_area,
00993                      picture,
00994                      position_in_screen,
00995                      pick_up_info)
00996         {
00997             this->sorted_zones = sorted_zones;
00998         }
00999 
01000         SDL_Surface*
01001         get_inv_surf()const
01002         {
01003             return pick_up_info->get_inv_surf();
01004         }
01005 
01006 
01007         void
01008         render(
01009             SDL_Surface * screen,
01010             const pt<game_state_t> game_state) const;
01011 
01012         bool
01013         can_be_moved_across_containers()const
01014         {
01015             return true;
01016         }
01017 
01018 };
01019 
01020 
01021 enum container_type{ CONCEPTS, PHYS_OBJECTS, CAN_CONTAIN_ANYTHING};
01022 
01023 
01024 struct container : public popup
01025 {
01026         container_type type;
01027         SDL_Rect drop_in_area;
01028         bool can_be_dragged;
01029         list<pos_and<pt<obj_or_concept> > > sorted_items;
01030 
01031         pt<container_pick_result>
01032         item_at_screen_pos(
01033             int_pair pos,
01034             pt<popup> me_as_a_smart_ptr) const ;
01035 
01036 
01037         container(
01038             string readable_name,
01039             pt<can_appear_closed_in_inv> pick_up_info,
01040             SDL_Rect drop_in_area,
01041             SDL_Surface* picture,
01042             const list<pos_and<pt<obj_or_concept> > >& sorted_items,
01043             int_pair position_in_screen,
01044             variant<SDL_Rect, cannot_be_closed> closing_area,
01045             container_type type,
01046             bool can_be_dragged)
01047             : popup( readable_name,
01048                         closing_area,
01049                         picture,
01050                         position_in_screen,
01051                         pick_up_info)
01052         {
01053             this->type = type;
01054             this->drop_in_area = drop_in_area;
01055             this->sorted_items = sorted_items;
01056             this->can_be_dragged = can_be_dragged;
01057         }
01058 
01059         SDL_Surface*
01060         get_inv_surf()const
01061         {
01062             return pick_up_info->get_inv_surf();
01063         }
01064 
01065         void
01066         add_item( 
01067             const pt<obj_or_concept> i);
01068 
01069         void
01070         remove_item_not_recursively( 
01071             const pt<obj_or_concept> i);
01072 
01073         void
01074         remove_item_recursively( 
01075             const pt<obj_or_concept> i);
01076 
01077 
01078         void
01079         add_item_in_pos(
01080             pos_and<pt<obj_or_concept> > obj_and_pos);
01081 
01082 
01083 
01084         bool
01085         can_contain_this_obj(pt<obj_or_concept> o)const;
01086 
01087         bool
01088         can_be_moved_across_containers()const;
01089 
01090 
01091         void
01092         render(
01093             SDL_Surface * screen,
01094             const pt<game_state_t> game_state) const;
01095 
01096     private:
01097 
01098         bool
01099         container::remove_item_aux(
01100             const pt<obj_or_concept> item);
01101 
01102 
01103         bool
01104         container::remove_item_rec_aux(
01105             const pt<obj_or_concept> item);
01106 
01107 };
01108 
01109 
01110 struct PS_missing_one_item : public PS_still_and_parsing{
01111         pt<obj_or_concept> obj_already_chosen;
01112         
01113         PS_missing_one_item(
01114             pt<obj_or_concept> obj_already_chosen,
01115             pt<animation> anim,
01116             float timer,
01117             int cur_frame)
01118             : PS_still_and_parsing(anim, timer, cur_frame)
01119         {
01120             this->obj_already_chosen = obj_already_chosen;
01121         }
01122 };
01123 
01124 
01125 struct PS_choosing_verb : public PS_still_and_parsing{
01126         pt<phys_obj> obj_one;
01127         pt<phys_obj> obj_two;
01128         list<pt<dialog_choice> > choices;
01129         SDL_Rect cancel_rect;
01130         
01131         
01132         PS_choosing_verb( 
01133             pt<phys_obj> obj_one,
01134             pt<phys_obj> obj_two,
01135             list<pt<dialog_choice> > choices,
01136             SDL_Rect cancel_rect,
01137             pt<animation> anim,
01138             float timer,
01139             int cur_frame)
01140 
01141             : PS_still_and_parsing( anim, timer, cur_frame)
01142         {
01143             this->obj_one = obj_one;
01144             this->obj_two = obj_two;
01145             this->choices = choices;
01146             this->cancel_rect = cancel_rect;
01147         }
01148 };
01149 
01150 
01151 struct PS_missing_two_items : public PS_still_and_parsing 
01152 {
01153         PS_missing_two_items(
01154             pt<animation> anim,
01155             float timer,
01156             int cur_frame)
01157 
01158             : PS_still_and_parsing(anim, timer, cur_frame)
01159         {}
01160 
01161 };
01162 
01163 
01164 
01165 // struct serializable
01166 // {
01167 //      virtual
01168 //      void 
01169 //      serialize(
01170 //          ostream& o)const = 0;
01171 
01172 //      virtual
01173 //      void 
01174 //      deserialize_once_subtype_known(
01175 //          istream& o,
01176 //          const list<pt<obj> > & objects) = 0;
01177 
01178         
01179 // };
01180 
01181 
01182 struct game_state_normal_t : public game_state_t 
01183 {
01184 };
01185 
01186 struct game_state_flashing_inv_t : public game_state_t
01187 {
01188         pt<obj_or_concept> item_that_is_flashing;
01189         float timer;
01190 
01191         game_state_flashing_inv_t(
01192             pt<obj_or_concept> item_that_is_flashing)
01193         {
01194             this->item_that_is_flashing = item_that_is_flashing;
01195             this->timer = 3; // seconds @@
01196         }
01197 
01198         game_state_flashing_inv_t(){}
01199 
01200 };
01201 
01202 struct player_illumination
01203 {
01204         virtual
01205         float
01206         get_illum_factor_at(
01207             int x, int y) const = 0;
01208 
01209 };
01210 
01211 
01212 struct player_illumination_constant : public player_illumination
01213 {
01214         float multiplier;
01215 
01216         player_illumination_constant(
01217             float multiplier)
01218         {
01219             this->multiplier = multiplier;
01220         }
01221 
01222         float
01223         get_illum_factor_at(
01224             int x, int y) const 
01225         {
01226             return this->multiplier;
01227         }
01228 
01229 };
01230 
01231 
01232 struct player_illumination_pixel_level : public player_illumination
01233 {
01234         vector2<float> multipliers;
01235 
01236         player_illumination_pixel_level(
01237             vector2<float> multipliers)
01238         {
01239             this->multipliers = multipliers;
01240         }
01241 };
01242 
01243 struct circle_t
01244 {
01245         float radius;
01246         int_pair center;
01247 
01248         circle_t(
01249             float radius,
01250             int_pair center)
01251         {
01252             this->radius = radius;
01253             this->center = center;
01254         }
01255 };
01256 
01257 
01258 struct light
01259 {
01260         float weight;
01261         float oscillation_speed;
01262         float oscillation_amplitude;
01263         pt<player_illumination> pl_illum;
01264 
01265         virtual 
01266         ~light(){}
01267 
01268     protected:
01269         light( float weight, float oscillation_speed, 
01270                float oscillation_amplitude,
01271                pt<player_illumination> pl_illum)
01272         {
01273             this->weight = weight;
01274             this->oscillation_amplitude = oscillation_amplitude;
01275             this->oscillation_speed = oscillation_speed;
01276             this->pl_illum = pl_illum;
01277         }
01278 
01279 };
01280 
01281 struct light_fixed_in_loc : public light
01282 {
01283         light_fixed_in_loc( float weight, float oscillation_speed, 
01284                float oscillation_amplitude,
01285                pt<player_illumination> pl_illum)
01286             : light(weight, oscillation_speed, oscillation_amplitude, pl_illum)
01287         {}
01288 
01289 };
01290 
01291 struct light_across_loc : public light
01292 {
01294         pt<phys_obj> obj_which_emits_the_light;
01295         float light_radius;
01296 
01297         light_across_loc( float weight, float oscillation_speed, 
01298                           float oscillation_amplitude,
01299                           pt<player_illumination> pl_illum,
01300                           pt<phys_obj> obj_which_emits_the_light,
01301                           float light_radius)
01302             : light( weight, oscillation_speed, oscillation_amplitude,
01303                      pl_illum)
01304         {
01305             this->obj_which_emits_the_light = obj_which_emits_the_light;
01306             this->light_radius = light_radius;
01307         }
01308 
01309 };
01310 
01311 struct surf_with_name{
01312         pt<light> ligh;
01313         pt<cfsurf> surf;
01314 
01315         surf_with_name(pt<light> ligh, pt<cfsurf> surf)
01316         {
01317             this->surf = surf;
01318             this->ligh = ligh;
01319         }
01320 };
01321 
01322 struct no_item{};
01323 
01324 struct room_scaling_data{
01325         float y1, scaling_at_y1, y2, scaling_at_y2;
01326 };
01327 
01328 struct printable
01329 {
01330         virtual
01331         void
01332         print_with_transparency(
01333             cfsurf & background,
01334             const room_scaling_data& d,
01335             const set<pt<light> > active_lights) = 0;
01336 
01337         virtual 
01338         int 
01339         y()= 0;
01340 };
01341 
01342 
01343 struct layer_unlit_after_anim
01344 {
01345         list<surf_with_name> lit_versions;
01346         int y_walkbehind;
01347 
01348         layer_unlit_after_anim(
01349             list<surf_with_name> lit_versions,
01350             int y_walkbehind)
01351         {
01352             this->lit_versions  = lit_versions;
01353             this->y_walkbehind = y_walkbehind;
01354         }
01355 };
01356 
01357 
01358 struct layer_unlit_before_anim
01359 {
01360         int y_walkbehind;
01361         bool visible;
01362 
01363         layer_unlit_before_anim(
01364             int y_walkbehind,
01365             bool visible)
01366         {
01367             this->y_walkbehind = y_walkbehind;
01368             this->visible = visible;
01369         }
01370 
01371         virtual
01372         pt<layer_unlit_after_anim>
01373         get_cur_frame(float dt) = 0;
01374 
01375 };
01376 
01377 struct layer_unlit_not_anim : public layer_unlit_before_anim
01378 {
01379         list<surf_with_name> lit_versions;
01380 
01381         layer_unlit_not_anim(
01382             const list<surf_with_name>& lit_versions,
01383             int y_walkbehind,
01384             bool visible)
01385             : layer_unlit_before_anim(y_walkbehind, visible)
01386         {
01387             this->lit_versions = lit_versions;
01388         }
01389 
01390         pt<layer_unlit_after_anim>
01391         get_cur_frame(float dt)
01392         {
01393             return NEW(layer_unlit_after_anim(lit_versions, y_walkbehind));
01394         }
01395 
01396 
01397 };
01398 
01399 struct layer_unlit_anim : public layer_unlit_before_anim
01400 {
01401         list<list<surf_with_name> > anim;
01402         float timer, frame_change_interval;
01403         list<list<surf_with_name> >::const_iterator cur_frame;
01404 
01405         layer_unlit_anim(
01406             const list<list<surf_with_name> >& anim,
01407             int y_walkbehind,
01408             bool visible,
01409             float frame_change_interval)
01410             : layer_unlit_before_anim(y_walkbehind, visible)
01411         {
01412             this->anim = anim;
01413             this->timer = 0;
01414             this->cur_frame = this->anim.begin();
01415             this->frame_change_interval = frame_change_interval;
01416         }
01417 
01418         pt<layer_unlit_after_anim>
01419         get_cur_frame(float dt);
01420 
01421 
01422 };
01423 
01424 struct layer_lit : public printable{
01425         pt<cfsurf> surf;
01426         int y_walkbehind;
01427 
01428         layer_lit(const pt<cfsurf> surf_, int y_walkbehind_){
01429             y_walkbehind = y_walkbehind_;
01430             surf = surf_;}
01431         layer_lit(){}
01432 
01433         void
01434         print_with_transparency(
01435             cfsurf & background,
01436             const room_scaling_data& d,
01437             const set<pt<light> > active_lights);
01438 
01439 
01440 
01441         int 
01442         y()
01443         {return y_walkbehind;}
01444 };
01445 
01446 
01447 
01448 
01449 
01450    
01451 
01452 
01453 
01454 struct mood_t{
01455         virtual 
01456         ~mood_t(){}
01457 };
01458 
01459 struct mood_and_string
01460 {
01461         pt<mood_t> mood;
01462         string str;
01463 
01464         mood_and_string(
01465             pt<mood_t> mood,
01466             string str)
01467         {
01468             this->mood = mood;
01469             this->str = str;
01470         }
01471 };
01472 
01473 struct anim_and_string
01474 {
01475         pt<animation> anim;
01476         string str;
01477 
01478         anim_and_string(
01479             pt<animation> anim,
01480             string str)
01481         {
01482             this->anim = anim;
01483             this->str = str;
01484         }
01485 };
01486 
01487 typedef  seq_list<mood_and_string> speech_t;
01488 
01489 typedef  seq_list<anim_and_string> speech2_t;
01490 
01491 
01492 
01493 struct script_cmd
01494 {
01495         virtual ~script_cmd(){}
01496 };
01497 
01498 typedef seq_list<pt<script_cmd> > script_cmds_t;
01499 
01500 
01501 struct transition_of_fixed_light
01502 {
01503         pt<light_fixed_in_loc> ligh;
01504         float cur_timer;
01505         float end_timer;
01506         float start_intensity;
01507         float end_intensity;
01508         bool switch_off_light_at_the_end;
01509 
01510         transition_of_fixed_light(
01511             pt<light_fixed_in_loc> ligh,
01512             float end_timer,
01513             float start_intensity,
01514             float end_intensity,
01515             bool switch_off_light_at_the_end)
01516         {
01517             this->switch_off_light_at_the_end = switch_off_light_at_the_end;
01518             this->ligh = ligh;
01519             this->start_intensity = start_intensity;
01520             this->end_timer = end_timer;
01521             this->end_intensity = end_intensity;
01522             this->cur_timer = 0.0f;
01523         }
01524 
01525 };
01526 
01530 struct scr_cmd_light_transition : public script_cmd
01531 {
01532         float time_delta;
01533         pt<light_fixed_in_loc> ligh;
01534         float start_intensity;
01535         float dest_intensity;
01536         bool switch_off_light_at_the_end;
01537 
01538         scr_cmd_light_transition(
01539             float time_delta,
01540             pt<light_fixed_in_loc> ligh,
01541             float start_intensity,
01542             float dest_intensity,
01543             bool switch_off_light_at_the_end)
01544         {
01545             this->time_delta = time_delta;
01546             this->switch_off_light_at_the_end = switch_off_light_at_the_end;
01547             this->ligh = ligh;
01548             this->dest_intensity = dest_intensity;
01549             this->start_intensity = start_intensity;
01550         }
01551 
01552 };
01553 
01554 
01555 struct scr_cmd_passive_anim : public script_cmd
01556 {
01557         pt<animation> anim;
01558 
01559         scr_cmd_passive_anim(
01560             pt<animation> anim)
01561         {
01562             this->anim = anim;
01563         }
01564 };
01565 struct scr_cmd_quick_message : public script_cmd
01566 {
01567         string text;
01568 
01569         scr_cmd_quick_message(
01570             string text)
01571         {
01572             this->text = text;
01573         }
01574 };
01575 
01576 struct scr_cmd_open_popup : public script_cmd
01577 {
01578 
01579         pt<popup > dr;
01580 
01581         scr_cmd_open_popup(
01582             pt<popup> dr)
01583         {
01584             this->dr = dr;
01585         }
01586 };
01587 
01588 
01589 struct scr_cmd_set_sitting_state : public script_cmd
01590 {
01591         string situation_name;
01592         string occupied_place;
01593 
01594         scr_cmd_set_sitting_state(
01595             string situation_name,
01596             string occupied_place)
01597         {
01598             this->situation_name = situation_name;
01599             this->occupied_place = occupied_place;
01600         }
01601 };
01602 
01603 
01604 
01605 enum direction{
01606     d_up, d_down, d_left, d_right};
01607 
01608 enum horizontal_dir{
01609     hd_right, hd_left};
01610 
01611 enum walking_phase{
01612     CONTACT, RECOIL, PASSING, HIGH_POINT};
01613 
01614 
01615 
01616 
01617 
01618 struct can_appear_closed_in_inv_no: public can_appear_closed_in_inv
01619 {
01620         SDL_Surface * get_inv_surf();
01621 
01622         bool
01623         can_be_moved_across_containers()const
01624         {
01625             return false;
01626         }
01627 
01628 };
01629 
01630 struct can_appear_closed_in_inv_yes: public can_appear_closed_in_inv
01631 {
01632         SDL_Surface* inv_surf;
01633         bool can_be_moved_to_another_container;
01634 
01635         can_appear_closed_in_inv_yes(
01636             SDL_Surface *inv_surf,
01637             bool can_be_moved_to_another_container = true)
01638         {
01639             this->inv_surf = inv_surf;
01640             this->can_be_moved_to_another_container = can_be_moved_to_another_container;
01641         }
01642 
01643         SDL_Surface * get_inv_surf();
01644 
01645         bool
01646         can_be_moved_across_containers()const
01647         {
01648             return can_be_moved_to_another_container;
01649         }
01650 
01651         
01652 };
01653 
01654 
01655 
01656 
01657 
01658 
01659 struct scr_cmd_walk : public script_cmd
01660 {
01661         int_pair dest;
01662 
01663         scr_cmd_walk(   
01664             int_pair dest)
01665         {
01666             this->dest = dest;
01667         }
01668 };
01669 
01670 
01671 
01672 
01673 struct AI_substate
01674 {
01675         virtual ~AI_substate(){}
01676 };
01677 
01678 struct PS_governed_by_AI : public player_state
01679 {
01680         vector<pt<script_cmd> > commands;
01681         int cur_cmd_it;
01682         pt<AI_substate> substate;
01683 
01684         PS_governed_by_AI(
01685             const vector<pt<script_cmd> > & commands,
01686             int cur_cmd_it,
01687             pt<AI_substate> substate)
01688         {
01689             this->commands= commands;
01690             this->cur_cmd_it = cur_cmd_it;
01691             this->substate = substate;
01692 
01693         }
01694 
01695 };
01696 
01697 struct AI_substate_passive_anim: public AI_substate
01698 {
01699         pt<animation> anim;
01700         int cur_frame;
01701         float timer;
01702 
01703         AI_substate_passive_anim(pt<animation> anim)
01704         {
01705             this->anim = anim;
01706             this->timer = 0;
01707             this->cur_frame = 0;
01708         }
01709 };
01710 
01711 struct AI_substate_walk : public AI_substate
01712 {
01713         vector<int_pair> route; // @@ transform to list
01714         int cur_pos; // transform to iterator @@
01715         horizontal_dir cur_foot;
01716         walking_phase cur_phase;
01717         float timer;
01718 
01719         AI_substate_walk(
01720             const vector<int_pair> & route)
01721         {
01722             this->route = route;
01723             this->cur_pos = 0;
01724             this->timer = 0;
01725             this->cur_foot = hd_left;
01726             this->cur_phase = CONTACT;
01727         }
01728 
01729 
01730 };
01731 
01732 
01733 
01734 struct walk_frame_id{
01735         horizontal_dir foot;
01736         walking_phase phase;
01737         direction dir;
01738 
01739         walk_frame_id(
01740             horizontal_dir foot,
01741             walking_phase phase, 
01742             direction dir)
01743         {
01744             this->phase = phase;
01745             this->foot = foot;
01746             this->dir = dir;
01747         }
01748 
01749         bool operator<(const walk_frame_id& w)const;
01750 };
01751 
01752 
01753 
01754 
01755 
01756 
01757 pt<vector2<bool> > 
01758 walking_map_from_sdl_surface(SDL_Surface * s);
01759 
01760 
01761 string string_of_int(int i);
01762 
01763 
01764 
01765 struct anim_frame_and_pos : public printable 
01766 {
01767 
01770         pt<anim_frame> surf;
01771 
01772         int position_x, position_y;
01773         bool must_be_scaled;
01774     
01775         anim_frame_and_pos( const pt<anim_frame> surf,
01776                             int position_x, int position_y,
01777                             bool must_be_scaled)
01778         {
01779             this->surf = surf;
01780             this->position_x = position_x;
01781             this->position_y = position_y;
01782             this->must_be_scaled = must_be_scaled;
01783         }
01784 
01785         anim_frame_and_pos() {}
01786 
01787         void
01788         print_with_transparency(
01789             cfsurf & background,
01790             const room_scaling_data& d,
01791             const set<pt<light> > active_lights);
01792 
01793         int 
01794         y()
01795         {return position_y;}
01796 
01797 };
01798 
01799 struct no_sentence{};
01800 
01801 struct sentence_with_location
01802 {
01803         string text;
01804         int x_left, y_top, x_right;
01805         rgb color;
01806 
01807         sentence_with_location(string text, int x_left, int y_top, int x_right, rgb color)
01808         {
01809             this->text = text;
01810             this->x_left = x_left;
01811             this->x_right = x_right;
01812             this->y_top = y_top;
01813             this->color = color;
01814         }
01815         sentence_with_location(){}
01816 };
01817 
01818 struct result_exec_next_scr_cmd
01819 {
01820         pt<player_state> new_pl_state;
01821         int new_cmd_it;
01822         int_pair new_pl_pos;
01823         direction new_pl_dir;
01824 
01825         result_exec_next_scr_cmd(
01826             pt<player_state> new_pl_state,
01827             int new_cmd_it,
01828             int_pair new_pl_pos,
01829             direction new_pl_dir)
01830         {
01831             this->new_pl_dir = new_pl_dir;
01832             this->new_pl_pos = new_pl_pos;
01833             this->new_cmd_it = new_cmd_it;
01834             this->new_pl_state = new_pl_state;
01835         }
01836             
01837         result_exec_next_scr_cmd(){}
01838         
01839 };
01840 
01841 struct update_AI_result
01842 {
01843         pt<anim_frame> frame;
01844         int_pair pos;
01845         direction dir;
01846         variant<no_sentence, sentence_with_location> maybe_sentence;
01847         pt<player_state> new_player_state;
01848             
01849         update_AI_result(
01850             pt<anim_frame> frame,
01851             int_pair pos,
01852             direction dir,
01853             variant<no_sentence, sentence_with_location> maybe_sentence,
01854             pt<player_state> new_player_state)
01855         {
01856             this->frame = frame;
01857             this->pos = pos;
01858             this->dir = dir;
01859             this->maybe_sentence = maybe_sentence;
01860             this->new_player_state = new_player_state;
01861         }
01862         update_AI_result(){}
01863 };
01864 
01865 
01866 struct location 
01867 {
01868         seq_list<pt<bg_hot_zone> > sorted_hot_zones;
01869         seq_list<pt<layer_unlit_before_anim> >  sorted_unlit_layers_before_anim;
01870         pt<vector2<bool> > walking_map;
01871         room_scaling_data scaling_data; 
01872         set<pt<light_fixed_in_loc> > active_lights;
01873         set<string> occupied_sitting_places;
01874         
01875 
01876         location(
01877             seq_list<pt<bg_hot_zone> > sorted_hot_zones,
01878             seq_list<pt<layer_unlit_before_anim> >  unlit_layers,
01879             pt<vector2<bool> > walking_map,
01880             room_scaling_data scaling_data,
01881             set<pt<light_fixed_in_loc> > active_lights)
01882         {
01883             this->sorted_hot_zones = sorted_hot_zones;
01884             this->sorted_unlit_layers_before_anim = unlit_layers;
01885             this->walking_map = walking_map;
01886             this->scaling_data = scaling_data;
01887             this->active_lights = active_lights;
01888             // occupied_sitting_places empty
01889         }
01890 
01891 };
01892 
01893 struct scr_cmd_change_light : public script_cmd
01894 {
01895         bool turn_on;
01896         pt<light_fixed_in_loc> ligh;
01897         pt<location> loc;
01898             
01899         scr_cmd_change_light(
01900             bool turn_on, 
01901             pt<light_fixed_in_loc> ligh,
01902             pt<location> loc)
01903         {
01904             this->turn_on = turn_on;
01905             this->ligh = ligh;
01906             this->loc = loc;
01907         }
01908 };
01909 
01910 struct scr_cmd_change_loc: public script_cmd
01911 {
01912         pt<location> new_loc;
01913         int_pair position;
01914 
01915         scr_cmd_change_loc(
01916             pt<location> new_loc,
01917             int_pair position)
01918         {
01919             this->new_loc = new_loc;
01920             this->position = position;
01921         }
01922 };
01923 
01924 typedef seq_list<seq_list<mood_and_string> > dialog_t;
01925 
01926 struct anim_right_left
01927 {
01928         pt<animation> right, left;
01929 
01930         anim_right_left(
01931             pt<animation> right, 
01932             pt<animation> left)
01933         {
01934             this->right = right;
01935             this->left = left;
01936         }
01937 
01938         pt<animation>
01939         get_anim(horizontal_dir dir) const;
01940 
01941         anim_right_left(){} // needed for putting anim_right_left in a std::map
01942 };
01943 
01944 typedef map< pt<mood_t>, anim_right_left > anim_of_mood_t;
01945 
01946 
01947 struct still_situation
01948 {
01949         virtual ~still_situation(){}
01950 };
01951 
01952 struct still_situation_normal : public still_situation {};
01953 
01954 struct still_situation_sitting : public still_situation 
01955 {
01956         string situation_name;
01957         string occupied_place;
01958 
01959         still_situation_sitting(
01960             string situation_name,
01961             string occupied_place)
01962         {
01963             this->situation_name = situation_name;
01964             this->occupied_place = occupied_place;
01965         }
01966 };
01967 
01968 
01969 struct dragging_state{
01970         virtual ~dragging_state(){}
01971 };
01972 
01973 struct dragging_state_not_dragging : public dragging_state{};
01974 
01975 struct dragging_state_maybe_dragging_obj : public dragging_state
01976 {
01977         pos_and<pt<obj_or_concept> > obj_and_pos;
01978         int_pair offset_of_mouse_in_obj;
01979         int_pair orig_mouse_pos;
01980         pt<container> orig_container;
01981 
01982         dragging_state_maybe_dragging_obj(
01983             pos_and<pt<obj_or_concept> > obj_and_pos,
01984             int_pair offset_of_mouse_in_obj,
01985             pt<container> orig_container,
01986             int_pair orig_mouse_pos)
01987         {
01988             this->obj_and_pos = obj_and_pos;
01989             this->offset_of_mouse_in_obj = offset_of_mouse_in_obj;
01990             this->orig_mouse_pos = orig_mouse_pos;
01991             this->orig_container = orig_container;
01992         }
01993 };
01994 struct dragging_state_dragging_open_popup : public dragging_state
01995 {
01996         pt<popup> pop;
01997         int_pair offset_of_mouse_in_obj;
01998 
01999         dragging_state_dragging_open_popup(
02000             int_pair offset_of_mouse_in_obj,
02001             pt<popup> pop)
02002         {
02003             this->offset_of_mouse_in_obj = offset_of_mouse_in_obj;
02004             this->pop = pop;
02005         }
02006 };
02007 
02009 struct PC
02010 {
02011         map<walk_frame_id, pt<anim_frame> >  walk_frame_when;
02012         pt<player_state> state; 
02013         map<direction, pt<animation> > anim_of_norm_still_sit;
02014         map<string, pt<animation> > anim_of_sitting_still_sit;
02015         int_pair  pos;
02016         float walk_step_horiz;
02017         float walk_step_vert;
02018         pt<container> cache;
02019         pt<location> loc;
02020         pt<phys_obj> obj;
02021         direction cur_dir;
02022         rgb text_color;
02023         anim_of_mood_t anim_of_mood; 
02024         pt<still_situation> still_situat;
02025         pt<dragging_state> drag_st;
02026         list<pt<popup> > open_popups;
02027 
02028         PC(
02029             const map<walk_frame_id, pt<anim_frame> >&  walk_frame_when,
02030             pt<player_state> state,
02031             const map<direction, pt<animation> > & anim_of_norm_still_sit,
02032             const map<string, pt<animation> > & anim_of_sitting_still_sit,
02033             int_pair  pos,
02034             float walk_step_horiz,
02035             float walk_step_vert,
02036             const pt<container> cache,
02037             pt<location> loc,
02038             pt<phys_obj> obj,
02039             direction cur_dir,
02040             rgb text_color,
02041             anim_of_mood_t anim_of_mood,
02042             pt<still_situation> still_situat)
02043         {
02044             this->drag_st = NEW(dragging_state_not_dragging());
02045             this->still_situat = still_situat;
02046             this->anim_of_mood = anim_of_mood;
02047             this->text_color = text_color;
02048             this->obj = obj;
02049             this->loc = loc;
02050             this->walk_frame_when = walk_frame_when;
02051             this->state = state;
02052             this->anim_of_sitting_still_sit = anim_of_sitting_still_sit;
02053             this->anim_of_norm_still_sit = anim_of_norm_still_sit;
02054             this->pos = pos;
02055             this->walk_step_horiz = walk_step_horiz;
02056             this->walk_step_vert = walk_step_vert;
02057 
02058             this->cache = cache;
02059 
02060             this->cur_dir = cur_dir;
02061         }
02062 
02063 
02064 
02065 };
02066 
02067 enum add_or_remove {ADD, REMOVE};
02068 enum show_or_hide {SHOW, HIDE};
02069 
02070 
02071 struct AI_substate_waiting_for_person_to_stop_talking : public AI_substate
02072 {
02073         pt<PC> person;
02074         pt<anim_frame> frame;
02075 
02076         AI_substate_waiting_for_person_to_stop_talking(
02077             pt<PC> person,
02078             pt<anim_frame> frame)
02079         {
02080             this->person = person;
02081             this->frame = frame;
02082         }
02083 };
02084 struct scr_cmd_wait_for_person_to_stop_talking : public script_cmd
02085 {
02086         pt<PC> person;
02087 
02088         scr_cmd_wait_for_person_to_stop_talking(
02089             pt<PC> person)
02090         {
02091             this->person = person;
02092         }
02093 };
02094 
02095 struct scr_cmd_remove_from_container : public script_cmd
02096 {
02097  
02098         pt<container> cont;
02099         pt<obj_or_concept> object;
02100 
02101         scr_cmd_remove_from_container(
02102             pt<container> cont,
02103             pt<obj_or_concept> object)
02104         {
02105             this->object = object;
02106             this->cont = cont;
02107         }
02108 };
02109 struct scr_cmd_add_to_container : public script_cmd
02110 {
02111  
02112         pt<container> cont;
02113         pt<obj_or_concept> object;
02114 
02115         scr_cmd_add_to_container(
02116             pt<container> cont,
02117             pt<obj_or_concept> object)
02118         {
02119             this->object = object;
02120             this->cont = cont;
02121         }
02122 };
02123 struct scr_cmd_add_to_container_in_pos : public script_cmd
02124 {
02125  
02126         pt<container> cont;
02127         int_pair pos;
02128         pt<obj_or_concept> object;
02129 
02130         scr_cmd_add_to_container_in_pos(
02131             pt<container> cont,
02132             pt<obj_or_concept> object,
02133             int_pair pos)
02134         {
02135             this->cont = cont;
02136             this->object = object;
02137             this->pos = pos;
02138         }
02139 };
02140 
02141 
02142 struct scr_cmd_modify_zone : public script_cmd
02143 {
02144  
02145         pt<bg_hot_zone> zone;
02146         show_or_hide show;
02147 
02148         scr_cmd_modify_zone(
02149             show_or_hide show,
02150             pt<bg_hot_zone> zone)
02151         {
02152             this->show = show;
02153             this->zone = zone;
02154         }
02155 };
02156 
02157 struct scr_cmd_modify_layer : public script_cmd
02158 {
02159  
02160         pt<layer_unlit_before_anim> layer;
02161         show_or_hide show;
02162 
02163         scr_cmd_modify_layer(
02164             show_or_hide show,
02165             pt<layer_unlit_before_anim> layer)
02166         {
02167             this->show = show;
02168             this->layer = layer;
02169         }
02170 };
02171 
02172 
02173 
02174 
02175 
02176 
02177 enum option_close_containers{ close_any_open_container, do_not_close_containers};
02178 
02179 struct scr_cmd_speak : public script_cmd
02180 {
02181         speech_t speech;
02182         option_close_containers close_containers;
02183 
02184         scr_cmd_speak(
02185             const speech_t & speech,
02186             option_close_containers close_containers) 
02187         {
02188             this->speech = speech;
02189             this->close_containers = close_containers;
02190         }
02191 
02192 };
02193 
02194 
02195 struct AI_substate_speaking_while_sitting : public AI_substate
02196 {
02197         list<string> speech;
02198         list<string>::const_iterator current_phrase;
02199         float speech_timer;
02200         pt<anim_frame> frame;
02201 
02202         AI_substate_speaking_while_sitting (
02203             const list<string> & speech,
02204             pt<anim_frame> frame)
02205         {
02206             this->speech = speech;
02207             this->current_phrase = this->speech.begin();
02208             this->speech_timer = 0;
02209             this->frame = frame;
02210         }
02211 
02212 };
02213 
02214 struct AI_substate_speaking_while_standing : public AI_substate
02215 {
02216         int cur_frame_it;
02217         float anim_timer;
02218         speech2_t speech;
02219         speech2_t::const_iterator current_phrase;
02220         float speech_timer;
02221 
02222         AI_substate_speaking_while_standing(
02223             const speech2_t& speech)
02224         {
02225             this->anim_timer = 0;
02226             this->cur_frame_it = 0;
02227             this->speech = speech;
02228             this->current_phrase = this->speech.begin();
02229             this->speech_timer = 0;
02230         }
02231 };
02232 
02233 struct scr_cmd_look_at_fixed_direction : public script_cmd
02234 {
02235         direction dir;
02236 
02237         scr_cmd_look_at_fixed_direction(
02238             direction dir)
02239         {
02240             this->dir = dir;
02241         }
02242 };
02243 
02244 typedef map<int, SDL_Surface*> surf_of_letter_t;
02245 
02246 
02247 
02248 struct container_pick_result_void : public container_pick_result{};
02249 
02250 struct container_pick_result_closing_area : public container_pick_result
02251 {
02252         pt<popup> pop;
02253 
02254         container_pick_result_closing_area(
02255             pt<popup> pop)
02256         {
02257             this->pop = pop;
02258         }
02259 };
02260 
02261 struct container_pick_result_container_drag_area : public container_pick_result
02262 {
02263         pt<popup> pop;
02264 
02265         container_pick_result_container_drag_area(
02266             pt<popup> pop)
02267         {
02268             this->pop = pop;
02269         }
02270 };
02271 
02272 struct container_pick_result_obj_and_pos : public container_pick_result
02273 {
02274         pos_and<pt<obj_or_concept> > obj_and_pos;
02275         pt<popup> pop;
02276         
02277         container_pick_result_obj_and_pos(
02278             const pos_and<pt<obj_or_concept> > & obj_and_pos,
02279             pt<popup> pop)
02280         {
02281             this->obj_and_pos = obj_and_pos;
02282             this->pop = pop;
02283         }
02284 };
02285 
02286 struct container_pick_result_obj : public container_pick_result
02287 {
02288       pt<obj_or_concept>  obj;
02289       pt<popup> pop;
02290         
02291       container_pick_result_obj(
02292          const pt<obj_or_concept>  obj,
02293          pt<popup> pop)
02294       {
02295          this->obj = obj;
02296          this->pop = pop;
02297       }
02298 };
02299 
02300 
02301 
02302 enum special_button_pick_result
02303 {
02304     SBPR_SAVE_LOAD, SBPR_CYCLE_PLAYER, SBPR_NOTHING, SBPR_STAY_FOLLOW
02305 };
02306 
02307 
02308 struct dir_watcher_list_model : public gcn::ListModel
02309 {
02310       dir_watcher_list_model();
02311 
02312       int
02313       getNumberOfElements();
02314 
02315       string
02316       getElementAt(int i);
02317 
02318 
02319       void
02320       rescan_dir();
02321 
02322       vector<string> strings;
02323 };
02324 
02325 
02328 class FACK : public gcn::ActionListener
02329 {
02330     public:
02331     
02332         void
02333         start();
02334 
02335 
02336     protected:
02337     
02338         FACK(int argc, char ** argv);
02339 
02340         // BEGIN pure virtual functions that must be implemented in
02341         // the derived class
02342         virtual void
02343         execute_action_verb_object(
02344             const pt<verb> v, 
02345             const pt<obj_or_concept> obj_for_which_no_verb_was_chosen,
02346             const pt<obj_or_concept> obj_for_which_the_verb_was_chosen) = 0;
02347 
02348         virtual void
02349         execute_action_object_object(
02350             const pt<obj_or_concept> o1, 
02351             const pt<obj_or_concept> o2) = 0;
02352     
02353         virtual void
02354         execute_action_double_none_of_the_above(
02355             const pt<phys_obj> o1, 
02356             const pt<phys_obj> o2) = 0;
02357         
02358  
02359         // END
02360         
02361 
02362         // BEGIN utility fuctions that the derived class can use
02363         void
02364         execute_commands(
02365             pt<PC> player,
02366             const list<pt<script_cmd> > & commands);
02367 
02368 
02369 
02370         void
02371         define_dialog_aux(
02372             const dialog_t & dialog,
02373             pt<PC> first_player, 
02374             pt<PC> second_player, 
02375             script_cmds_t & commands_first,
02376             script_cmds_t & commands_second) const;
02377     
02378 
02379         static bool
02380         contains_recursively(
02381             pt<container> cont,
02382             pt<obj_or_concept> o,
02384             pt<container> & real_cont,
02386             int_pair & pos );
02387 
02388 
02389         static bool
02390         contains_not_recursively(
02391             pt<container> cont,
02392             pt<obj_or_concept> o,
02394             int_pair & pos );
02395     
02396         virtual void
02397         active_player_changed(pt<PC> new_act_pl){}
02398         
02399         // END
02400 
02401 
02402         // BEGIN protected member variables that must be initialized
02403         // by the derived class
02404         SDL_Surface* special_buttons_icon;
02405         int_pair special_buttons_icon_pos;
02406         SDL_Rect zone_save_load_game, zone_cycle_active_player, zone_toggle_stay_follow;
02407 
02408         surf_of_letter_t surf_of_letter;
02409 
02410         pt<PC> act_pl;
02411 
02412         seq_list<pt<PC> > players; // for switching
02413 
02414         set<pt<location> > locations;
02415 
02416         pt<phys_obj> hand,  eye, mouth,  foot, ear, body; 
02417 
02418         pt<concept> topic_hello, topic_yes, topic_no, topic_bye; // @@ why here?
02419 
02420         set<pt<light_across_loc> > lights_across_loc;
02421         // END
02422 
02423 
02424         // BEGIN members that must not be written but can be read or
02425         // written by the derived class
02426         SDL_Surface* screen;
02427 
02428         pt<quick_message> quick_msg;
02429 
02430         list<pt<transition_of_fixed_light> > transitions_of_fixed_light;
02431         // END
02432 
02433     private:
02434 
02435         bool must_exit; 
02436 
02437         pt<gcn::SDLGraphics> gcn_graphics;
02438         pt<gcn::Gui> gcn_gui;
02439         pt<gcn::Container> gcn_top_container;
02440 
02441         pt<gcn::Window> gcn_save_window;
02442         pt<gcn::Container> gcn_save_cont;
02443         pt<gcn::Button> gcn_cancel_save_button;
02444         pt<gcn::Button> gcn_save_button;
02445         pt<gcn::TextField> gcn_save_text_field;
02446 
02447         pt<gcn::Window> gcn_options_window;
02448         pt<gcn::Container> gcn_options_cont;
02449 
02450         pt<dir_watcher_list_model> list_model;
02451 
02452 
02453 
02454         pt<gcn::Window> gcn_load_window;
02455         pt<gcn::Container> gcn_load_cont;
02456         pt<gcn::Button> gcn_cancel_load_button;
02457         pt<gcn::ListBox> gcn_load_listbox;
02458         pt<gcn::ScrollArea> gcn_load_scroll_area;
02459         
02460         pt<gcn::SDLInput> gcn_input;
02461         pt<gcn::SDLImageLoader> gcn_image_loader;
02462         pt<gcn::ImageFont> gcn_font;
02463 
02464         pt<gcn::Button> gcn_options_save_button;
02465         pt<gcn::Button> gcn_options_cancel_button;
02466         pt<gcn::Button> gcn_options_fullscreen_button;
02467         pt<gcn::Button> gcn_options_load_button;
02468         pt<gcn::Button> gcn_options_quit_button;
02469 
02470         
02471 
02472         void action(const string& eventId);
02473 
02474 
02475         void
02476         recompute_on_lights(
02477             set<pt<light> > & on_lights ) const;
02478 
02479         special_button_pick_result
02480         special_button_at_pos(
02481             int_pair pos) const;
02482 
02483 
02484         pt<layer_lit> 
02485         lit_layer_of_unlit_layer ( 
02486             const layer_unlit_after_anim & unlit,
02487             const set<pt<light> > & on_lights,
02488             float time,
02489             SDL_Rect visible_rect)const;
02490 
02491         pt<circle_t>
02492         circle_of_light(pt<light> l) const;
02493 
02494         update_AI_result
02495         update_AI_state(pt<PC> player, float dt,
02496                         int_pair top_left_of_obj_in_cont_coords);
02497 
02498         void
02499         update_light_transitions(float dt);
02500 
02501         SDL_Rect
02502         find_scrolling_rect(
02503             int_pair size_of_bg_surf);
02504         
02505         result_exec_next_scr_cmd
02506         exec_next_scr_cmd(
02507             const vector<pt<script_cmd> > commands,
02508             int cur_cmd_it,
02509             const pt<PC> pl,
02510             pt<anim_frame> last_frame,
02511             bool increm_cmd_at_start,
02512             bool must_set_player_left_or_right);
02513 
02514         pt<game_state_t> game_state;
02515 
02516         void
02517         close_all_open_popups(
02518             const pt<PC> pl);
02519 
02520         void
02521         render_command_bar( 
02522             int_pair mouse_screen,
02523             int_pair mouse_bg,
02524             const map<pt<PC>, pt<anim_frame> > & cur_frame_of_player) const;
02525 
02526         void
02527         manage_button_up(
02528             list<SDL_Event>::const_iterator ev);
02529 
02530         int
02531         calc_command_bar_ht() const
02532         {
02533             return 2 + map_get(surf_of_letter, 'a')->h;
02534         }
02535 
02536         
02537         pt<container_pick_result>
02538         item_in_popup_at_screen_pos(
02539             int_pair screen_pos) const;
02540 
02541 
02542         void
02543         the_obj_was_clicked(
02544             pt<obj_or_concept> o,
02545             int_pair mouse);
02546 
02547         void 
02548         drop_item(
02549             pt<dragging_state_maybe_dragging_obj> st,
02550             int_pair mouse);
02551 
02552 
02553         void
02554         cycle_active_player();
02555 
02556 
02557         void
02558         stand_up_if_sitting(
02559             pt<PC> pl);
02560 
02561 };
02562 
02563 void 
02564 blit_char( 
02566     const anim_frame_and_pos & src,
02569     float scaling ,
02571     float lighting,
02573     cfsurf & screen );
02574 
02575 
02576 struct surf_and_weight{
02577         pt<cfsurf> surf;
02578         float oscillation_amplitude;
02579         float oscillation_speed;
02580 
02581         pt<circle_t> circle;
02582 
02583         float calc_weight(int_pair pos) const;
02584 
02585         surf_and_weight(
02586             pt<cfsurf> surf, 
02587             float weight,
02588             float oscillation_amplitude, 
02589             float oscillation_speed,
02590             pt<circle_t> circle);
02591 
02592         surf_and_weight(){}
02593     
02594         bool operator< (const surf_and_weight& s) const;
02595 
02596     private:
02597         float weight;
02598 };
02599 
02600 inline
02601 float
02602 surf_and_weight::calc_weight(int_pair pos) const
02603 {
02604     
02605     if(circle)
02606     {
02607         // BEGIN decl
02608         float dx, dy;
02609         float distance_squared, circle_rad_squared, ratio;
02610         // END
02611 
02612         dx = float(abs(pos.x - circle->center.x));
02613         dy = float(abs(pos.y - circle->center.y));
02614         distance_squared =  dx * dx + dy * dy;
02615         circle_rad_squared = circle->radius * circle->radius;
02616 
02617         if (distance_squared >= circle_rad_squared)
02618         {
02619             return 0;
02620         }
02621         else
02622         {
02623             ratio = distance_squared / circle_rad_squared;
02624             return weight * ( 1.0f - ratio  );
02625         }
02626     }
02627     else
02628     {
02629         return weight;
02630     }
02631 }
02632 
02633 inline
02634 surf_and_weight::surf_and_weight(
02635     pt<cfsurf> surf, float weight,
02636     float oscillation_amplitude, float oscillation_speed,
02637     pt<circle_t> circle)
02638 {
02639     assert(0 <= oscillation_amplitude  && oscillation_amplitude < 0.5f);
02640     this->weight = weight;
02641     this->surf = surf;
02642     this->circle = circle;
02643     this->oscillation_speed = oscillation_speed;
02644     this->oscillation_amplitude = oscillation_amplitude;
02645 }
02646 
02647 pt<cfsurf> 
02648 sum_each_pixel( const list<surf_and_weight > & surfs, float time,
02649                 SDL_Rect visible_rect);
02650 
02651 
02652 pt<layer_lit> 
02653 lit_layer_of_unlit_layer ( 
02654     const layer_unlit_after_anim & unlit,
02655     const set<pt<light> > & on_lights,
02656     float time ,
02657     SDL_Rect visible_rect);
02658 
02659 inline
02660 rgbaf 
02661 sum_rgbaf(rgbaf r1, rgbaf r2){
02662     return rgbaf(r1.r + r2.r
02663                  , r1.g + r2.g
02664                  , r1.b + r2.b
02665                  , r1.a + r2.a);
02666 }
02667 
02668 inline
02669 rgbaf
02670 rgbaf_of_rgbai(Uint8 r, Uint8 g, Uint8 b, Uint8 a){
02671     return rgbaf( float(r)
02672                   , float(g)
02673                   , float(b)
02674                   , float(a) / 255.0f);
02675 }
02676 
02677 inline
02678 rgbaf
02679 mul_scalar_rgbaf(float scal, rgbaf rg){
02680     return rgbaf( scal * rg.r
02681                   , scal * rg.g
02682                   , scal * rg.b
02683                   , scal * rg.a );
02684 }
02685 
02686 inline
02687 rgbaf 
02688 mul_scalar_rgbaf_noalpha(float scal, rgbaf rg){
02689     return rgbaf( scal * rg.r
02690                   , scal * rg.g
02691                   , scal * rg.b
02692                   , rg.a );
02693 }
02694 
02695 
02696 
02697 inline
02698 void 
02699 cfsurf::set_pixel(
02702     int x, 
02705     int y, 
02706     rgbaf pix)
02707 {
02708     // BEGIN decl
02709     int x2, y2;
02710     // END
02711 
02712     // BEGIN precond
02713     x2 = x - offs_x;
02714     y2 = y - offs_y;
02715     assert(0<= x2 && x2 < real_wt);
02716     assert(0<= y2 && y2 < real_ht);
02717     // END
02718 
02719     pixels[ y2 * real_wt + x2] = pix;
02720 }
02721 
02722 
02723 inline
02724 rgbaf
02725 cfsurf::get_pixel(
02726     int x, 
02727     int y)const
02728 {
02729     // BEGIN decl
02730     int x2, y2;
02731     // END
02732 
02733     // BEGIN precond
02734     assert (0 <= x && x < apparent_wt);
02735     assert (0 <= y && y < apparent_ht);
02736     // END
02737 
02738     x2 = x - offs_x;
02739     y2 = y - offs_y;
02740     if (   0<= x2 && x2 < real_wt
02741         &&  0<= y2 && y2 < real_ht){
02742         return pixels[ y2 * real_wt + x2];}
02743     else{
02744         return rgbaf(0.f ,0.f ,0.f ,0.f );} // useful to merge
02745     // surfaces with different
02746     // real widths.
02747 }
02748 
02749 inline
02750 rgbaf 
02751 anim_frame::get_pixel_with_interpolation(
02752     float px,
02753     float py) const
02754 {
02755     // BEGIN decl
02756     float x_low, x_high, y_low, y_high;
02757     int x_low_i, x_high_i, y_low_i, y_high_i;
02758     float delta_x, delta_y;
02759     float weight_x1, weight_x2, weight_y1, weight_y2;
02760     rgbaf p1, p2, p3, p4, p12, p34, p;
02761     // END
02762 
02763     // BEGIN precond
02764     assert(w > 0);
02765     assert(h > 0);
02766     assert(px >= 0.0f);
02767     assert(py >= 0.0f);
02768     // due to approximation errors, I don't know how to check for this:
02769     //     assert(int(px) < w);
02770     //     assert(int(py) < h);
02771     // END
02772 
02773 
02774     x_low = std::max(0.0f, px - 0.5f);
02775     x_high = std::min (float(w) -0.1f, px + 0.5f);
02776     y_low = std::max(0.0f, py - 0.5f);
02777     y_high = std::min ( float(h) - 0.1f, py + 0.5f ) ;
02778 
02779     assert(x_low < x_high);
02780     assert(y_low < y_high);
02781 
02782     x_low_i = int( floor(x_low)); // floor() is important because, if
02783     // x_low==0.5f, x_low_i could be set
02784     // to 1, which is wrong.
02785     x_high_i = int(floor(x_high)); // floor() is important because, if
02786     // x_high == 1.5, x_high_i could be
02787     // set to 2, which is wrong.
02788     y_low_i = int( floor(y_low));
02789     y_high_i = int(floor(y_high));
02790 
02791     assert(x_low_i < w);
02792     assert(y_low_i < h);
02793     assert(x_high_i < w);
02794 
02795     if (y_high_i >= h){
02796         cout << "w = " << w << ", h = " << h << ", y_high_i = " << y_high_i <<endl;}
02797     assert(y_high_i < h);
02798 
02799 
02800     p1 = get_pixel(  x_low_i, y_low_i);
02801     p2 = get_pixel(  x_high_i, y_low_i);
02802     p3 = get_pixel(  x_low_i, y_high_i);
02803     p4 = get_pixel(  x_high_i, y_high_i);
02804 
02805     delta_x = nearbyint(px) - px; 
02806     delta_y = nearbyint(py) - py;
02807 
02808     weight_x1 = 0.5f  + delta_x;
02809     weight_x2 = 0.5f  - delta_x;
02810 
02811     weight_y1 = 0.5f  + delta_y;
02812     weight_y2 = 0.5f  - delta_y;
02813 
02814     assert(weight_x1 >= 0.0f);
02815     assert(weight_x2 >= 0.0f);
02816     assert(weight_y1 >= 0.0f);
02817     assert(weight_y2 >= 0.0f);
02818 
02819     // in order to compute p from p1, p2, p3, p4, first we blend
02820     // p1 and p2 to obtain p12, then p3 and p4 to obtain p34, and
02821     // finally p34 and p12 to obtain p.
02822     p12 = sum_rgbaf( mul_scalar_rgbaf(weight_x1, p1)
02823         , mul_scalar_rgbaf(weight_x2, p2));
02824     p34 = sum_rgbaf( mul_scalar_rgbaf(weight_x1, p3)
02825         ,  mul_scalar_rgbaf(weight_x2, p4));
02826     p = sum_rgbaf( mul_scalar_rgbaf(weight_y1, p12)
02827         , mul_scalar_rgbaf(weight_y2, p34));
02828 
02829         
02830     return p;
02831 }
02832 
02833 inline
02834 rgbaf
02835 anim_frame::get_pixel(
02836     int x, 
02837     int y) const
02838 {
02839     // BEGIN precond
02840     assert (0 <= x && x < w);
02841     assert (0 <= y && y < h);
02842     // END
02843     return pixels[ y * w + x];
02844 }
02845 
02846 
02847 
02848 
02849 
02850 #endif

Generated on Wed May 25 15:36:06 2005 for FACK by  doxygen 1.4.0