]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add an unfill mode to the fill tool
authorMario <mario@smbclan.net>
Sun, 15 Nov 2015 19:24:04 +0000 (05:24 +1000)
committerMario <mario@smbclan.net>
Sun, 15 Nov 2015 19:24:04 +0000 (05:24 +1000)
qcsrc/common/minigames/minigame/bd.qc

index 78892cef2fdd2c4c053f002e301c110ad9a8f728..d002adaff45ebba3669eedba311a02976f97c9ad 100644 (file)
@@ -285,14 +285,58 @@ void bd_fill_recurse(entity minigame, entity player, int thetype, int letter, in
        bd_fill_recurse(minigame, player, thetype, letter, number + 1);
 }
 
+void bd_unfill_recurse(entity minigame, entity player, int thetype, int letter, int number)
+{
+       string pos = minigame_tile_buildname(letter,number);
+       if(!bd_valid_tile(pos))
+               return;
+
+       entity targ = bd_find_piece(minigame, pos, true);
+       entity piece = bd_find_piece(minigame, pos, false);
+
+       if(targ && thetype == targ.bd_tiletype)
+       {
+               if(targ.netname) { strunzone(targ.netname); }
+               remove(targ);
+       }
+       else if(piece && thetype == piece.bd_tiletype)
+       {
+               if(piece.netname) { strunzone(piece.netname); }
+               remove(piece);
+       }
+       else return;
+
+       bd_unfill_recurse(minigame, player, thetype, letter - 1, number);
+       bd_unfill_recurse(minigame, player, thetype, letter + 1, number);
+       bd_unfill_recurse(minigame, player, thetype, letter, number - 1);
+       bd_unfill_recurse(minigame, player, thetype, letter, number + 1);
+}
+
 void bd_do_fill(entity minigame, entity player, string dir, string thetile)
 {
        if(minigame.minigame_flags & BD_TURN_EDIT)
        {
                int thetype = stof(thetile);
 
-               if(!bd_canfill(thetype))
+               entity targ = bd_find_piece(minigame, dir, true);
+               entity piece = bd_find_piece(minigame, dir, false);
+
+               if(!bd_canfill(thetype) || (piece || targ))
+               {
+                       int killtype = 0;
+
+                       if(targ) { killtype = targ.bd_tiletype; }
+                       if(piece) { killtype = piece.bd_tiletype; }
+
+                       if(killtype)
+                       {
+                               int letter = minigame_tile_letter(dir);
+                               int number = minigame_tile_number(dir);
+                               bd_unfill_recurse(minigame, player, killtype, letter, number);
+                       }
+
                        return;
+               }
 
                int letter = minigame_tile_letter(dir);
                int number = minigame_tile_number(dir);