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

Diff of /enigma/src/stones_complex.cc

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

revision 1.30 by reallysoft, Wed Jul 9 07:01:33 2003 UTC revision 1.31 by reallysoft, Fri Jul 11 11:02:23 2003 UTC
# Line 862  namespace Line 862  namespace
862          void rotate_cluster(const Cluster &c);          void rotate_cluster(const Cluster &c);
863          void maybe_rotate_cluster(Direction dir);          void maybe_rotate_cluster(Direction dir);
864    
         void shuffle(int count);  
   
865          void message(const string& msg, const Value &val);          void message(const string& msg, const Value &val);
866    
867          void on_creation();          void on_creation();
# Line 1054  PuzzleStone::maybe_move_cluster(Cluster Line 1052  PuzzleStone::maybe_move_cluster(Cluster
1052      // moving the cluster.      // moving the cluster.
1053      //      //
1054      // For partial clusters build bridges only on water and if      // For partial clusters build bridges only on water and if
1055      // the wielded item is not the magic wand.      // the wielded item is NOT the magic wand.
1056    
1057      bool create_bridge = true;      bool create_bridge = true;
1058    
# Line 1109  PuzzleStone::get_modelno() const { Line 1107  PuzzleStone::get_modelno() const {
1107  void  void
1108  PuzzleStone::rotate_cluster(const Cluster &c)  PuzzleStone::rotate_cluster(const Cluster &c)
1109  {  {
1110      if (c.size() > 1) {      unsigned size = c.size();
1111        if (size > 1) {
1112          vector<Stone*> stones;          vector<Stone*> stones;
1113          for (unsigned i=0; i<c.size(); ++i)          for (unsigned i=0; i<size; ++i)
1114              stones.push_back(YieldStone(c[i]));              stones.push_back(YieldStone(c[i]));
1115    
1116          // exclude last list item          // exclude last list item
1117          for (unsigned i=0; i<c.size()-1; ++i)          for (unsigned i=0; i<size-1; ++i)
1118              SetStone(c[i+1], stones[i]);              SetStone(c[i+1], stones[i]);
1119          SetStone(c[0], stones.back());          SetStone(c[0], stones.back());
1120      }      }
# Line 1130  PuzzleStone::collision_response(const St Line 1129  PuzzleStone::collision_response(const St
1129  }  }
1130    
1131  void  void
 PuzzleStone::shuffle(int count)  
 {  
     assert(oxyd1_compatible());  
   
     Direction move_dir = static_cast<Direction>(IntegerRand(0, 3));  
     Cluster   c;  
     find_row_or_column_cluster(c, get_pos(), reverse(move_dir), 1);  
     if (!c.empty()) {  
         GridPos last = c.back();  
         c.clear();  
         find_row_or_column_cluster(c, last, move_dir, 1);  
   
         // if cluster too small to rotate -> turn direction by 90 deg  
         if (c.size() <= 1) {  
             move_dir = rotate(move_dir, true);  
             c.clear();  
             find_row_or_column_cluster(c, last, move_dir, 1);  
         }  
   
         if (c.size() > 1) {  
   
             // @@@ FIXME:  check whether rotation is impossible  
             // (e.g. blocked by unmoveable stone at both sides)  
   
             while (count--)  
                 rotate_cluster(c);  
         }  
     }  
 }  
   
 void  
1132  PuzzleStone::trigger_explosion(double delay) {  PuzzleStone::trigger_explosion(double delay) {
1133      if (state == IDLE) {      if (state == IDLE) {
1134          state = EXPLODING;          state = EXPLODING;
# Line 1210  PuzzleStone::alarm() { Line 1178  PuzzleStone::alarm() {
1178    
1179  void  void
1180  PuzzleStone::message(const string& msg, const Value &val) {  PuzzleStone::message(const string& msg, const Value &val) {
1181      if (oxyd1_compatible()) {      if (msg == "scramble") {
1182          if (msg == "init") {          // oxyd levels contain explicit information on how to
1183              // shuffle oxyd1 style puzzle pieces at level startup.          // scramble puzzle stones. According to that information
1184              // only done this way if gametype is GAMET_ENIGMA.          // a "scramble" message is send to specific puzzle stones
1185              if (enigma::GameCompatibility == GAMET_ENIGMA) {          // together with information about the direction.
1186                  int count = options::Difficulty == DIFFICULTY_EASY          //
1187                      ? 1          // enigma levels may create scramble messages using
1188                      : IntegerRand(0, 4);          // AddScramble() and SetScrambleIntensity()
1189    
1190            Direction dir = static_cast<Direction>(val.get_double());
1191            Cluster   c;
1192            find_row_or_column_cluster(c, get_pos(), dir, oxyd1_compatible());
1193    
1194                  shuffle(count);          int size = c.size();
1195              }  
1196            // warning("received 'scramble'. dir=%s size=%i", to_suffix(dir).c_str(), size);
1197    
1198            if (size >= 2) {
1199                int count = IntegerRand(1, size-1);
1200                while (count--)
1201                    rotate_cluster(c);
1202          }          }
1203          else if (msg == "scramble") {          else {
1204              // oxyd levels contain explicit information on how to              warning("useless scramble (cluster size=%i)", size);
             // shuffle puzzle stones. According to that information  
             // a "scramble" message is send to specific puzzle stones  
             // together with information about the direction.  
             // only done this way if gametype is not GAMET_ENIGMA.  
   
             Direction dir = static_cast<Direction>(val.get_double());  
             Cluster   c;  
             find_row_or_column_cluster(c, get_pos(), dir, 1);  
   
             int size = c.size();  
             if (size >= 2) {  
                 int count = IntegerRand(1, size-1);  
                 while (count--)  
                     rotate_cluster(c);  
             }  
1205          }          }
1206      }      }
1207  }  }

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

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