Fort Mode: allow more than 2 clans
authorsheepluva
Tue, 26 Apr 2016 14:41:56 +0200
changeset 11705 4b2179d9516c
parent 11704 1694b379c83f
child 11706 863e1a75ec99
Fort Mode: allow more than 2 clans
ChangeLog.txt
hedgewars/uGears.pas
hedgewars/uLand.pas
--- a/ChangeLog.txt	Tue Apr 26 14:22:54 2016 +0200
+++ b/ChangeLog.txt	Tue Apr 26 14:41:56 2016 +0200
@@ -7,6 +7,7 @@
  + 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)
+ + Fort Mode will now work with more than 2 teams
  * 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	Tue Apr 26 14:22:54 2016 +0200
+++ b/hedgewars/uGears.pas	Tue Apr 26 14:41:56 2016 +0200
@@ -829,7 +829,7 @@
 // in section-divide mode, divide the map into equal-width sections and put each clan in one of them
 if sectionDivide then
     begin
-    t:= 0;
+    t:= leftX;
     for p:= 0 to (ClansCount - 1) do
         begin
         with ClansArray[p]^ do
@@ -842,7 +842,7 @@
                                 if PlacingHogs then
                                     Unplaced:= true
                                 else
-                                    FindPlace(Gear, false, t, t + LAND_WIDTH div ClansCount, true);// could make Gear == nil;
+                                    FindPlace(Gear, false, t, t + playWidth div ClansCount, true);// could make Gear == nil;
                                 if Gear <> nil then
                                     begin
                                     Gear^.Pos:= GetRandom(49);
@@ -853,7 +853,7 @@
                                         Gear^.dX.isNegative:= (GetRandom(2) = 1);
                                     end
                                 end;
-        inc(t, LAND_WIDTH div ClansCount);
+        inc(t, playWidth div ClansCount);
         end
     end 
 else // mix hedgehogs
@@ -876,10 +876,10 @@
         if PlacingHogs then
             ar[i]^.Unplaced:= true
         else
-            FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH, true);
+            FindPlace(ar[i]^.Gear, false, leftX, playWidth, true);
         if ar[i]^.Gear <> nil then
             begin
-            ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > LAND_WIDTH div 2;
+            ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > leftX + playWidth div 2;
             ar[i]^.Gear^.Pos:= GetRandom(19)
             end;
         ar[i]:= ar[Count - 1];
--- a/hedgewars/uLand.pas	Tue Apr 26 14:22:54 2016 +0200
+++ b/hedgewars/uLand.pas	Tue Apr 26 14:41:56 2016 +0200
@@ -350,33 +350,57 @@
 
 procedure MakeFortsMap;
 var tmpsurf: PSDL_Surface;
+    i: integer;
+    mirror: boolean;
+const sectionWidth = 1024 + 300;
 begin
-ResizeLand(4096,2048);
-MaxHedgehogs:= 32;
+// figure out how much space we need
+playWidth:= sectionWidth * ClansCount;
+
+// note: LAND_WIDTH might be bigger than specified below (rounded to next power of 2)
+ResizeLand(playWidth, 2048);
+
 // For now, defining a fort is playable area as 3072x1200 - there are no tall forts.  The extra height is to avoid triggering border with current code, also if user turns on a border, it will give a bit more maneuvering room.
 playHeight:= 1200;
-playWidth:= 2560;
-leftX:= (LAND_WIDTH - playWidth) div 2;
+
+// center playable area in land array
+leftX:= ((LAND_WIDTH - playWidth) div 2);
 rightX:= ((playWidth + (LAND_WIDTH - playWidth) div 2) - 1);
 topY:= LAND_HEIGHT - playHeight;
 
 WriteLnToConsole('Generating forts land...');
 
-tmpsurf:= LoadDataImage(ptForts, ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
-BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
-SDL_FreeSurface(tmpsurf);
+for i := 0 to ClansCount - 1 do
+    begin
+
+    // face in random direction
+    mirror:= (GetRandom(2) = 0);
+    // make first/last fort face inwards
+    if WorldEdge <> weWrap then
+        mirror:= (i <> 0) and (mirror or (i = ClansCount));
 
-// not critical because if no R we can fallback to mirrored L
-tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
-// fallback
-if tmpsurf = nil then
-    begin
-    tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
-    BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf, 0, true);
-    end
-else
-    BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
-SDL_FreeSurface(tmpsurf);
+    if mirror then
+        begin
+        // not critical because if no R we can fallback to mirrored L
+        tmpsurf:= LoadDataImage(ptForts, ClansArray[i]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
+        // fallback
+        if tmpsurf = nil then
+            begin
+            tmpsurf:= LoadDataImage(ptForts, ClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
+            BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf, 0, true);
+            end
+        else
+            BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
+        SDL_FreeSurface(tmpsurf);
+        end
+    else
+        begin
+        tmpsurf:= LoadDataImage(ptForts, ClansArray[i]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
+        BlitImageAndGenerateCollisionInfo(leftX + sectionWidth * i + ((sectionWidth - tmpsurf^.w) div 2), LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
+        SDL_FreeSurface(tmpsurf);
+        end;
+
+    end;
 end;
 
 procedure LoadMapConfig;