"divided teams" modifier will now work with more than 2 teams!
authorsheepluva
Mon, 25 Apr 2016 21:12:34 +0200
changeset 11705 ea1097d7bd27
parent 11703 e86feecadced
child 11706 e71435e046a1
"divided teams" modifier will now work with more than 2 teams!
ChangeLog.txt
hedgewars/uGears.pas
--- a/ChangeLog.txt	Mon Apr 25 16:11:39 2016 +0200
+++ b/ChangeLog.txt	Mon Apr 25 21:12:34 2016 +0200
@@ -6,6 +6,7 @@
  + Highlander mode displays game scheme specifics (mines timer, etc.) in ESC info
  + AI hedgehogs know how to use Bee now
  + Small visual effects enhancements
+ + Divided Teams mode will now work with more than 2 teams (Hint: you probably want to set world edges to "wrap" in such games)
  * Video recording functionality is restored
  * Gameplay fix: Hammer damage is now rounded down. This means it will cause NO DAMAGE to a hedgehog with less than 3 hp.
  * Fixed bee not being affected by wrap world edge while still being thrown
--- a/hedgewars/uGears.pas	Mon Apr 25 16:11:39 2016 +0200
+++ b/hedgewars/uGears.pas	Mon Apr 25 21:12:34 2016 +0200
@@ -745,11 +745,11 @@
 begin
 if (GameFlags and gfPlaceHog) <> 0 then
     PlacingHogs:= true;
-if (ClansCount = 2) and ((GameFlags and gfDivideTeams) <> 0) then
+// in divided-teams mode, slice map into vertical stripes of identical length and spawn one clan in each slice
+if {((ClansCount = 2) or ((GameFlags and gfForts) <> 0)) and} ((GameFlags and gfDivideTeams) <> 0) then
     begin
     t:= 0;
-    if checkFails(ClansCount = 2, 'More or less than 2 clans on map in divided teams mode!', true) then exit;
-    for p:= 0 to 1 do
+    for p:= 0 to (ClansCount - 1) do
         begin
         with ClansArray[p]^ do
             for j:= 0 to Pred(TeamsNumber) do
@@ -761,14 +761,18 @@
                                 if PlacingHogs then
                                     Unplaced:= true
                                 else
-                                    FindPlace(Gear, false, t, t + LAND_WIDTH div 2, true);// could make Gear == nil;
+                                    FindPlace(Gear, false, t, t + LAND_WIDTH div ClansCount, true);// could make Gear == nil;
                                 if Gear <> nil then
                                     begin
                                     Gear^.Pos:= GetRandom(49);
-                                    Gear^.dX.isNegative:= p = 1;
+                                    // unless the world is wrapping, make outter teams face to map center
+                                    if (WorldEdge <> weWrap) and ((p = 0) or (p = ClansCount - 1)) then
+                                        Gear^.dX.isNegative:= (p <> 0)
+                                    else
+                                        Gear^.dX.isNegative:= (GetRandom(2) = 1);
                                     end
                                 end;
-        t:= LAND_WIDTH div 2
+        inc(t, LAND_WIDTH div ClansCount);
         end
     end 
 else // mix hedgehogs