/[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.7 by dheck, Thu Jan 23 22:41:00 2003 UTC revision 1.8 by dheck, Sun Feb 2 18:20:49 2003 UTC
# Line 44  Item::get_inventory_model() Line 44  Item::get_inventory_model()
44      return get_kind();      return get_kind();
45  }  }
46    
47    void Item::stone_change (Stone *st) {}
48    void Item::on_stonehit (Stone *st) {}
49    void Item::on_drop (Actor *a) {}
50    void Item::on_pickup (Actor *a) {}
51    
52    ItemAction Item::activate(Actor* a, GridPos p)
53    { return ITEM_DROP; }
54    
55    
56    px::V3 Item::get_force(Actor *a)
57    { return px::V3(); }
58    
59  bool  bool
60  Item::actor_hit(Actor *actor)  Item::actor_hit(Actor *actor)
61  {  {
# Line 66  Item::actor_hit(Actor *actor) Line 78  Item::actor_hit(Actor *actor)
78    
79  namespace  namespace
80  {  {
     DEF_ITEM(Hammer, "it-hammer");  
81      DEF_ITEM(MagicWand, "it-magicwand");      DEF_ITEM(MagicWand, "it-magicwand");
82      DEF_ITEM(Umbrella, "it-umbrella");      DEF_ITEM(Umbrella, "it-umbrella");
83      DEF_ITEM(Floppy, "it-floppy");      DEF_ITEM(Floppy, "it-floppy");
84      DEF_ITEM(Brush, "it-brush");      DEF_ITEM(Brush, "it-brush");
85      DEF_ITEM(Sword, "it-sword");  
86        class Sword : public Item {
87            CLONEOBJ(Sword);
88            bool on_laserhit(Direction d) {
89                play_sound("st-magic");
90                world::SetItem(get_pos(), MakeItem("it-hammer"));
91                return false;
92            }
93        public:
94            Sword() : Item("it-sword") {}
95        };
96    
97        class Hammer : public Item {
98            CLONEOBJ(Hammer);
99            bool on_laserhit(Direction d) {
100                play_sound("st-magic");
101                world::SetItem(get_pos(), MakeItem("it-sword"));
102                return false;
103            }
104        public:
105            Hammer() : Item("it-hammer") {}
106        };
107    
108      class ExtraLife : public Item {      class ExtraLife : public Item {
109          CLONEOBJ(ExtraLife);          CLONEOBJ(ExtraLife);
# Line 121  namespace Line 153  namespace
153          Coin() : Item("it-coin") { set_attrib("value", 1.0); }          Coin() : Item("it-coin") { set_attrib("value", 1.0); }
154      private:      private:
155          void init_model() { set_model(get_inventory_model()); }          void init_model() { set_model(get_inventory_model()); }
156    
157            bool on_laserhit(Direction d) {
158                play_sound("st-magic");
159                switch(get_value()) {
160                case 1: SetItem (get_pos(), MakeItem("it-umbrella")); break;
161                case 2: SetItem (get_pos(), MakeItem("it-hammer")); break;
162                default: SetItem (get_pos(), MakeItem("it-extralife")); break;
163                }
164                return false;
165            }
166    
167            void on_stonehit(Stone *st) {
168                switch(get_value()) {
169                case 1: set_attrib("value", 2.0); init_model(); break;
170                case 2: set_attrib("value", 4.0); init_model(); break;
171                default: break;
172                }
173            }
174    
175          string get_inventory_model()          string get_inventory_model()
176          {          {
177              int value=int_attrib("value");              switch(get_value()) {
             switch(value) {  
178              case 1: return "it-coin1";              case 1: return "it-coin1";
179              case 2: return "it-coin2";              case 2: return "it-coin2";
180              default:return "it-coin4";              default: return "it-coin4";
181              }              }
182          }          }
183    
184            int get_value() {
185                int value = int_attrib("value");
186    //            assert (value==1 || value==2 || value==4);
187                return value;
188            }
189      };      };
190  }  }
191    
# Line 154  namespace Line 210  namespace
210      protected:      protected:
211          enum Type { HILL, HOLLOW, TINYHILL, TINYHOLLOW };          enum Type { HILL, HOLLOW, TINYHILL, TINYHOLLOW };
212                    
213          HillHollow(const char *name, Type t) : Item(name), m_type(t) {}          HillHollow(const char *name, Type t);
214    
215          void transmute(Type newtype);          void transmute(Type newtype);
216          V3 vec_to_center (V3 v);          V3 vec_to_center (V3 v);
217          double get_radius() const { return m_radius[m_type]; }          double get_radius() const { return m_radius[m_type]; }
218    
219      private:      private:
220          double get_forcefac() const { return m_forcefac[m_type]; }          double get_forcefac() const { return m_forcefac[m_type]; }
221            void shovel();
222                    
         // Variables.  
         static double m_radius[4], m_forcefac[4];  
         Type m_type;  
   
223          // Item interface          // Item interface
224          px::V3 get_force(Actor *a);          px::V3 get_force(Actor *a);
225          bool actor_hit(Actor *a) { return false; }          bool actor_hit(Actor *a) { return false; }
226            void on_stonehit(Stone *st);
227    
228          // Object interface.          // Object interface.
229          void message(const string &m, const Value &);          void message(const string &m, const Value &);
230    
231            // Variables.
232            static double m_radius[4], m_forcefac[4];
233            Type m_type;
234      };      };
235  }  }
236    
237  double HillHollow::m_radius[4] = {0.5, 0.5, 0.3, 0.3};  double HillHollow::m_radius[4] = {0.5, 0.5, 0.3, 0.3};
238  double HillHollow::m_forcefac[4] = {90,-90, 90, -90};  double HillHollow::m_forcefac[4] = {90,-90, 90, -90};
239    
240    
241    HillHollow::HillHollow(const char *name, Type t)
242    : Item(name), m_type(t)
243    {}
244    
245    void HillHollow::on_stonehit(Stone *st)
246    {
247        shovel();
248    }
249    
250    void HillHollow::shovel()
251    {
252        if (m_type==HOLLOW)
253            transmute (TINYHOLLOW);
254        else if (m_type==HILL)
255            transmute (TINYHILL);
256        else
257            KillItem(get_pos());
258    }
259    
260    
261  void HillHollow::message(const string &m, const Value &)  void HillHollow::message(const string &m, const Value &)
262  {  {
263      if (m=="trigger") {      if (m=="trigger") {
264          Type flippedkind[] = {HOLLOW,HILL, TINYHOLLOW,TINYHILL};          Type flippedkind[] = {HOLLOW,HILL, TINYHOLLOW,TINYHILL};
265          transmute(flippedkind[m_type]);          transmute(flippedkind[m_type]);
266      }      }
267      else if (m=="shovel") {      else if (m=="shovel")
268          if (m_type==HOLLOW) transmute(TINYHOLLOW);          shovel();
         else if (m_type==HILL) transmute(TINYHILL);  
         else  
             KillItem(get_pos());  
     }  
269  }  }
270    
271  V3 HillHollow::vec_to_center (V3 v)  V3 HillHollow::vec_to_center (V3 v)
# Line 209  V3 HillHollow::get_force(Actor *a) Line 285  V3 HillHollow::get_force(Actor *a)
285    
286  void HillHollow::transmute(Type newtype)  void HillHollow::transmute(Type newtype)
287  {  {
 #if 0  
     string name;  
     Item *newitem = MakeItem(newkind);  
     if (string_attrib("name", &name)) {  
         SetItem(get_pos(), newitem);  
         newitem->set_attrib("name", name.c_str());  
         NameObject(newitem, name);  
     } else {  
         SetItem(get_pos(), newitem);  
     }  
 #else  
288      m_type = newtype;      m_type = newtype;
289      static char *modelname[] = { "it-hill", "it-hollow",      static char *modelname[] = { "it-hill", "it-hollow",
290                                   "it-tinyhill", "it-tinyhollow" };                                   "it-tinyhill", "it-tinyhollow" };
291      set_model(modelname[m_type]);      set_model(modelname[m_type]);
 #endif  
292  }  }
293    
294  namespace  namespace
# Line 645  namespace Line 709  namespace
709      class Seed : public Item {      class Seed : public Item {
710          CLONEOBJ(Seed);          CLONEOBJ(Seed);
711          enum State { IDLE, GROWING } state;          enum State { IDLE, GROWING } state;
     public:  
         Seed() : Item ("it-seed"), state(IDLE) {}  
712    
713          bool actor_hit(Actor *a) { return state==IDLE; }          bool actor_hit(Actor *a) { return state==IDLE; }
714          void on_drop(Actor *a) { state=GROWING; set_anim("it-seed-growing"); }          void on_drop(Actor *a) { start_growing(); }
715            void on_stonehit(Stone *) { start_growing(); }
716            
717            void start_growing() {
718                state=GROWING;
719                set_anim("it-seed-growing");
720            }
721    
722          void animcb() {          void animcb() {
723              Stone *st = world::MakeStone("st-wood-growing");              Stone *st = world::MakeStone("st-wood-growing");
724              world::SetStone(get_pos(), st);              world::SetStone(get_pos(), st);
725              world::KillItem(get_pos());              world::KillItem(get_pos());
726          }          }
727    
728        public:
729            Seed() : Item ("it-seed"), state(IDLE) {}
730    
731      };      };
732  }  }
733    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

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