hedgewars/uTeams.pas
branchwebgl
changeset 9950 2759212a27de
parent 9521 8054d9d775fd
parent 9790 0b4b9fda5bd4
child 10015 4feced261c68
equal deleted inserted replaced
9521:8054d9d775fd 9950:2759212a27de
    39 procedure RestoreTeamsFromSave;
    39 procedure RestoreTeamsFromSave;
    40 function  CheckForWin: boolean;
    40 function  CheckForWin: boolean;
    41 procedure TeamGoneEffect(var Team: TTeam);
    41 procedure TeamGoneEffect(var Team: TTeam);
    42 procedure SwitchCurrentHedgehog(newHog: PHedgehog);
    42 procedure SwitchCurrentHedgehog(newHog: PHedgehog);
    43 
    43 
       
    44 var MaxTeamHealth: LongInt;
       
    45 
    44 implementation
    46 implementation
    45 uses uLocale, uAmmos, uChat, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug,
    47 uses uLocale, uAmmos, uChat, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug,
    46     uGearsUtils, uGearsList, uVisualGearsList, uTextures
    48     uGearsUtils, uGearsList, uVisualGearsList, uTextures
    47     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
    49     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
    48 
    50 
    49 var MaxTeamHealth: LongInt;
    51 var GameOver: boolean;
    50     GameOver: boolean;
       
    51     NextClan: boolean;
    52     NextClan: boolean;
    52 
    53 
    53 function CheckForWin: boolean;
    54 function CheckForWin: boolean;
    54 var AliveClan: PClan;
    55 var AliveClan: PClan;
    55     s: shortstring;
    56     s: shortstring;
   478         if Hedgehogs[i].Gear <> nil then
   479         if Hedgehogs[i].Gear <> nil then
   479             inc(TeamHealth, Hedgehogs[i].Gear^.Health)
   480             inc(TeamHealth, Hedgehogs[i].Gear^.Health)
   480         else if Hedgehogs[i].GearHidden <> nil then
   481         else if Hedgehogs[i].GearHidden <> nil then
   481             inc(TeamHealth, Hedgehogs[i].GearHidden^.Health);
   482             inc(TeamHealth, Hedgehogs[i].GearHidden^.Health);
   482 
   483 
   483     if not hasGone then
   484     if TeamHealth > MaxTeamHealth then
   484         NewTeamHealthBarWidth:= TeamHealth
   485         begin
   485         else
   486         MaxTeamHealth:= TeamHealth;
   486         NewTeamHealthBarWidth:= 0;
       
   487 
       
   488     if NewTeamHealthBarWidth > MaxTeamHealth then
       
   489         begin
       
   490         MaxTeamHealth:= NewTeamHealthBarWidth;
       
   491         RecountAllTeamsHealth;
   487         RecountAllTeamsHealth;
   492         end else if NewTeamHealthBarWidth > 0 then
   488         end
   493             NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
       
   494     end;
   489     end;
   495 
   490 
   496 RecountClanHealth(team^.Clan);
   491 RecountClanHealth(team^.Clan);
   497 
   492 
   498 AddVisualGear(0, 0, vgtTeamHealthSorter)
   493 AddVisualGear(0, 0, vgtTeamHealthSorter)
   526             if Hedgehogs[i].GearHidden <> nil then
   521             if Hedgehogs[i].GearHidden <> nil then
   527                 RestoreHog(@Hedgehogs[i]);
   522                 RestoreHog(@Hedgehogs[i]);
   528 
   523 
   529             if Gear <> nil then
   524             if Gear <> nil then
   530                 begin
   525                 begin
   531                 Gear^.Invulnerable:= false;
   526                 Gear^.Hedgehog^.Effects[heInvulnerable]:= 0;
   532                 Gear^.Damage:= Gear^.Health;
   527                 Gear^.Damage:= Gear^.Health;
   533                 Gear^.State:= (Gear^.State or gstHHGone) and (not gstHHDriven)
   528                 Gear^.State:= (Gear^.State or gstHHGone) and (not gstHHDriven)
   534                 end
   529                 end
   535             end
   530             end
   536 end;
   531 end;
   545 with CurrentTeam^ do
   540 with CurrentTeam^ do
   546     begin
   541     begin
   547     SplitBySpace(id, s);
   542     SplitBySpace(id, s);
   548     SwitchCurrentHedgehog(@Hedgehogs[HedgehogsNumber]);
   543     SwitchCurrentHedgehog(@Hedgehogs[HedgehogsNumber]);
   549     CurrentHedgehog^.BotLevel:= StrToInt(id);
   544     CurrentHedgehog^.BotLevel:= StrToInt(id);
       
   545     CurrentHedgehog^.Team:= CurrentTeam;
   550     Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0);
   546     Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0);
   551     SplitBySpace(s, id);
   547     SplitBySpace(s, id);
   552     Gear^.Health:= StrToInt(s);
   548     Gear^.Health:= StrToInt(s);
   553     TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true);
   549     TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true);
   554     Gear^.Hedgehog^.Team:= CurrentTeam;
       
   555     if (GameFlags and gfSharedAmmo) <> 0 then
   550     if (GameFlags and gfSharedAmmo) <> 0 then
   556         CurrentHedgehog^.AmmoStore:= Clan^.ClanIndex
   551         CurrentHedgehog^.AmmoStore:= Clan^.ClanIndex
   557     else if (GameFlags and gfPerHogAmmo) <> 0 then
   552     else if (GameFlags and gfPerHogAmmo) <> 0 then
   558         begin
   553         begin
   559         AddAmmoStore;
   554         AddAmmoStore;
   686     if oldCI then AddCI(oldHH^.Gear);
   681     if oldCI then AddCI(oldHH^.Gear);
   687     if newCI then AddCI(newHog^.Gear)
   682     if newCI then AddCI(newHog^.Gear)
   688 end;
   683 end;
   689 
   684 
   690 
   685 
       
   686 procedure chSetHat(var s: shortstring);
       
   687 begin
       
   688 if (not isDeveloperMode) or (CurrentTeam = nil) then exit;
       
   689 with CurrentTeam^ do
       
   690     begin
       
   691     if not CurrentHedgehog^.King then
       
   692     if (s = '')
       
   693     or (((GameFlags and gfKing) <> 0) and (s = 'crown'))
       
   694     or ((Length(s) > 39) and (Copy(s,1,8) = 'Reserved') and (Copy(s,9,32) <> PlayerHash)) then
       
   695         CurrentHedgehog^.Hat:= 'NoHat'
       
   696     else
       
   697         CurrentHedgehog^.Hat:= s
       
   698     end;
       
   699 end;
       
   700 
       
   701 procedure chGrave(var s: shortstring);
       
   702 begin
       
   703     if CurrentTeam = nil then
       
   704         OutError(errmsgIncorrectUse + ' "/grave"', true);
       
   705     if s[1]='"' then
       
   706         Delete(s, 1, 1);
       
   707     if s[byte(s[0])]='"' then
       
   708         Delete(s, byte(s[0]), 1);
       
   709     CurrentTeam^.GraveName:= s
       
   710 end;
       
   711 
       
   712 procedure chFort(var s: shortstring);
       
   713 begin
       
   714     if CurrentTeam = nil then
       
   715         OutError(errmsgIncorrectUse + ' "/fort"', true);
       
   716     if s[1]='"' then
       
   717         Delete(s, 1, 1);
       
   718     if s[byte(s[0])]='"' then
       
   719         Delete(s, byte(s[0]), 1);
       
   720     CurrentTeam^.FortName:= s
       
   721 end;
       
   722 
       
   723 procedure chFlag(var s: shortstring);
       
   724 begin
       
   725     if CurrentTeam = nil then
       
   726         OutError(errmsgIncorrectUse + ' "/flag"', true);
       
   727     if s[1]='"' then
       
   728         Delete(s, 1, 1);
       
   729     if s[byte(s[0])]='"' then
       
   730         Delete(s, byte(s[0]), 1);
       
   731     CurrentTeam^.flag:= s
       
   732 end;
       
   733 
       
   734 procedure chOwner(var s: shortstring);
       
   735 begin
       
   736     if CurrentTeam = nil then
       
   737         OutError(errmsgIncorrectUse + ' "/owner"', true);
       
   738 
       
   739     CurrentTeam^.Owner:= s
       
   740 end;
       
   741 
   691 procedure initModule;
   742 procedure initModule;
   692 begin
   743 begin
   693 RegisterVariable('addhh', @chAddHH, false);
   744 RegisterVariable('addhh', @chAddHH, false);
   694 RegisterVariable('addteam', @chAddTeam, false);
   745 RegisterVariable('addteam', @chAddTeam, false);
   695 RegisterVariable('hhcoords', @chSetHHCoords, false);
   746 RegisterVariable('hhcoords', @chSetHHCoords, false);
   696 RegisterVariable('bind', @chBind, true );
   747 RegisterVariable('bind', @chBind, true );
   697 RegisterVariable('teamgone', @chTeamGone, true );
   748 RegisterVariable('teamgone', @chTeamGone, true );
   698 RegisterVariable('finish', @chFinish, true ); // all teams gone
   749 RegisterVariable('finish', @chFinish, true ); // all teams gone
       
   750 RegisterVariable('fort'    , @chFort         , false);
       
   751 RegisterVariable('grave'   , @chGrave        , false);
       
   752 RegisterVariable('hat'     , @chSetHat       , false);
       
   753 RegisterVariable('flag'    , @chFlag         , false);
       
   754 RegisterVariable('owner'   , @chOwner        , false);
   699 
   755 
   700 CurrentTeam:= nil;
   756 CurrentTeam:= nil;
   701 PreviousTeam:= nil;
   757 PreviousTeam:= nil;
   702 CurrentHedgehog:= nil;
   758 CurrentHedgehog:= nil;
   703 TeamsCount:= 0;
   759 TeamsCount:= 0;
   720         for h:= 0 to cMaxHHIndex do
   776         for h:= 0 to cMaxHHIndex do
   721             with TeamsArray[i]^.Hedgehogs[h] do
   777             with TeamsArray[i]^.Hedgehogs[h] do
   722                 begin
   778                 begin
   723                 if GearHidden <> nil then
   779                 if GearHidden <> nil then
   724                     Dispose(GearHidden);
   780                     Dispose(GearHidden);
   725                     
   781 
   726                 FreeTexture(NameTagTex);
   782                 FreeTexture(NameTagTex);
   727                 FreeTexture(HealthTagTex);
   783                 FreeTexture(HealthTagTex);
   728                 FreeTexture(HatTex);
   784                 FreeTexture(HatTex);
   729                 end;
   785                 end;
   730                 
   786 
   731         with TeamsArray[i]^ do
   787         with TeamsArray[i]^ do
   732             begin
   788             begin
   733             FreeTexture(NameTagTex);
   789             FreeTexture(NameTagTex);
   734             FreeTexture(CrosshairTex);
       
   735             FreeTexture(GraveTex);
   790             FreeTexture(GraveTex);
   736             FreeTexture(HealthTex);
       
   737             FreeTexture(AIKillsTex);
   791             FreeTexture(AIKillsTex);
   738             FreeTexture(FlagTex);
   792             FreeTexture(FlagTex);
   739             end;
   793             end;
   740         
   794 
   741         Dispose(TeamsArray[i]);
   795         Dispose(TeamsArray[i]);
   742     end;
   796     end;
   743 for i:= 0 to Pred(ClansCount) do
   797     for i:= 0 to Pred(ClansCount) do
   744     Dispose(ClansArray[i]);
   798         begin
       
   799         FreeTexture(ClansArray[i]^.HealthTex);
       
   800         Dispose(ClansArray[i]);
       
   801         end
   745     end;
   802     end;
   746 TeamsCount:= 0;
   803 TeamsCount:= 0;
   747 ClansCount:= 0;
   804 ClansCount:= 0;
   748 end;
   805 end;
   749 
   806