hedgewars/uGearsList.pas
changeset 10646 0be6442946b1
parent 10645 b8c73bacb31e
child 10663 9bbb29d2bd68
equal deleted inserted replaced
10645:b8c73bacb31e 10646:0be6442946b1
    21 
    21 
    22 interface
    22 interface
    23 uses uFloat, uTypes, SDLh;
    23 uses uFloat, uTypes, SDLh;
    24 
    24 
    25 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    25 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    26 procedure DeleteGear(Gear: PGear); inline;
    26 procedure DeleteGear(Gear: PGear);
    27 procedure DeleteGearStage(Gear: PGear; cleanup: boolean);
       
    28 procedure InsertGearToList(Gear: PGear);
    27 procedure InsertGearToList(Gear: PGear);
    29 procedure RemoveGearFromList(Gear: PGear);
    28 procedure RemoveGearFromList(Gear: PGear);
    30 
    29 
    31 var curHandledGear: PGear;
    30 var curHandledGear: PGear;
    32 
    31 
   630 AddGear:= gear;
   629 AddGear:= gear;
   631 
   630 
   632 ScriptCall('onGearAdd', gear^.uid);
   631 ScriptCall('onGearAdd', gear^.uid);
   633 end;
   632 end;
   634 
   633 
   635 procedure DeleteGear(Gear: PGear); inline;
   634 procedure DeleteGear(Gear: PGear);
   636 begin
       
   637 DeleteGearStage(Gear, false)
       
   638 end;
       
   639 
       
   640 procedure DeleteGearStage(Gear: PGear; cleanup: boolean);
       
   641 var team: PTeam;
   635 var team: PTeam;
   642     t,i: Longword;
   636     t,i: Longword;
   643     k: boolean;
   637     k: boolean;
   644 begin
   638 begin
   645 
   639 
   666         CurAmmoGear^.Message:= gmDestroy;
   660         CurAmmoGear^.Message:= gmDestroy;
   667         exit
   661         exit
   668         end
   662         end
   669     else*)
   663     else*)
   670         begin
   664         begin
       
   665         if ((CurrentHedgehog = nil) or (Gear <> CurrentHedgehog^.Gear)) or (CurAmmoGear = nil) or (CurAmmoGear^.Kind <> gtKamikaze) then
       
   666             Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
       
   667         if not CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
       
   668             begin
       
   669             t:= max(Gear^.Damage, Gear^.Health);
       
   670             Gear^.Damage:= t;
       
   671             if (((not SuddenDeathDmg) and (WaterOpacity < $FF)) or (SuddenDeathDmg and (SDWaterOpacity < $FF))) then
       
   672                 spawnHealthTagForHH(Gear, t);
       
   673             end;
       
   674 
   671         team:= Gear^.Hedgehog^.Team;
   675         team:= Gear^.Hedgehog^.Team;
   672         if not cleanup then
       
   673             begin
       
   674             if ((CurrentHedgehog = nil) or (Gear <> CurrentHedgehog^.Gear)) or (CurAmmoGear = nil) or (CurAmmoGear^.Kind <> gtKamikaze) then
       
   675                 Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
       
   676             if not CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y)) then
       
   677                 begin
       
   678                 t:= max(Gear^.Damage, Gear^.Health);
       
   679                 Gear^.Damage:= t;
       
   680                 if (((not SuddenDeathDmg) and (WaterOpacity < $FF)) or (SuddenDeathDmg and (SDWaterOpacity < $FF))) then
       
   681                     spawnHealthTagForHH(Gear, t);
       
   682                 end;
       
   683 
       
   684             // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
       
   685             // same stand for CheckHHDamage
       
   686             if (Gear^.LastDamage <> nil) and (CurrentHedgehog <> nil) then
       
   687                 uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true)
       
   688             else if CurrentHedgehog <> nil then
       
   689                 uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true);
       
   690 
       
   691             inc(KilledHHs);
       
   692             RecountTeamHealth(team);
       
   693             if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Effects[heResurrectable] <> 0)  and
       
   694             //(Gear^.Hedgehog^.Effects[heResurrectable] = 0) then
       
   695             (Gear^.Hedgehog^.Team^.Clan <> CurrentHedgehog^.Team^.Clan) then
       
   696                 with CurrentHedgehog^ do
       
   697                     begin
       
   698                     inc(Team^.stats.AIKills);
       
   699                     FreeAndNilTexture(Team^.AIKillsTex);
       
   700                     Team^.AIKillsTex := RenderStringTex(ansistring(inttostr(Team^.stats.AIKills)), Team^.Clan^.Color, fnt16);
       
   701                     end
       
   702             end;
       
   703 
       
   704         if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear = Gear) then
   676         if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear = Gear) then
   705             begin
   677             begin
   706             AttackBar:= 0;
   678             AttackBar:= 0;
   707             FreeActionsList; // to avoid ThinkThread on drawned gear
   679             FreeActionsList; // to avoid ThinkThread on drawned gear
   708             if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0)
   680             if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0)
   709             and (CurrentHedgehog^.MultiShootAttacks > 0) then
   681             and (CurrentHedgehog^.MultiShootAttacks > 0) then
   710                 OnUsedAmmo(CurrentHedgehog^);
   682                 OnUsedAmmo(CurrentHedgehog^);
   711             end;
   683             end;
   712 
   684 
   713         Gear^.Hedgehog^.Gear:= nil;
   685         Gear^.Hedgehog^.Gear:= nil;
       
   686 
   714         if Gear^.Hedgehog^.King then
   687         if Gear^.Hedgehog^.King then
   715             begin
   688             begin
   716             // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
   689             // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
   717             k:= false;
   690             k:= false;
   718             for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
   691             for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
   723                     begin
   696                     begin
   724                     team^.Clan^.Teams[i]^.hasGone:= true;
   697                     team^.Clan^.Teams[i]^.hasGone:= true;
   725                     TeamGoneEffect(team^.Clan^.Teams[i]^)
   698                     TeamGoneEffect(team^.Clan^.Teams[i]^)
   726                     end
   699                     end
   727             end;
   700             end;
       
   701 
       
   702         // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
       
   703         // same stand for CheckHHDamage
       
   704         if (Gear^.LastDamage <> nil) and (CurrentHedgehog <> nil) then
       
   705             uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true)
       
   706         else if CurrentHedgehog <> nil then
       
   707             uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true);
       
   708 
       
   709         inc(KilledHHs);
       
   710         RecountTeamHealth(team);
       
   711         if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Effects[heResurrectable] <> 0)  and
       
   712         //(Gear^.Hedgehog^.Effects[heResurrectable] = 0) then
       
   713         (Gear^.Hedgehog^.Team^.Clan <> CurrentHedgehog^.Team^.Clan) then
       
   714             with CurrentHedgehog^ do
       
   715                 begin
       
   716                 inc(Team^.stats.AIKills);
       
   717                 FreeAndNilTexture(Team^.AIKillsTex);
       
   718                 Team^.AIKillsTex := RenderStringTex(ansistring(inttostr(Team^.stats.AIKills)), Team^.Clan^.Color, fnt16);
       
   719                 end
   728         end;
   720         end;
   729 with Gear^ do
   721 with Gear^ do
   730     begin
   722     begin
   731     AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
   723     AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
   732     AddRandomness(X.round xor X.frac xor dX.round xor dX.frac xor Y.round xor Y.frac xor dY.round xor dY.frac)
   724     AddRandomness(X.round xor X.frac xor dX.round xor dX.frac xor Y.round xor Y.frac xor dY.round xor dY.frac)