hedgewars/uGears.pas
changeset 4824 efbc8f80acac
parent 4813 53c2f0f92281
child 4826 d6a0a38407c8
equal deleted inserted replaced
4823:8789a8f6c016 4824:efbc8f80acac
    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: PGear; Damage: Longword; Source: TDamageSource);
    32 procedure ApplyDamage(Gear, Attacker: PGear; 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; Mask: LongWord); forward;
    53 procedure doMakeExplosion(X, Y, Radius: LongInt; GearCaused: PGear; Mask: Longword; const Tint: LongWord = $FFFFFFFF); forward;
    54 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask, Tint: LongWord); forward;
       
    55 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
    54 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
    56 //procedure AmmoFlameWork(Ammo: PGear); forward;
    55 //procedure AmmoFlameWork(Ammo: PGear); forward;
    57 function  GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): TPGearArray; forward;
    56 function  GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): TPGearArray; forward;
    58 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
    57 function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward;
    59 procedure SpawnBoxOfSmth; forward;
    58 procedure SpawnBoxOfSmth; forward;
   557             begin
   556             begin
   558             t:= max(Gear^.Damage, Gear^.Health);
   557             t:= max(Gear^.Damage, Gear^.Health);
   559             Gear^.Damage:= t;
   558             Gear^.Damage:= t;
   560             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
   561                 spawnHealthTagForHH(Gear, t);
   560                 spawnHealthTagForHH(Gear, t);
   562             uStats.HedgehogDamaged(Gear)
   561             uStats.HedgehogDamaged(Gear, CurrentHedgehog^.Gear)
   563             end;
   562             end;
   564 
   563 
   565         team:= Gear^.Hedgehog^.Team;
   564         team:= Gear^.Hedgehog^.Team;
   566         if CurrentHedgehog^.Gear = Gear then
   565         if CurrentHedgehog^.Gear = Gear then
   567             FreeActionsList; // to avoid ThinkThread on drawned gear
   566             FreeActionsList; // to avoid ThinkThread on drawned gear
   614         if (not isInMultiShoot) then inc(Gear^.Damage, Gear^.Karma);
   613         if (not isInMultiShoot) then inc(Gear^.Damage, Gear^.Karma);
   615         if (Gear^.Damage <> 0) and
   614         if (Gear^.Damage <> 0) and
   616         (not Gear^.Invulnerable) then
   615         (not Gear^.Invulnerable) then
   617             begin
   616             begin
   618             CheckNoDamage:= false;
   617             CheckNoDamage:= false;
   619             uStats.HedgehogDamaged(Gear);
   618 
   620             dmg:= Gear^.Damage;
   619             dmg:= Gear^.Damage;
   621             if Gear^.Health < dmg then
   620             if Gear^.Health < dmg then
   622                 begin
   621                 begin
   623                 Gear^.Active:= true;
   622                 Gear^.Active:= true;
   624                 Gear^.Health:= 0
   623                 Gear^.Health:= 0
   984     if (GameFlags and gfResetHealth) <> 0 then
   983     if (GameFlags and gfResetHealth) <> 0 then
   985         for i:= 0 to Pred(TeamsCount) do
   984         for i:= 0 to Pred(TeamsCount) do
   986             RecountTeamHealth(TeamsArray[i])
   985             RecountTeamHealth(TeamsArray[i])
   987 end;
   986 end;
   988 
   987 
   989 procedure ApplyDamage(Gear: PGear; Damage: Longword; Source: TDamageSource);
   988 procedure ApplyDamage(Gear, Attacker: PGear; Damage: Longword; Source: TDamageSource);
   990 var s: shortstring;
   989 var s: shortstring;
   991     vampDmg, tmpDmg, i: Longword;
   990     vampDmg, tmpDmg, i: Longword;
   992     vg: PVisualGear;
   991     vg: PVisualGear;
   993 begin
   992 begin
   994     if (Gear^.Kind = gtHedgehog) and (Damage>=1) then
   993     if (Gear^.Kind = gtHedgehog) and (Damage>=1) then
   995     begin
   994     begin
       
   995     uStats.HedgehogDamaged(Gear, Attacker);
   996     HHHurt(Gear^.Hedgehog, Source);
   996     HHHurt(Gear^.Hedgehog, Source);
   997     AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
   997     AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
   998     tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
   998     tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
   999     if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
   999     if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
  1000         begin
  1000         begin
  1131         AddGear(GetRandom(LAND_WIDTH+1024)-512, LAND_HEIGHT - GetRandom(LAND_HEIGHT div 2), gtFlake, 0, _0, _0, 0);
  1131         AddGear(GetRandom(LAND_WIDTH+1024)-512, LAND_HEIGHT - GetRandom(LAND_HEIGHT div 2), gtFlake, 0, _0, _0, 0);
  1132     disableLandBack:= true
  1132     disableLandBack:= true
  1133     end
  1133     end
  1134 end;
  1134 end;
  1135 
  1135 
  1136 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord);
  1136 procedure doMakeExplosion(X, Y, Radius: LongInt; GearCaused: PGear; Mask: Longword; const Tint: LongWord);
  1137 begin
       
  1138 doMakeExplosion(X, Y, Radius, Mask, $FFFFFFFF);
       
  1139 end;
       
  1140 
       
  1141 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask, Tint: LongWord);
       
  1142 var Gear: PGear;
  1137 var Gear: PGear;
  1143     dmg, dmgRadius, dmgBase: LongInt;
  1138     dmg, dmgRadius, dmgBase: LongInt;
  1144     fX, fY: hwFloat;
  1139     fX, fY: hwFloat;
  1145     vg: PVisualGear;
  1140     vg: PVisualGear;
  1146     i, cnt: LongInt;
  1141     i, cnt: LongInt;
  1190                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
  1185                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
  1191                             //{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
  1186                             //{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
  1192                             if (Mask and EXPLNoDamage) = 0 then
  1187                             if (Mask and EXPLNoDamage) = 0 then
  1193                                 begin
  1188                                 begin
  1194                                 if not Gear^.Invulnerable then
  1189                                 if not Gear^.Invulnerable then
  1195                                     ApplyDamage(Gear, dmg, dsExplosion)
  1190                                     ApplyDamage(Gear, GearCaused, dmg, dsExplosion)
  1196                                 else
  1191                                 else
  1197                                     Gear^.State:= Gear^.State or gstWinner;
  1192                                     Gear^.State:= Gear^.State or gstWinner;
  1198                                 end;
  1193                                 end;
  1199                             if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
  1194                             if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
  1200                                 begin
  1195                                 begin
  1256             gtSMine,
  1251             gtSMine,
  1257             gtCase,
  1252             gtCase,
  1258             gtTarget,
  1253             gtTarget,
  1259             gtExplosives: begin
  1254             gtExplosives: begin
  1260                     if (not t^.Invulnerable) then
  1255                     if (not t^.Invulnerable) then
  1261                         ApplyDamage(t, dmg, dsBullet)
  1256                         ApplyDamage(t, Gear, dmg, dsBullet)
  1262                     else
  1257                     else
  1263                         Gear^.State:= Gear^.State or gstWinner;
  1258                         Gear^.State:= Gear^.State or gstWinner;
  1264 
  1259 
  1265                     DeleteCI(t);
  1260                     DeleteCI(t);
  1266                     t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX);
  1261                     t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX);
  1303     dec(i);
  1298     dec(i);
  1304     Gear:= t^.ar[i];
  1299     Gear:= t^.ar[i];
  1305     tmpDmg:= ModifyDamage(Damage, Gear);
  1300     tmpDmg:= ModifyDamage(Damage, Gear);
  1306     if (Gear^.State and gstNoDamage) = 0 then
  1301     if (Gear^.State and gstNoDamage) = 0 then
  1307         begin
  1302         begin
  1308         
  1303 
  1309         if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then 
  1304         if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then 
  1310             begin
  1305             begin
  1311             VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit);
  1306             VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit);
  1312             if VGear <> nil then VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY);
  1307             if VGear <> nil then VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY);
  1313             end;
  1308             end;
  1314         
  1309 
  1315         if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then Gear^.FlightTime:= 1;
  1310         if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then Gear^.FlightTime:= 1;
  1316 
  1311 
  1317         case Gear^.Kind of
  1312         case Gear^.Kind of
  1318             gtHedgehog,
  1313             gtHedgehog,
  1319             gtMine,
  1314             gtMine,
  1321             gtTarget,
  1316             gtTarget,
  1322             gtCase,
  1317             gtCase,
  1323             gtExplosives: begin
  1318             gtExplosives: begin
  1324                     if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end;
  1319                     if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end;
  1325                     if (not Gear^.Invulnerable) then
  1320                     if (not Gear^.Invulnerable) then
  1326                         ApplyDamage(Gear, tmpDmg, dsShove)
  1321                         ApplyDamage(Gear, Ammo, tmpDmg, dsShove)
  1327                     else
  1322                     else
  1328                         Gear^.State:= Gear^.State or gstWinner;
  1323                         Gear^.State:= Gear^.State or gstWinner;
  1329                     if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then ApplyDamage(Gear, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
  1324                     if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then ApplyDamage(Gear, Ammo, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
  1330 
  1325 
  1331                     DeleteCI(Gear);
  1326                     DeleteCI(Gear);
  1332                     if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
  1327                     if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
  1333                         begin
  1328                         begin
  1334                         Gear^.dX:= Ammo^.dX * Power * _0_005;
  1329                         Gear^.dX:= Ammo^.dX * Power * _0_005;
  1515 var tempTeam : PTeam;
  1510 var tempTeam : PTeam;
  1516 begin
  1511 begin
  1517     gear^.dX := _0;
  1512     gear^.dX := _0;
  1518     gear^.dY := _0;
  1513     gear^.dY := _0;
  1519     gear^.State := gstWait;
  1514     gear^.State := gstWait;
  1520     uStats.HedgehogDamaged(gear);
       
  1521     gear^.Damage := 0;
  1515     gear^.Damage := 0;
  1522     gear^.Health := gear^.Hedgehog^.InitialHealth;
  1516     gear^.Health := gear^.Hedgehog^.InitialHealth;
  1523     gear^.Hedgehog^.Effects[hePoisoned] := false;
  1517     gear^.Hedgehog^.Effects[hePoisoned] := false;
  1524     if not CurrentHedgehog^.Effects[heResurrectable] then
  1518     if not CurrentHedgehog^.Effects[heResurrectable] then
  1525         with CurrentHedgehog^ do 
  1519         with CurrentHedgehog^ do