hedgewars/uGears.pas
changeset 3693 09892cdb8f95
parent 3689 e2be39ee19f0
child 3697 d5b30d6373fc
equal deleted inserted replaced
3680:aaf832c6fbd7 3693:09892cdb8f95
    81 procedure initModule;
    81 procedure initModule;
    82 procedure freeModule;
    82 procedure freeModule;
    83 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    83 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
    84 procedure ProcessGears;
    84 procedure ProcessGears;
    85 procedure EndTurnCleanup;
    85 procedure EndTurnCleanup;
    86 procedure ApplyDamage(Gear: PGear; Damage: Longword);
    86 procedure ApplyDamage(Gear: PGear; Damage: Longword; Source: TDamageSource);
    87 procedure SetAllToActive;
    87 procedure SetAllToActive;
    88 procedure SetAllHHToActive;
    88 procedure SetAllHHToActive;
    89 procedure DrawGears;
    89 procedure DrawGears;
    90 procedure FreeGearsList;
    90 procedure FreeGearsList;
    91 procedure AddMiscGears;
    91 procedure AddMiscGears;
   633 procedure HealthMachine;
   633 procedure HealthMachine;
   634 var Gear: PGear;
   634 var Gear: PGear;
   635     team: PTeam;
   635     team: PTeam;
   636        i: LongWord;
   636        i: LongWord;
   637     flag: Boolean;
   637     flag: Boolean;
   638 begin
   638      tmp: LongWord;
   639 	Gear:= GearsList;
   639 begin
   640 
   640     Gear:= GearsList;
   641 	while Gear <> nil do
   641 
   642 	begin
   642     while Gear <> nil do
   643 		if Gear^.Kind = gtHedgehog then
   643     begin
   644 			begin
   644         if Gear^.Kind = gtHedgehog then
       
   645             begin
       
   646             tmp:= 0;
   645             if PHedgehog(Gear^.Hedgehog)^.Effects[hePoisoned] then
   647             if PHedgehog(Gear^.Hedgehog)^.Effects[hePoisoned] then
   646                 begin
   648                 inc(tmp, min(ModifyDamage(5,Gear), max(0,Gear^.Health - 1 - Gear^.Damage)));
   647                 inc(Gear^.Damage, min(ModifyDamage(5,Gear), max(0,Gear^.Health - 1 - Gear^.Damage)));
   649             inc(tmp, min(cHealthDecrease, max(0,Gear^.Health - 1 - Gear^.Damage)));
   648                 if getRandom(2) = 0 then
       
   649                     PlaySound(sndPoisonCough, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack)
       
   650                 else
       
   651                     PlaySound(sndPoisonMoan, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
       
   652                 end;
       
   653             inc(Gear^.Damage, min(cHealthDecrease, max(0,Gear^.Health - 1 - Gear^.Damage)));
       
   654             if PHedgehog(Gear^.Hedgehog)^.King then
   650             if PHedgehog(Gear^.Hedgehog)^.King then
   655                 begin
   651                 begin
   656                 flag:= false;
   652                 flag:= false;
   657                 team:= PHedgehog(Gear^.Hedgehog)^.Team;
   653                 team:= PHedgehog(Gear^.Hedgehog)^.Team;
   658                 for i:= 0 to Pred(team^.HedgehogsNumber) do
   654                 for i:= 0 to Pred(team^.HedgehogsNumber) do
   659                     if (team^.Hedgehogs[i].Gear <> nil) and 
   655                     if (team^.Hedgehogs[i].Gear <> nil) and 
   660                         (not team^.Hedgehogs[i].King) and 
   656                         (not team^.Hedgehogs[i].King) and 
   661                         (team^.Hedgehogs[i].Gear^.Health > team^.Hedgehogs[i].Gear^.Damage) 
   657                         (team^.Hedgehogs[i].Gear^.Health > team^.Hedgehogs[i].Gear^.Damage) 
   662                     then flag:= true;
   658                     then flag:= true;
   663                 if not flag then inc(Gear^.Damage, min(5, max(0,Gear^.Health - 1 - Gear^.Damage)))
   659                 if not flag then inc(tmp, min(5, max(0,Gear^.Health - 1 - Gear^.Damage)))
   664                 end;
   660                 end;
   665 			end;
   661             if tmp > 0 then ApplyDamage(Gear, tmp, dsPoison);
   666 
   662             end;
   667 		Gear:= Gear^.NextGear
   663 
   668 	end;
   664         Gear:= Gear^.NextGear
       
   665     end;
   669 end;
   666 end;
   670 
   667 
   671 procedure ProcessGears;
   668 procedure ProcessGears;
   672 const delay: LongWord = 0;
   669 const delay: LongWord = 0;
   673     step: (stDelay, stChDmg, stSweep, stTurnReact,
   670     step: (stDelay, stChDmg, stSweep, stTurnReact,
   889         t^.PortalCounter:= 0;
   886         t^.PortalCounter:= 0;
   890         t:= t^.NextGear
   887         t:= t^.NextGear
   891         end
   888         end
   892 end;
   889 end;
   893 
   890 
   894 procedure ApplyDamage(Gear: PGear; Damage: Longword);
   891 procedure ApplyDamage(Gear: PGear; Damage: Longword; Source: TDamageSource);
   895 var s: shortstring;
   892 var s: shortstring;
   896     vampDmg, tmpDmg, i: Longword;
   893     vampDmg, tmpDmg, i: Longword;
   897     vg: PVisualGear;
   894     vg: PVisualGear;
   898 begin
   895 begin
   899     if (Gear^.Kind = gtHedgehog) and (Damage>=1) then
   896     if (Gear^.Kind = gtHedgehog) and (Damage>=1) then
   900     begin
   897     begin
       
   898     HHHurt(Gear^.Hedgehog, Source);
   901     AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.Color);
   899     AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.Color);
   902     tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
   900     tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
   903     if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
   901     if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
   904         begin
   902         begin
   905         if cVampiric then
   903         if cVampiric then
  1177 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask, Tint: LongWord);
  1175 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask, Tint: LongWord);
  1178 var Gear: PGear;
  1176 var Gear: PGear;
  1179     dmg, dmgRadius, dmgBase: LongInt;
  1177     dmg, dmgRadius, dmgBase: LongInt;
  1180     fX, fY: hwFloat;
  1178     fX, fY: hwFloat;
  1181     vg: PVisualGear;
  1179     vg: PVisualGear;
       
  1180     i, cnt: LongInt;
  1182 begin
  1181 begin
  1183 TargetPoint.X:= NoPointX;
  1182 TargetPoint.X:= NoPointX;
  1184 {$IFDEF DEBUGFILE}if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF}
  1183 {$IFDEF DEBUGFILE}if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF}
  1185 if Radius > 25 then KickFlakes(Radius, X, Y);
  1184 if Radius > 25 then KickFlakes(Radius, X, Y);
  1186 
  1185 
  1224                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
  1223                             dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
  1225                             //{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
  1224                             //{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
  1226                             if (Mask and EXPLNoDamage) = 0 then
  1225                             if (Mask and EXPLNoDamage) = 0 then
  1227                                 begin
  1226                                 begin
  1228                                 if not Gear^.Invulnerable then
  1227                                 if not Gear^.Invulnerable then
  1229                                     ApplyDamage(Gear, dmg)
  1228                                     ApplyDamage(Gear, dmg, dsExplosion)
  1230                                 else
  1229                                 else
  1231                                     Gear^.State:= Gear^.State or gstWinner;
  1230                                     Gear^.State:= Gear^.State or gstWinner;
  1232                                 end;
  1231                                 end;
  1233                             if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then
  1232                             if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then
  1234                                 begin
  1233                                 begin
  1261         end;
  1260         end;
  1262     Gear:= Gear^.NextGear
  1261     Gear:= Gear^.NextGear
  1263     end;
  1262     end;
  1264 
  1263 
  1265 if (Mask and EXPLDontDraw) = 0 then
  1264 if (Mask and EXPLDontDraw) = 0 then
  1266     if (GameFlags and gfSolidLand) = 0 then DrawExplosion(X, Y, Radius);
  1265     if (GameFlags and gfSolidLand) = 0 then
       
  1266         begin
       
  1267         cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk
       
  1268         if cnt > 0 then
       
  1269             for i:= 0 to cnt do
       
  1270                 AddVisualGear(X, Y, vgtChunk)
       
  1271         end;
  1267 
  1272 
  1268 uAIMisc.AwareOfExplosion(0, 0, 0)
  1273 uAIMisc.AwareOfExplosion(0, 0, 0)
  1269 end;
  1274 end;
  1270 
  1275 
  1271 procedure ShotgunShot(Gear: PGear);
  1276 procedure ShotgunShot(Gear: PGear);
  1283             gtMine,
  1288             gtMine,
  1284             gtCase,
  1289             gtCase,
  1285             gtTarget,
  1290             gtTarget,
  1286             gtExplosives: begin
  1291             gtExplosives: begin
  1287                     if (not t^.Invulnerable) then
  1292                     if (not t^.Invulnerable) then
  1288                         ApplyDamage(t, dmg)
  1293                         ApplyDamage(t, dmg, dsBullet)
  1289                     else
  1294                     else
  1290                         Gear^.State:= Gear^.State or gstWinner;
  1295                         Gear^.State:= Gear^.State or gstWinner;
  1291 
  1296 
  1292                     DeleteCI(t);
  1297                     DeleteCI(t);
  1293                     t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX);
  1298                     t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX);
  1338             gtTarget,
  1343             gtTarget,
  1339             gtCase,
  1344             gtCase,
  1340             gtExplosives: begin
  1345             gtExplosives: begin
  1341                     if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end;
  1346                     if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end;
  1342                     if (not Gear^.Invulnerable) then
  1347                     if (not Gear^.Invulnerable) then
  1343                         ApplyDamage(Gear, tmpDmg)
  1348                         ApplyDamage(Gear, tmpDmg, dsShove)
  1344                     else
  1349                     else
  1345                         Gear^.State:= Gear^.State or gstWinner;
  1350                         Gear^.State:= Gear^.State or gstWinner;
  1346                     if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then ApplyDamage(Gear, tmpDmg * 100); // crank up damage for explosives + blowtorch
  1351                     if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then ApplyDamage(Gear, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
  1347 
  1352 
  1348                     DeleteCI(Gear);
  1353                     DeleteCI(Gear);
  1349                     if (Gear^.Kind = gtHedgehog) and PHedgehog(Gear^.Hedgehog)^.King then
  1354                     if (Gear^.Kind = gtHedgehog) and PHedgehog(Gear^.Hedgehog)^.King then
  1350                         begin
  1355                         begin
  1351                         Gear^.dX:= Ammo^.dX * Power * _0_005;
  1356                         Gear^.dX:= Ammo^.dX * Power * _0_005;