/[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.43 by dheck, Sat Jun 14 12:17:09 2003 UTC revision 1.44 by dheck, Sun Jun 15 10:36:07 2003 UTC
# Line 1341  namespace Line 1341  namespace
1341      class Crack : public Item {      class Crack : public Item {
1342          CLONEOBJ(Crack);          CLONEOBJ(Crack);
1343      public:      public:
1344          Crack() : Item("it-crack"),anim_end(false)          Crack() : Item("it-crack"), state(IDLE), anim_end(false)
1345          {          {
1346              set_attrib("type", 0.0);              set_attrib("type", 0.0);
1347              set_attrib("fixed", 0.0);              set_attrib("fixed", 0.0);
1348          }          }
1349      private:      private:
1350            enum State { IDLE, CRACKING1, CRACKING2 } state;
1351          bool anim_end;          bool anim_end;
1352    
1353          int get_type() const { return int_attrib("type"); }          int get_type() const { return int_attrib("type"); }
# Line 1354  namespace Line 1355  namespace
1355    
1356          void init_model() {          void init_model() {
1357              if (int t=get_type()) {              if (int t=get_type()) {
1358                  if( t > 3)                  if (t > 3) {
1359                        state = CRACKING1;
1360                      set_anim("it-crack_anim1");                      set_anim("it-crack_anim1");
1361                  //SetItem(get_pos(), MakeItem("it-debris"));                  //SetItem(get_pos(), MakeItem("it-debris"));
1362                  else {                  }else {
1363                      char modelname[20];                      char modelname[20];
1364                      sprintf(modelname, "it-crack%d", t);                      sprintf(modelname, "it-crack%d", t);
1365                      set_model(modelname);                      set_model(modelname);
# Line 1367  namespace Line 1369  namespace
1369                  set_model("invisible");                  set_model("invisible");
1370          }          }
1371          void animcb() {          void animcb() {
1372              if (anim_end) {              if (state == CRACKING2) {
1373                  GridPos p= get_pos();                  GridPos p= get_pos();
1374                  SetFloor(p, MakeFloor("fl-abyss"));                  SetFloor(p, MakeFloor("fl-abyss"));
1375                  KillItem(p);                  KillItem(p);
1376              } else {              } else {
1377                  anim_end = true;                  state = CRACKING2;
1378                  set_anim("it-crack_anim2");                  set_anim("it-crack_anim2");
1379              }              }
1380          }          }
# Line 1381  namespace Line 1383  namespace
1383              if (Item *it = GetItem(p))              if (Item *it = GetItem(p))
1384                  SendMessage (it, "crack");                  SendMessage (it, "crack");
1385              else if (Floor *fl = GetFloor(p))              else if (Floor *fl = GetFloor(p))
1386                  if (fl->get_kind() != "fl-abyss")                  if (fl->get_kind() != "fl-abyss" && do_crack()) {
1387                      SetItem(p, MakeItem("it-crack"));                      SetItem(p, MakeItem("it-crack"));
1388                    }
1389          }          }
1390    
1391          void actor_enter(Actor */*a*/) {          void actor_enter(Actor */*a*/) {
             if (is_fixed())  
                 return;  
   
1392              SendMessage(this, "crack");              SendMessage(this, "crack");
1393    
1394              if (get_type() <= 3) {              if (get_type() <= 3) {
# Line 1405  namespace Line 1405  namespace
1405              return false;              return false;
1406          }          }
1407          void message(const string &msg, const Value &/*val*/) {          void message(const string &msg, const Value &/*val*/) {
1408              if ((msg == "crack") && !is_fixed()) {              if (msg == "crack" && state==IDLE && !is_fixed()) {
1409                  set_attrib("type", Value(int_attrib("type") + 1));                  int type = get_type();
1410                  play_sound("crack");                  if ((type == 0 && do_crack()) || (type > 0)) {
1411                  init_model();                      set_attrib("type", Value(int_attrib("type") + 1));
1412                        play_sound("crack");
1413                        init_model();
1414                    }
1415              }              }
1416          }          }
1417    
1418            bool do_crack() {
1419                double brittleness = enigma::Brittleness;
1420                double_attrib ("brittleness", &brittleness);
1421                double rnd = rand() / (RAND_MAX+1.0);
1422                return rnd < brittleness;
1423            }
1424      };      };
1425    
1426      class Debris : public Item {      class Debris : public Item {

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.44

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