--- a/hedgewars/uFLGameConfig.pas Sat Oct 25 00:31:10 2014 +0400
+++ b/hedgewars/uFLGameConfig.pas Fri Oct 31 00:36:08 2014 +0300
@@ -159,7 +159,34 @@
procedure tryAddTeam(teamName: PChar);
var msg: ansistring;
+ i, hn, hedgehogsNumber: Longword;
+ team: PTeam;
begin
+ with currentConfig do
+ begin
+ hedgehogsNumber:= 0;
+ i:= 0;
+
+ while (i < 8) and (teams[i].hogsNumber > 0) do
+ begin
+ inc(i);
+ inc(hedgehogsNumber, teams[i].hogsNumber)
+ end;
+
+ // no free space for a team or reached hogs number maximum
+ if (i > 7) or (hedgehogsNumber >= 48) then exit;
+
+ team:= teamByName(teamName);
+ if team = nil then exit;
+
+ teams[i]:= team^;
+
+ if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
+ if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
+ teams[i].hogsNumber:= hn;
+ end;
+
+
msg:= '0' + #10 + teamName;
guiCallbackFunction(guiCallbackPointer, mtAddPlayingTeam, @msg[1], length(msg));
--- a/hedgewars/uFLTeams.pas Sat Oct 25 00:31:10 2014 +0400
+++ b/hedgewars/uFLTeams.pas Fri Oct 31 00:36:08 2014 +0300
@@ -8,6 +8,8 @@
function getTeamsList: PPChar; cdecl;
procedure freeTeamsList;
+function teamByName(s: shortstring): PTeam;
+
implementation
uses uFLUtils, uFLIPC, uPhysFSLayer;
@@ -156,6 +158,20 @@
getTeamsList:= listOfTeamNames
end;
+function teamByName(s: shortstring): PTeam;
+var i: Longword;
+ team: PTeam;
+begin
+ team:= teamsList;
+ i:= 0;
+ while (i < teamsNumber) and (team^.teamName <> s) do
+ begin
+ inc(team);
+ inc(i)
+ end;
+
+ if i < teamsNumber then teamByName:= team else teamByName:= nil
+end;
procedure freeTeamsList;
begin