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

Diff of /enigma/src/objects.cc

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

revision 1.65 by reallysoft, Thu May 8 23:10:54 2003 UTC revision 1.66 by reallysoft, Fri May 9 10:50:46 2003 UTC
# Line 33  Line 33 
33  #include <algorithm>  #include <algorithm>
34  #include <string>  #include <string>
35  #include <cstdlib>  #include <cstdlib>
36    #include <cstdarg>
37  #include <iostream>  #include <iostream>
38  #include <cassert>  #include <cassert>
39    
# Line 166  Object::double_attrib(const string &name Line 167  Object::double_attrib(const string &name
167      return false;      return false;
168  }  }
169    
170    void
171    Object::log(const char *format, ...) const {
172        va_list arg_ptr;
173    
174        va_start(arg_ptr, format);
175        fprintf(stderr, "non-grid-\"%s\": ", get_kind());
176        vfprintf(stderr, format, arg_ptr);
177        fputc('\n', stderr);
178        fflush(stderr);
179        va_end(arg_ptr);
180    }
181    
182  //----------------------------------------  //----------------------------------------
183  // GridObject  // GridObject
184  //----------------------------------------  //----------------------------------------
# Line 175  GridObject::play_sound(const char *name) Line 188  GridObject::play_sound(const char *name)
188      sound::PlaySound(name, px::V2(get_pos().x+0.5, get_pos().y+0.5));      sound::PlaySound(name, px::V2(get_pos().x+0.5, get_pos().y+0.5));
189  }  }
190    
191    void
192    GridObject::log(const char *format, ...) const {
193        va_list        arg_ptr;
194        const GridPos& pos = get_pos();
195    
196        va_start(arg_ptr, format);
197        fprintf(stderr, "\"%s\" at %i/%i: ", get_kind(), pos.x, pos.y);
198        vfprintf(stderr, format, arg_ptr);
199        fputc('\n', stderr);
200        fflush(stderr);
201        va_end(arg_ptr);
202    }
203    
204    
205    
206    
207  //======================================================================  //======================================================================
# Line 1187  namespace Line 1214  namespace
1214              change_state(BREAK);              change_state(BREAK);
1215              return false;              return false;
1216          }          }
1217          void Break_acblack::message(const string &msg, const Value &) {          void message(const string &msg, const Value &) {
1218              if (msg =="ignite")              if (msg =="ignite")
1219                  change_state(BREAK);                  change_state(BREAK);
1220          }          }
# Line 1573  namespace Line 1600  namespace
1600          }          }
1601    
1602          void alarm() {          void alarm() {
1603              state = MOVING;              state              = MOVING;
1604              GridPos p = get_pos();              GridPos   last_pos = get_pos();
1605              if (move_stone(get_dir())) {              Direction dir      = get_dir();
1606    
1607                if (move_stone(dir)) {
1608                  // send a message to the stone that's blocking our way                  // send a message to the stone that's blocking our way
1609                  Stone *st = GetStone(move(move(p,get_dir()),get_dir()));                  GridPos  next_pos = move(get_pos(), dir);
1610                  if( st) SendMessage(st, "trigger", Value(get_dir()));                  Stone   *st       = GetStone(next_pos);
1611    
1612                    if (st) {
1613                        log("BolderStone sends 'trigger'");
1614                        SendMessage(st, "trigger", Value(dir));
1615                    }
1616    
1617                    // send a message to items that were below the BolderStone
1618                    // before it moved (e.g. Blocker items)
1619    
1620                    Item *it = GetItem(last_pos);
1621                    if (it) {
1622                        log("BolderStone sends 'grow'");
1623                        SendMessage(it, "grow");
1624                    }
1625              }              }
1626              state = IDLE;              state = IDLE;
1627          }          }
# Line 1607  namespace Line 1650  namespace
1650          }          }
1651    
1652          void actor_inside(Actor *a) {SendMessage(a, "shatter");}          void actor_inside(Actor *a) {SendMessage(a, "shatter");}
1653    
1654      };      };
1655  }  }
1656    
1657  //----------------------------------------  //----------------------------------------
1658    // BlockerStone
1659    //----------------------------------------
1660    
1661    /** \page st-blocker Blocker Stone
1662    
1663    The BlockerStone acts like a normal stone until it is hit by a
1664    BolderStone. Then it shrinks and morphs into a 'Blocker' item.
1665    
1666    */
1667    
1668    namespace {
1669        class BlockerStone : public Stone
1670        {
1671            CLONEOBJ(BlockerStone);
1672        public:
1673            BlockerStone(bool solid)
1674                : Stone(solid ? "st-blocker" : "st-blocker-growing")
1675                , state(solid ? SOLID : GROWING)
1676            {}
1677    
1678        private:
1679            enum State { SOLID, SHRINKING, GROWING } state;
1680    
1681            void init_model() {
1682                switch (state) {
1683                    case SOLID:
1684                        set_model("st-blocker");
1685                        break;
1686    
1687                    case SHRINKING:
1688                        set_anim("st-blocker-shrinking");
1689                        break;
1690    
1691                    case GROWING:
1692                        set_anim("st-blocker-growing");
1693                        break;
1694                }
1695            }
1696    
1697            void animcb() {
1698                switch (state) {
1699                    case SHRINKING: {
1700                        Item *it = world::MakeItem("it-blocker-new");
1701                        world::SetItem(get_pos(), it);
1702                        world::KillStone(get_pos());
1703                        break;
1704                    }
1705                    case GROWING:
1706                        state = SOLID;
1707                        init_model();
1708                        break;
1709                }
1710            }
1711    
1712            void message(const string &msg, const Value &) {
1713                if (msg == "trigger" && state == SOLID) {
1714                    state = SHRINKING;
1715                    init_model();
1716                }
1717            }
1718        };
1719    };
1720    
1721    //----------------------------------------
1722  // PuzzleStones  // PuzzleStones
1723  //----------------------------------------  //----------------------------------------
1724    
# Line 2557  ShogunStone::get_holes() const Line 2665  ShogunStone::get_holes() const
2665      if (h>=1 && h<=7)      if (h>=1 && h<=7)
2666          return Holes(h);          return Holes(h);
2667      else {      else {
2668          fprintf(stderr, "Wrong `holes' attribute\n");          log("Wrong 'holes' attribute (%i)", h);
2669          return SMALL;          return SMALL;
2670      }      }
2671  }  }
# Line 4302  ObjectRepos::ObjectRepos() Line 4410  ObjectRepos::ObjectRepos()
4410      add_templ("st-bolder-e", new BolderStone(EAST));      add_templ("st-bolder-e", new BolderStone(EAST));
4411      add_templ("st-bolder-s", new BolderStone(SOUTH));      add_templ("st-bolder-s", new BolderStone(SOUTH));
4412      add_templ("st-bolder-w", new BolderStone(WEST));      add_templ("st-bolder-w", new BolderStone(WEST));
4413        add_templ(new BlockerStone(true));
4414        add_templ(new BlockerStone(false));
4415      add_templ(new BombStone);      add_templ(new BombStone);
4416      add_templ(new BombStone_a);      add_templ(new BombStone_a);
4417      add_templ(new BrickMagic);      add_templ(new BrickMagic);

Legend:
Removed from v.1.65  
changed lines
  Added in v.1.66

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