/[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.65 by dheck, Fri Jul 4 18:14:40 2003 UTC revision 1.66 by reallysoft, Sat Jul 5 08:30:26 2003 UTC
# Line 1183  namespace Line 1183  namespace
1183      {      {
1184          CLONEOBJ(Vortex);          CLONEOBJ(Vortex);
1185      public:      public:
1186          Vortex(bool opened) : Item("it-vortex"), state(opened ? OPEN : CLOSED) {          Vortex(bool opened)
1187              set_target(V2());              : Item("it-vortex")
1188                , state(opened ? OPEN : CLOSED)
1189                , close_after_warp(!opened)
1190            {
1191          }          }
1192    
1193      private:      private:
# Line 1224  namespace Line 1227  namespace
1227    
1228          V2 target() {          V2 target() {
1229              double tx, ty;              double tx, ty;
1230              double_attrib("targetx", &tx);              if (!double_attrib("targetx", &tx) || !double_attrib("targety", &ty)) {
1231              double_attrib("targety", &ty);                  // no target attributes -> search for signal
1232                    Object *target_obj = FindSignalDestination(this);
1233                    V2 t;
1234    
1235                    if (target_obj) {
1236                        GridObject *gridTarget = dynamic_cast<GridObject*>(target_obj);
1237    
1238                        if (gridTarget)
1239                            t = gridTarget->get_pos().center();
1240                        else {
1241                            target_obj->warning("signal target is not a GridObject");
1242                            t = get_pos().center(); // take own position
1243                        }
1244                    }
1245                    else {
1246                        warning("no target attributes and no signal found");
1247                        t = get_pos().center(); // take own position
1248                    }
1249                    set_target(t);
1250                    return t;
1251                }
1252              return V2(tx, ty);              return V2(tx, ty);
1253          }          }
1254          void set_target(V2 t) {          void set_target(V2 t) {
# Line 1234  namespace Line 1257  namespace
1257          }          }
1258    
1259          void open() {          void open() {
1260              if (state == CLOSED) {              if (state == CLOSED || state == CLOSING) {
1261                  state = OPENING;                  state = OPENING;
1262                  init_model();                  init_model();
1263              }              }
1264          }          }
1265          void close() {          void close() {
1266              if (state == OPEN) {              if (state == OPEN || state == OPENING) {
1267                  state = CLOSING;                  state = CLOSING;
1268                  init_model();                  init_model();
1269              }              }
1270          }          }
1271            void openclose() {
1272                if (state == OPEN || state == OPENING) close();
1273                else                                   open();
1274            }
1275    
1276          void warp();            // warp swallowed actor(s)          void warp();            // warp swallowed actor(s)
1277          void warp_to(V2 t);     // warp() using alternate target          void warp_to(V2 t);     // warp() using alternate target
1278    
1279          // Variables          // Variables
1280          enum State { OPEN, CLOSED, OPENING, CLOSING } state;          enum State { OPEN, CLOSED, OPENING, CLOSING } state;
1281            bool close_after_warp;
1282      };      };
1283  }  }
1284    
# Line 1308  void Vortex::warp() { Line 1337  void Vortex::warp() {
1337                      world::WarpActor(actor, v_target[0], v_target[1], false);                      world::WarpActor(actor, v_target[0], v_target[1], false);
1338                      SendMessage(actor, "rise");                      SendMessage(actor, "rise");
1339                      rewarp = false;                      rewarp = false;
1340    
1341                        if (this != v && close_after_warp)
1342                            close(); // close source vortex
1343                  }                  }
1344                  else if (v->state == CLOSED) { // destination is closed                  else if (v->state == CLOSED) { // destination is closed
1345                      SendMessage(v, "open");                      SendMessage(v, "open");
# Line 1331  void Vortex::warp() { Line 1363  void Vortex::warp() {
1363      }      }
1364  }  }
1365    
1366  void Vortex::message(const string &msg, const Value &) {  void Vortex::message(const string &msg, const Value &val) {
1367  //     warning("received '%s'", msg.c_str());      warning("received '%s'", msg.c_str());
1368    
1369      if (msg == "open")       open();      if (msg == "open")
1370      else if (msg == "close") close();          open();
1371      else if (msg == "warp")  warp();      else if (msg == "close" || (msg == "arrival" && close_after_warp))
1372            close();
1373        else if (msg == "warp")
1374            warp();
1375        else if (msg == "signal") {
1376            if (val.get_type() == Value::DOUBLE) {
1377                int value = static_cast<int>(val.get_double());
1378    //             warning("received signal (val=%i)", value);
1379    
1380    //             close_after_warp = false; (no - see Per.Oxyd #22)
1381                if (value) open();
1382                else close();
1383            }
1384        }
1385  }  }
1386    
1387  //----------------------------------------  //----------------------------------------
# Line 1649  namespace Line 1694  namespace
1694              Item::on_removal();              Item::on_removal();
1695          }          }
1696    
1697          void message(const string &msg, const Value &) {          void message(const string &msg, const Value &val) {
1698              if (msg == "signal" || msg == "trigger") {              if (msg == "trigger") {
1699                  switch (state) {                  switch (state) {
1700                      case IDLE:                      case IDLE:
1701                      case SHRINKED:                      case SHRINKED:
# Line 1666  namespace Line 1711  namespace
1711                          break;                          break;
1712                  }                  }
1713              }              }
1714                else if (msg == "signal") {
1715                    if (val.get_type() == Value::DOUBLE) {
1716                        int value = static_cast<int>(val.get_double());
1717    //                     warning("received signal (val=%i)", value);
1718                        if (value) { // value == 1 -> shrink
1719                            if (state == COVERED)
1720                                change_state(BOLDERED);
1721                        }
1722                        else {      // value == 0 -> grow
1723                            if (state == BOLDERED)
1724                                change_state(COVERED);
1725                            else if (state == SHRINKED)
1726                                change_state(IDLE); // remove alarm
1727    
1728                            if (state == IDLE) {
1729                                assert(!GetStone(get_pos()));
1730                                grow();
1731                            }
1732                        }
1733                    }
1734                }
1735          }          }
1736    
1737    
# Line 1799  namespace Line 1865  namespace
1865      };      };
1866  }  }
1867    
1868    // ----------------------
1869    //      SignalFilters
1870    // ----------------------
1871    namespace {
1872        class SignalFilter : public Item {
1873            CLONEOBJ(SignalFilter);
1874        public:
1875            SignalFilter(const char *kind, int type_) : Item(kind), type(type_) {
1876                assert(type >= 0 && type <= 1);
1877            }
1878        private:
1879    
1880            void init_model() { set_model("invisible"); }
1881    
1882            void message(const string& m, const Value& val) {
1883                if (m == "signal") {
1884                    int value = to_int(val);
1885    //                 warning("received signal with value %i", value);
1886                    if (value)
1887                        PerformAction(this, type);
1888                }
1889            }
1890    
1891            // type of signal filter
1892            // 0 : receive 1 -> send 0
1893            // 1 : receive 1 -> send 1
1894            int type;
1895        };
1896    }
1897    
1898  //----------------------------------------  //----------------------------------------
1899  // Remaining items (still need to be implemented)  // Remaining items (still need to be implemented)
1900  //----------------------------------------  //----------------------------------------
# Line 1817  void items::Init() Line 1913  void items::Init()
1913  {  {
1914      using world::Register;      using world::Register;
1915    
1916        Register(new SignalFilter("it-signal-filter0", 0));
1917        Register(new SignalFilter("it-signal-filter1", 1));
1918      Register(new BlackBomb);      Register(new BlackBomb);
1919      Register(new WhiteBomb);      Register(new WhiteBomb);
1920      Register(new Brake);      Register(new Brake);

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