hedgewars/uTeams.pas
branchsdl2transition
changeset 9798 f2b18754742f
parent 9790 0b4b9fda5bd4
child 9950 2759212a27de
child 9998 736015b847e3
equal deleted inserted replaced
9711:7d0329f37181 9798:f2b18754742f
    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;
   682     if oldCI then AddCI(oldHH^.Gear);
   677     if oldCI then AddCI(oldHH^.Gear);
   683     if newCI then AddCI(newHog^.Gear)
   678     if newCI then AddCI(newHog^.Gear)
   684 end;
   679 end;
   685 
   680 
   686 
   681 
       
   682 procedure chSetHat(var s: shortstring);
       
   683 begin
       
   684 if (not isDeveloperMode) or (CurrentTeam = nil) then exit;
       
   685 with CurrentTeam^ do
       
   686     begin
       
   687     if not CurrentHedgehog^.King then
       
   688     if (s = '')
       
   689     or (((GameFlags and gfKing) <> 0) and (s = 'crown'))
       
   690     or ((Length(s) > 39) and (Copy(s,1,8) = 'Reserved') and (Copy(s,9,32) <> PlayerHash)) then
       
   691         CurrentHedgehog^.Hat:= 'NoHat'
       
   692     else
       
   693         CurrentHedgehog^.Hat:= s
       
   694     end;
       
   695 end;
       
   696 
       
   697 procedure chGrave(var s: shortstring);
       
   698 begin
       
   699     if CurrentTeam = nil then
       
   700         OutError(errmsgIncorrectUse + ' "/grave"', true);
       
   701     if s[1]='"' then
       
   702         Delete(s, 1, 1);
       
   703     if s[byte(s[0])]='"' then
       
   704         Delete(s, byte(s[0]), 1);
       
   705     CurrentTeam^.GraveName:= s
       
   706 end;
       
   707 
       
   708 procedure chFort(var s: shortstring);
       
   709 begin
       
   710     if CurrentTeam = nil then
       
   711         OutError(errmsgIncorrectUse + ' "/fort"', true);
       
   712     if s[1]='"' then
       
   713         Delete(s, 1, 1);
       
   714     if s[byte(s[0])]='"' then
       
   715         Delete(s, byte(s[0]), 1);
       
   716     CurrentTeam^.FortName:= s
       
   717 end;
       
   718 
       
   719 procedure chFlag(var s: shortstring);
       
   720 begin
       
   721     if CurrentTeam = nil then
       
   722         OutError(errmsgIncorrectUse + ' "/flag"', true);
       
   723     if s[1]='"' then
       
   724         Delete(s, 1, 1);
       
   725     if s[byte(s[0])]='"' then
       
   726         Delete(s, byte(s[0]), 1);
       
   727     CurrentTeam^.flag:= s
       
   728 end;
       
   729 
       
   730 procedure chOwner(var s: shortstring);
       
   731 begin
       
   732     if CurrentTeam = nil then
       
   733         OutError(errmsgIncorrectUse + ' "/owner"', true);
       
   734 
       
   735     CurrentTeam^.Owner:= s
       
   736 end;
       
   737 
   687 procedure initModule;
   738 procedure initModule;
   688 begin
   739 begin
   689 RegisterVariable('addhh', @chAddHH, false);
   740 RegisterVariable('addhh', @chAddHH, false);
   690 RegisterVariable('addteam', @chAddTeam, false);
   741 RegisterVariable('addteam', @chAddTeam, false);
   691 RegisterVariable('hhcoords', @chSetHHCoords, false);
   742 RegisterVariable('hhcoords', @chSetHHCoords, false);
   692 RegisterVariable('bind', @chBind, true );
   743 RegisterVariable('bind', @chBind, true );
   693 RegisterVariable('teamgone', @chTeamGone, true );
   744 RegisterVariable('teamgone', @chTeamGone, true );
   694 RegisterVariable('finish', @chFinish, true ); // all teams gone
   745 RegisterVariable('finish', @chFinish, true ); // all teams gone
       
   746 RegisterVariable('fort'    , @chFort         , false);
       
   747 RegisterVariable('grave'   , @chGrave        , false);
       
   748 RegisterVariable('hat'     , @chSetHat       , false);
       
   749 RegisterVariable('flag'    , @chFlag         , false);
       
   750 RegisterVariable('owner'   , @chOwner        , false);
   695 
   751 
   696 CurrentTeam:= nil;
   752 CurrentTeam:= nil;
   697 PreviousTeam:= nil;
   753 PreviousTeam:= nil;
   698 CurrentHedgehog:= nil;
   754 CurrentHedgehog:= nil;
   699 TeamsCount:= 0;
   755 TeamsCount:= 0;