hedgewars/uGears.pas
changeset 4837 2ea0a152c319
parent 4835 a6924450e694
child 4867 e604ee83e34f
equal deleted inserted replaced
4836:680103541f15 4837:2ea0a152c319
    27 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    27 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    28 function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content: Longword ): PGear;
    28 function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content: Longword ): PGear;
    29 procedure ResurrectHedgehog(gear: PGear);
    29 procedure ResurrectHedgehog(gear: PGear);
    30 procedure ProcessGears;
    30 procedure ProcessGears;
    31 procedure EndTurnCleanup;
    31 procedure EndTurnCleanup;
    32 procedure ApplyDamage(Gear, Attacker: PGear; Damage: Longword; Source: TDamageSource);
    32 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
    33 procedure SetAllToActive;
    33 procedure SetAllToActive;
    34 procedure SetAllHHToActive;
    34 procedure SetAllHHToActive;
    35 procedure DrawGears;
    35 procedure DrawGears;
    36 procedure FreeGearsList;
    36 procedure FreeGearsList;
    37 procedure AddMiscGears;
    37 procedure AddMiscGears;
    48 uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics,
    48 uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics,
    49      uAIMisc, uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables,
    49      uAIMisc, uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables,
    50      uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture;
    50      uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture;
    51 
    51 
    52 
    52 
    53 procedure doMakeExplosion(X, Y, Radius: LongInt; GearCaused: PGear; Mask: Longword; const Tint: LongWord = $FFFFFFFF); forward;
    53 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); forward;
    54 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
    54 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
    55 //procedure AmmoFlameWork(Ammo: PGear); forward;
    55 //procedure AmmoFlameWork(Ammo: PGear); forward;
    56 function  GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): TPGearArray; forward;
    56 function  GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): TPGearArray; forward;
    57 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
    57 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
    58 procedure SpawnBoxOfSmth; forward;
    58 procedure SpawnBoxOfSmth; forward;
   202 gear^.uid:= Counter;
   202 gear^.uid:= Counter;
   203 gear^.SoundChannel:= -1;
   203 gear^.SoundChannel:= -1;
   204 gear^.ImpactSound:= sndNone;
   204 gear^.ImpactSound:= sndNone;
   205 gear^.nImpactSounds:= 0;
   205 gear^.nImpactSounds:= 0;
   206 
   206 
   207 if CurrentTeam <> nil then
   207 if CurrentHedgehog <> nil then
   208     begin
   208     begin
   209     gear^.Hedgehog:= CurrentHedgehog;
   209     gear^.Hedgehog:= CurrentHedgehog;
   210     gear^.IntersectGear:= CurrentHedgehog^.Gear
   210     gear^.IntersectGear:= CurrentHedgehog^.Gear
   211     end;
   211     end;
   212 
   212 
   557             t:= max(Gear^.Damage, Gear^.Health);
   557             t:= max(Gear^.Damage, Gear^.Health);
   558             Gear^.Damage:= t;
   558             Gear^.Damage:= t;
   559             if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cWaterOpacity < $FF))) and (hwRound(Gear^.Y) < cWaterLine + 256) then
   559             if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cWaterOpacity < $FF))) and (hwRound(Gear^.Y) < cWaterLine + 256) then
   560                 spawnHealthTagForHH(Gear, t);
   560                 spawnHealthTagForHH(Gear, t);
   561 
   561 
   562             // should be CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
   562             // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
   563             uStats.HedgehogDamaged(Gear, CurrentHedgehog^.Gear)
   563             // same stand for CheckHHDamage
       
   564             uStats.HedgehogDamaged(Gear, CurrentHedgehog)
   564             end;
   565             end;
   565 
   566 
   566         team:= Gear^.Hedgehog^.Team;
   567         team:= Gear^.Hedgehog^.Team;
   567         if CurrentHedgehog^.Gear = Gear then
   568         if CurrentHedgehog^.Gear = Gear then
   568             FreeActionsList; // to avoid ThinkThread on drawned gear
   569             FreeActionsList; // to avoid ThinkThread on drawned gear
   986     if (GameFlags and gfResetHealth) <> 0 then
   987     if (GameFlags and gfResetHealth) <> 0 then
   987         for i:= 0 to Pred(TeamsCount) do
   988         for i:= 0 to Pred(TeamsCount) do
   988             RecountTeamHealth(TeamsArray[i])
   989             RecountTeamHealth(TeamsArray[i])
   989 end;
   990 end;
   990 
   991 
   991 procedure ApplyDamage(Gear, Attacker: PGear; Damage: Longword; Source: TDamageSource);
   992 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
   992 var s: shortstring;
   993 var s: shortstring;
   993     vampDmg, tmpDmg, i: Longword;
   994     vampDmg, tmpDmg, i: Longword;
   994     vg: PVisualGear;
   995     vg: PVisualGear;
   995 begin
   996 begin
   996     if (Gear^.Kind = gtHedgehog) and (Damage>=1) then
   997     if (Gear^.Kind = gtHedgehog) and (Damage>=1) then
   997     begin
   998     begin
   998     uStats.HedgehogDamaged(Gear, Attacker);
   999     uStats.HedgehogDamaged(Gear, AttackerHog);
   999     HHHurt(Gear^.Hedgehog, Source);
  1000     HHHurt(Gear^.Hedgehog, Source);
  1000     AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
  1001     AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
  1001     tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
  1002     tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
  1002     if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
  1003     if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
  1003         begin
  1004         begin
  1030            inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
  1031            inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
  1031            spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
  1032            spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
  1032            end;
  1033            end;
  1033         end;
  1034         end;
  1034     end else // not gtHedgehog
  1035     end else // not gtHedgehog
  1035         Gear^.Hedgehog:= Attacker^.Hedgehog;
  1036         begin
       
  1037         AddFileLog('Assigning hedgehog ' + inttostr(LongInt(AttackerHog)) + ' to gear ' + inttostr(Gear^.uid));
       
  1038         Gear^.Hedgehog:= AttackerHog;
       
  1039         end;
  1036     inc(Gear^.Damage, Damage);
  1040     inc(Gear^.Damage, Damage);
  1037     ScriptCall('onGearDamage', Gear^.UID, Damage);
  1041     ScriptCall('onGearDamage', Gear^.UID, Damage);
  1038 end;
  1042 end;
  1039 
  1043 
  1040 procedure SetAllToActive;
  1044 procedure SetAllToActive;
  1142         AddGear(GetRandom(LAND_WIDTH+1024)-512, LAND_HEIGHT - GetRandom(LAND_HEIGHT div 2), gtFlake, 0, _0, _0, 0);
  1146         AddGear(GetRandom(LAND_WIDTH+1024)-512, LAND_HEIGHT - GetRandom(LAND_HEIGHT div 2), gtFlake, 0, _0, _0, 0);
  1143     disableLandBack:= true
  1147     disableLandBack:= true
  1144     end
  1148     end
  1145 end;
  1149 end;
  1146 
  1150 
  1147 procedure doMakeExplosion(X, Y, Radius: LongInt; GearCaused: PGear; Mask: Longword; const Tint: LongWord);
  1151 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
  1148 var Gear: PGear;
  1152 var Gear: PGear;
  1149     dmg, dmgRadius, dmgBase: LongInt;
  1153     dmg, dmgRadius, dmgBase: LongInt;
  1150     fX, fY: hwFloat;
  1154     fX, fY: hwFloat;
  1151     vg: PVisualGear;
  1155     vg: PVisualGear;
  1152     i, cnt: LongInt;
  1156     i, cnt: LongInt;
  1196                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
  1200                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
  1197                             //{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
  1201                             //{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
  1198                             if (Mask and EXPLNoDamage) = 0 then
  1202                             if (Mask and EXPLNoDamage) = 0 then
  1199                                 begin
  1203                                 begin
  1200                                 if not Gear^.Invulnerable then
  1204                                 if not Gear^.Invulnerable then
  1201                                     ApplyDamage(Gear, GearCaused, dmg, dsExplosion)
  1205                                     ApplyDamage(Gear, AttackingHog, dmg, dsExplosion)
  1202                                 else
  1206                                 else
  1203                                     Gear^.State:= Gear^.State or gstWinner;
  1207                                     Gear^.State:= Gear^.State or gstWinner;
  1204                                 end;
  1208                                 end;
  1205                             if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
  1209                             if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
  1206                                 begin
  1210                                 begin
  1262             gtSMine,
  1266             gtSMine,
  1263             gtCase,
  1267             gtCase,
  1264             gtTarget,
  1268             gtTarget,
  1265             gtExplosives: begin
  1269             gtExplosives: begin
  1266                     if (not t^.Invulnerable) then
  1270                     if (not t^.Invulnerable) then
  1267                         ApplyDamage(t, Gear, dmg, dsBullet)
  1271                         ApplyDamage(t, Gear^.Hedgehog, dmg, dsBullet)
  1268                     else
  1272                     else
  1269                         Gear^.State:= Gear^.State or gstWinner;
  1273                         Gear^.State:= Gear^.State or gstWinner;
  1270 
  1274 
  1271                     DeleteCI(t);
  1275                     DeleteCI(t);
  1272                     t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX);
  1276                     t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX);
  1327             gtTarget,
  1331             gtTarget,
  1328             gtCase,
  1332             gtCase,
  1329             gtExplosives: begin
  1333             gtExplosives: begin
  1330                     if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end;
  1334                     if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end;
  1331                     if (not Gear^.Invulnerable) then
  1335                     if (not Gear^.Invulnerable) then
  1332                         ApplyDamage(Gear, Ammo, tmpDmg, dsShove)
  1336                         ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
  1333                     else
  1337                     else
  1334                         Gear^.State:= Gear^.State or gstWinner;
  1338                         Gear^.State:= Gear^.State or gstWinner;
  1335                     if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then ApplyDamage(Gear, Ammo, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
  1339                     if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
  1336 
  1340 
  1337                     DeleteCI(Gear);
  1341                     DeleteCI(Gear);
  1338                     if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
  1342                     if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
  1339                         begin
  1343                         begin
  1340                         Gear^.dX:= Ammo^.dX * Power * _0_005;
  1344                         Gear^.dX:= Ammo^.dX * Power * _0_005;