hedgewars/uTeams.pas
branchwebgl
changeset 9521 8054d9d775fd
parent 9236 ddd675825672
parent 9468 3d07fd84c39d
child 9950 2759212a27de
equal deleted inserted replaced
9282:92af50454cf2 9521:8054d9d775fd
     1 (*
     1  (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uTeams;
    21 unit uTeams;
    22 interface
    22 interface
    23 uses uConsts, uInputHandler, uRandom, uFloat, uStats, uVisualGears,
    23 uses uConsts, uInputHandler, uRandom, uFloat, uStats, 
    24      uCollisions, GLunit, uSound, uStore, uTypes, uScript
    24      uCollisions, uSound, uStore, uTypes, uScript
    25      {$IFDEF USE_TOUCH_INTERFACE}, uWorld{$ENDIF};
    25      {$IFDEF USE_TOUCH_INTERFACE}, uWorld{$ENDIF};
    26 
    26 
    27 
    27 
    28 procedure initModule;
    28 procedure initModule;
    29 procedure freeModule;
    29 procedure freeModule;
    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 implementation
    44 implementation
    45 uses uLocale, uAmmos, uChat, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug,
    45 uses uLocale, uAmmos, uChat, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug,
    46     uGearsUtils, uGearsList
    46     uGearsUtils, uGearsList, uVisualGearsList, uTextures
    47     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
    47     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
    48 
    48 
    49 var MaxTeamHealth: LongInt;
    49 var MaxTeamHealth: LongInt;
    50     GameOver: boolean;
    50     GameOver: boolean;
    51     NextClan: boolean;
    51     NextClan: boolean;
   124         if Gear <> nil then
   124         if Gear <> nil then
   125            begin
   125            begin
   126            DeleteCI(Gear);
   126            DeleteCI(Gear);
   127            FindPlace(Gear, false, 0, LAND_WIDTH);
   127            FindPlace(Gear, false, 0, LAND_WIDTH);
   128            if Gear <> nil then
   128            if Gear <> nil then
   129                AddGearCI(Gear)
   129                AddCI(Gear)
   130            end
   130            end
   131         end;
   131         end;
   132 
   132 
   133 PreviousTeam:= CurrentTeam;
   133 PreviousTeam:= CurrentTeam;
   134 
   134 
   361 
   361 
   362 TeamsArray[TeamsCount]:= team;
   362 TeamsArray[TeamsCount]:= team;
   363 inc(TeamsCount);
   363 inc(TeamsCount);
   364 
   364 
   365 for t:= 0 to cKbdMaxIndex do
   365 for t:= 0 to cKbdMaxIndex do
   366     team^.Binds[t]:= '';
   366     team^.Binds[t]:= DefaultBinds[t];
   367 
   367 
   368 c:= Pred(ClansCount);
   368 c:= Pred(ClansCount);
   369 while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c);
   369 while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c);
   370 if c < 0 then
   370 if c < 0 then
   371     begin
   371     begin
   502 begin
   502 begin
   503     HH^.Gear:=HH^.GearHidden;
   503     HH^.Gear:=HH^.GearHidden;
   504     HH^.GearHidden:= nil;
   504     HH^.GearHidden:= nil;
   505     InsertGearToList(HH^.Gear);
   505     InsertGearToList(HH^.Gear);
   506     HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked;
   506     HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked;
   507     AddGearCI(HH^.Gear);
   507     AddCI(HH^.Gear);
   508     HH^.Gear^.Active:= true;
   508     HH^.Gear^.Active:= true;
   509     ScriptCall('onHogRestore', HH^.Gear^.Uid)
   509     ScriptCall('onHogRestore', HH^.Gear^.Uid)
   510 end;
   510 end;
   511 
   511 
   512 procedure RestoreTeamsFromSave;
   512 procedure RestoreTeamsFromSave;
   566     CurrHedgehog:= HedgehogsNumber;
   566     CurrHedgehog:= HedgehogsNumber;
   567     inc(HedgehogsNumber)
   567     inc(HedgehogsNumber)
   568     end
   568     end
   569 end;
   569 end;
   570 
   570 
       
   571 procedure loadTeamBinds(s: shortstring);
       
   572 var i: LongInt;
       
   573 begin
       
   574     for i:= 1 to length(s) do
       
   575         if ((s[i] = '\') or
       
   576             (s[i] = '/') or
       
   577             (s[i] = ':')) then
       
   578             s[i]:= '_';
       
   579 
       
   580     s:= cPathz[ptTeams] + '/' + s + '.hwt';
       
   581 
       
   582     loadBinds('bind', s);
       
   583 end;
       
   584 
   571 procedure chAddTeam(var s: shortstring);
   585 procedure chAddTeam(var s: shortstring);
   572 var Color: Longword;
   586 var Color: Longword;
   573     ts, cs: shortstring;
   587     ts, cs: shortstring;
   574 begin
   588 begin
   575 cs:= '';
   589 cs:= '';
   584     // color is always little endian so the mask must be constant also in big endian archs
   598     // color is always little endian so the mask must be constant also in big endian archs
   585     Color:= Color or $FF000000;
   599     Color:= Color or $FF000000;
   586     AddTeam(Color);
   600     AddTeam(Color);
   587     CurrentTeam^.TeamName:= ts;
   601     CurrentTeam^.TeamName:= ts;
   588     CurrentTeam^.PlayerHash:= s;
   602     CurrentTeam^.PlayerHash:= s;
       
   603     loadTeamBinds(ts);
       
   604     
   589     if GameType in [gmtDemo, gmtSave, gmtRecord] then
   605     if GameType in [gmtDemo, gmtSave, gmtRecord] then
   590         CurrentTeam^.ExtDriven:= true;
   606         CurrentTeam^.ExtDriven:= true;
   591 
   607 
   592     CurrentTeam^.voicepack:= AskForVoicepack('Default')
   608     CurrentTeam^.voicepack:= AskForVoicepack('Default')
   593     end
   609     end
   606     t:= StrToInt(y);
   622     t:= StrToInt(y);
   607     CurrentHedgehog^.Gear^.Y:= int2hwFloat(t)
   623     CurrentHedgehog^.Gear^.Y:= int2hwFloat(t)
   608 end;
   624 end;
   609 
   625 
   610 procedure chBind(var id: shortstring);
   626 procedure chBind(var id: shortstring);
   611 var KeyName, Modifier, tmp : shortstring;
   627 var i : Integer;
   612     b              : LongInt;
   628 begin
   613     i              : Integer;
   629     if CurrentTeam = nil then
   614 begin
   630         exit;
   615 KeyName:= '';
   631 
   616 Modifier:= '';
   632     addBind(CurrentTeam^.Binds, id)
   617 
       
   618 if CurrentTeam = nil then
       
   619     exit;
       
   620 
       
   621 i := Pos('mod:', id);
       
   622 
       
   623 if(i <> 0)then
       
   624     begin
       
   625     tmp:= '';
       
   626     SplitBySpace(id, tmp);
       
   627     Modifier:= id;
       
   628     id:= tmp;
       
   629     end;
       
   630 
       
   631 SplitBySpace(id, KeyName);
       
   632 if KeyName[1]='"' then
       
   633     Delete(KeyName, 1, 1);
       
   634 if KeyName[byte(KeyName[0])]='"' then
       
   635     Delete(KeyName, byte(KeyName[0]), 1);
       
   636 b:= KeyNameToCode(id, Modifier);
       
   637 if b = 0 then
       
   638     OutError(errmsgUnknownVariable + ' "' + id + '"', false)
       
   639 else
       
   640     CurrentTeam^.Binds[b]:= KeyName;
       
   641 end;
   633 end;
   642 
   634 
   643 procedure chTeamGone(var s:shortstring);
   635 procedure chTeamGone(var s:shortstring);
   644 var t: LongInt;
   636 var t: LongInt;
   645 begin
   637 begin
   689     if newCI then DeleteCI(newHog^.Gear);
   681     if newCI then DeleteCI(newHog^.Gear);
   690     oldHH:= CurrentHedgehog;
   682     oldHH:= CurrentHedgehog;
   691     CurrentHedgehog:= newHog;
   683     CurrentHedgehog:= newHog;
   692    if (CurrentHedgehog <> nil) and (CurrentHedgehog^.CurAmmoType = amKnife) then
   684    if (CurrentHedgehog <> nil) and (CurrentHedgehog^.CurAmmoType = amKnife) then
   693        LoadHedgehogHat(CurrentHedgehog^, 'Reserved/chef');
   685        LoadHedgehogHat(CurrentHedgehog^, 'Reserved/chef');
   694     if oldCI then AddGearCI(oldHH^.Gear);
   686     if oldCI then AddCI(oldHH^.Gear);
   695     if newCI then AddGearCI(newHog^.Gear)
   687     if newCI then AddCI(newHog^.Gear)
   696 end;
   688 end;
   697 
   689 
   698 
   690 
   699 procedure initModule;
   691 procedure initModule;
   700 begin
   692 begin
   724 if TeamsCount > 0 then
   716 if TeamsCount > 0 then
   725     begin
   717     begin
   726     for i:= 0 to Pred(TeamsCount) do
   718     for i:= 0 to Pred(TeamsCount) do
   727         begin
   719         begin
   728         for h:= 0 to cMaxHHIndex do
   720         for h:= 0 to cMaxHHIndex do
   729             if TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil then
   721             with TeamsArray[i]^.Hedgehogs[h] do
   730                 Dispose(TeamsArray[i]^.Hedgehogs[h].GearHidden);
   722                 begin
       
   723                 if GearHidden <> nil then
       
   724                     Dispose(GearHidden);
       
   725                     
       
   726                 FreeTexture(NameTagTex);
       
   727                 FreeTexture(HealthTagTex);
       
   728                 FreeTexture(HatTex);
       
   729                 end;
       
   730                 
       
   731         with TeamsArray[i]^ do
       
   732             begin
       
   733             FreeTexture(NameTagTex);
       
   734             FreeTexture(CrosshairTex);
       
   735             FreeTexture(GraveTex);
       
   736             FreeTexture(HealthTex);
       
   737             FreeTexture(AIKillsTex);
       
   738             FreeTexture(FlagTex);
       
   739             end;
       
   740         
   731         Dispose(TeamsArray[i]);
   741         Dispose(TeamsArray[i]);
   732     end;
   742     end;
   733 for i:= 0 to Pred(ClansCount) do
   743 for i:= 0 to Pred(ClansCount) do
   734     Dispose(ClansArray[i]);
   744     Dispose(ClansArray[i]);
   735     end;
   745     end;