/[enigma]/enigma/src/items.cc
ViewVC logotype

Diff of /enigma/src/items.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.85 by dheck, Mon Sep 8 18:26:49 2003 UTC revision 1.86 by dheck, Tue Sep 9 19:23:04 2003 UTC
# Line 190  namespace Line 190  namespace
190          CLONEOBJ(Umbrella);          CLONEOBJ(Umbrella);
191    
192          bool on_laserhit(Direction /*d*/) {          bool on_laserhit(Direction /*d*/) {
193              KillItem(get_pos());              SetItem(get_pos(), MakeItem("it-explosion1"));
194              return false;              return false;
195          }          }
196    
# Line 1317  namespace Line 1317  namespace
1317          CLONEOBJ(Vortex);          CLONEOBJ(Vortex);
1318      public:      public:
1319          Vortex(bool opened)          Vortex(bool opened)
1320              : Item("it-vortex")          : Item("it-vortex"), state(opened ? OPEN : CLOSED),
1321              , state(opened ? OPEN : CLOSED)            close_after_warp(!opened)
             , close_after_warp(!opened)  
1322          {          {
1323          }          }
1324    
# Line 1330  namespace Line 1329  namespace
1329          bool actor_hit(Actor*);          bool actor_hit(Actor*);
1330          void init_model() {          void init_model() {
1331              switch(state) {              switch(state) {
1332                  case OPEN:   set_model("it-vortex-open"  ); break;              case OPEN:   set_model("it-vortex-open"  ); break;
1333                  case CLOSED: set_model("it-vortex-closed"); break;              case CLOSED: set_model("it-vortex-closed"); break;
1334                  case OPENING: set_anim("it-vortex-opening"); break;              case OPENING: set_anim("it-vortex-opening"); break;
1335                  case CLOSING: set_anim("it-vortex-closing"); break;              case CLOSING: set_anim("it-vortex-closing"); break;
1336              }              }
1337          }          }
1338          void animcb() {          void animcb() {
# Line 2018  namespace Line 2017  namespace
2017              Item::on_removal();              Item::on_removal();
2018          }          }
2019    
2020          void message(const string &msg, const Value &val) {          void message(const string &msg, const Value &val);
             if (msg == "trigger" || msg == "openclose") {  
                 switch (state) {  
                     case IDLE:  
                     case SHRINKED:  
                         grow(); // if no stone on top -> grow  
                         break;  
   
                     // if stone on top -> toggle state (has no effect until stone leaves)  
                     case BOLDERED:  
                         change_state(COVERED);  
                         break;  
                     case COVERED:  
                         change_state(BOLDERED);  
                         break;  
                 }  
             }  
             else {  
                 int open = -1;  
   
                 if (msg == "signal") {  
                     if (val.get_type() == Value::DOUBLE) {  
                         // val: 1 means "shrink", 0 means "grow"  
                         open = static_cast<int>(val.get_double());  
                         warning("received signal %i", open);  
                     }  
                     else {  
                         assert(0);  
                     }  
                 }  
                 else if (msg == "open")  
                     open = 1;  
                 else if (msg == "close")  
                     open = 0;  
   
                 if (open == 1)  { // shrink  
                     if (state == COVERED)  
                         change_state(BOLDERED);  
                 }  
                 else { // grow  
                     if (state == BOLDERED)  
                         change_state(COVERED);  
                     else if (state == SHRINKED)  
                         change_state(IDLE); // remove alarm  
   
                     if (state == IDLE) {  
                         if (Stone *st = GetStone(get_pos())) {  
                             if (st->is_kind("st-bolder"))  
                                 change_state(BOLDERED); // occurs in Per.Oxyd #84  
                             else  
                                 change_state(COVERED);  
                         }  
                         else {  
                             grow();  
                         }  
                     }  
                 }  
             }  
         }  
   
2021    
2022          void stone_change(Stone *st) {          void stone_change(Stone *st);
             if (st) {  
                 if (st->is_kind("st-bolder")) { // bolder arrived  
                     switch (state) {  
                     case IDLE:  
                         change_state(COVERED);  
                         break;  
                     case SHRINKED:  
                         change_state(BOLDERED);  
                         break;  
                     case COVERED:  
                     case BOLDERED:  
                         // two BolderStones running directly next to each other  
                         // let second pass as well (correct? siegfried says yes)  
                         break;  
                     }  
                 }  
                 else { // any other stone  
                     change_state(BOLDERED);  
                 }  
             }  
             else {              // stone disappeared  
                 switch (state) {  
                 case BOLDERED:  
                     change_state(IDLE);  
                     break;  
                 case COVERED:  
                     grow();  
                     break;  
                 case IDLE:  
                 case SHRINKED:  
                     // no action  
                     break;  
                 }  
             }  
         }  
2023    
2024          void grow() {          void grow() {
2025              Stone *st = world::MakeStone("st-blocker-growing");              Stone *st = world::MakeStone("st-blocker-growing");
# Line 2135  namespace Line 2040  namespace
2040    
2041  };  };
2042    
2043    void
2044    Blocker::message(const string &msg, const Value &val)
2045    {
2046        if (msg == "trigger" || msg == "openclose") {
2047            switch (state) {
2048            case IDLE:
2049            case SHRINKED:
2050                grow(); // if no stone on top -> grow
2051                break;
2052    
2053                // if stone on top -> toggle state (has no effect until stone leaves)
2054            case BOLDERED:
2055                change_state(COVERED);
2056                break;
2057            case COVERED:
2058                change_state(BOLDERED);
2059                break;
2060            }
2061        }
2062        else {
2063            int open = -1;
2064    
2065            if (msg == "signal") {
2066                if (val.get_type() == Value::DOUBLE) {
2067                    // val: 1 means "shrink", 0 means "grow"
2068                    open = static_cast<int>(val.get_double());
2069                    warning("received signal %i", open);
2070                }
2071                else {
2072                    assert(0);
2073                }
2074            }
2075            else if (msg == "open")
2076                open = 1;
2077            else if (msg == "close")
2078                open = 0;
2079    
2080            if (open == 1)  { // shrink
2081                if (state == COVERED)
2082                    change_state(BOLDERED);
2083            }
2084            else { // grow
2085                if (state == BOLDERED)
2086                    change_state(COVERED);
2087                else if (state == SHRINKED)
2088                    change_state(IDLE); // remove alarm
2089    
2090                if (state == IDLE) {
2091                    if (Stone *st = GetStone(get_pos())) {
2092                        if (st->is_kind("st-bolder"))
2093                            change_state(BOLDERED); // occurs in Per.Oxyd #84
2094                        else
2095                            change_state(COVERED);
2096                    }
2097                    else {
2098                        grow();
2099                    }
2100                }
2101            }
2102        }
2103    }
2104    
2105    void Blocker::stone_change(Stone *st)
2106    {
2107        if (st) {
2108            if (st->is_kind("st-bolder")) { // bolder arrived
2109                switch (state) {
2110                case IDLE:
2111                    change_state(COVERED);
2112                    break;
2113                case SHRINKED:
2114                    change_state(BOLDERED);
2115                    break;
2116                case COVERED:
2117                case BOLDERED:
2118                    // two BolderStones running directly next to each other
2119                    // let second pass as well (correct? siegfried says yes)
2120                    break;
2121                }
2122            }
2123            else { // any other stone
2124                change_state(BOLDERED);
2125            }
2126        }
2127        else {              // stone disappeared
2128            switch (state) {
2129            case BOLDERED:
2130                change_state(IDLE);
2131                break;
2132            case COVERED:
2133                grow();
2134                break;
2135            case IDLE:
2136            case SHRINKED:
2137                // no action
2138                break;
2139            }
2140        }
2141    }
2142    
2143    
2144    
2145    //----------------------------------------
2146    // Soother
2147    //----------------------------------------
2148    
2149  namespace  namespace
2150  {  {
2151      class Soother : public Item {      class Soother : public Item {
# Line 2361  namespace Line 2372  namespace
2372          void on_stonehit(Stone */*st*/) {          void on_stonehit(Stone */*st*/) {
2373              SetItem(get_pos(), MakeItem("it-explosion2"));              SetItem(get_pos(), MakeItem("it-explosion2"));
2374          }          }
   
2375      };      };
2376  }  }
2377    
# Line 2376  namespace Line 2386  namespace
2386          Rubberband() : Item ("it-rubberband") {}          Rubberband() : Item ("it-rubberband") {}
2387      };      };
2388    
2389        class HStrip : public Item {
2390            CLONEOBJ(HStrip);
2391        public:
2392            HStrip() : Item ("it-hstrip") {
2393            }
2394            bool actor_hit(Actor *a) {
2395                double ycenter = get_pos().y + 0.5;
2396                const double MAXDIST = 6.0/32;
2397                if (fabs(a->get_pos()[1] - ycenter) > MAXDIST) {
2398                    if (Floor *fl = GetFloor(get_pos()))
2399                        fl->actor_contact(a);
2400                }
2401                return false;
2402            }
2403    
2404            bool covers_floor() const { return true; }
2405        };
2406    
2407        class VStrip : public Item {
2408            CLONEOBJ(VStrip);
2409        public:
2410            VStrip() : Item ("it-vstrip") {
2411            }
2412            bool actor_hit(Actor *a) {
2413                double xcenter = get_pos().x + 0.5;
2414                const double MAXDIST = 5.0/32;
2415                if (fabs(a->get_pos()[0] - xcenter) > MAXDIST) {
2416                    if (Floor *fl = GetFloor(get_pos()))
2417                        fl->actor_contact(a);
2418                }
2419                return false;
2420            }
2421    
2422            bool covers_floor() const { return true; }
2423        };
2424    
2425  }  }
2426    
2427    
# Line 2423  void items::Init() Line 2469  void items::Init()
2469      Register(new Hammer);      Register(new Hammer);
2470      Register(new Hill);      Register(new Hill);
2471      Register(new Hollow);      Register(new Hollow);
2472        Register(new HStrip);
2473      Register(new InverseSensor);      Register(new InverseSensor);
2474      Register(new InvisibleAbyss);      Register(new InvisibleAbyss);
2475      Register(new Key);      Register(new Key);
# Line 2475  void items::Init() Line 2522  void items::Init()
2522      Register(new Umbrella);      Register(new Umbrella);
2523      Register ("it-vortex-closed", new Vortex(false));      Register ("it-vortex-closed", new Vortex(false));
2524      Register ("it-vortex-open", new Vortex(true));      Register ("it-vortex-open", new Vortex(true));
2525        Register(new VStrip);
2526      Register(new Weight);      Register(new Weight);
2527      Register(new WhiteBomb);      Register(new WhiteBomb);
2528      Register(new Wrench);      Register(new Wrench);

Legend:
Removed from v.1.85  
changed lines
  Added in v.1.86

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26