hedgewars/uGears.pas
changeset 307 96b428ac11f2
parent 306 7b61834edcf6
child 351 29bc9c36ad5f
equal deleted inserted replaced
306:7b61834edcf6 307:96b428ac11f2
    62 procedure InsertGearToList(Gear: PGear);
    62 procedure InsertGearToList(Gear: PGear);
    63 procedure RemoveGearFromList(Gear: PGear);
    63 procedure RemoveGearFromList(Gear: PGear);
    64 
    64 
    65 var CurAmmoGear: PGear = nil;
    65 var CurAmmoGear: PGear = nil;
    66     GearsList: PGear = nil;
    66     GearsList: PGear = nil;
       
    67     KilledHHs: Longword = 0;
    67 
    68 
    68 implementation
    69 implementation
    69 uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions,
    70 uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions,
    70      uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos;
    71      uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos;
    71 var RopePoints: record
    72 var RopePoints: record
    75                                   X, Y: Double;
    76                                   X, Y: Double;
    76                                   dLen: Double;
    77                                   dLen: Double;
    77                                   b: boolean;
    78                                   b: boolean;
    78                                   end;
    79                                   end;
    79                  end;
    80                  end;
       
    81     StepDamage: Longword = 0;
    80 
    82 
    81 procedure DeleteGear(Gear: PGear); forward;
    83 procedure DeleteGear(Gear: PGear); forward;
    82 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward;
    84 procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward;
    83 procedure AmmoShove(Ammo: PGear; Damage, Power: integer); forward;
    85 procedure AmmoShove(Ammo: PGear; Damage, Power: integer); forward;
    84 procedure AmmoFlameWork(Ammo: PGear); forward;
    86 procedure AmmoFlameWork(Ammo: PGear); forward;
   273 InsertGearToList(Result)
   275 InsertGearToList(Result)
   274 end;
   276 end;
   275 
   277 
   276 procedure DeleteGear(Gear: PGear);
   278 procedure DeleteGear(Gear: PGear);
   277 var team: PTeam;
   279 var team: PTeam;
       
   280     t: Longword;
   278 begin
   281 begin
   279 if Gear.CollIndex < High(Longword) then DeleteCI(Gear);
   282 if Gear.CollIndex < High(Longword) then DeleteCI(Gear);
   280 if Gear.Surf <> nil then SDL_FreeSurface(Gear.Surf);
   283 if Gear.Surf <> nil then SDL_FreeSurface(Gear.Surf);
   281 if Gear.Kind = gtHedgehog then
   284 if Gear.Kind = gtHedgehog then
   282    if CurAmmoGear <> nil then
   285    if CurAmmoGear <> nil then
   286       CurAmmoGear.Message:= gm_Destroy;
   289       CurAmmoGear.Message:= gm_Destroy;
   287       exit
   290       exit
   288       end else
   291       end else
   289       begin
   292       begin
   290       if Gear.Y >= cWaterLine then
   293       if Gear.Y >= cWaterLine then
   291          AddGear(Round(Gear.X), Round(Gear.Y), gtHealthTag, max(Gear.Damage, Gear.Health)).Hedgehog:= Gear.Hedgehog;
   294          begin
       
   295          t:= max(Gear.Damage, Gear.Health);
       
   296          AddGear(Round(Gear.X), Round(Gear.Y), gtHealthTag, t).Hedgehog:= Gear.Hedgehog;
       
   297          inc(StepDamage, t)
       
   298          end;
   292       team:= PHedgehog(Gear.Hedgehog).Team;
   299       team:= PHedgehog(Gear.Hedgehog).Team;
   293       if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear = Gear then
   300       if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear = Gear then
   294          FreeActionsList; // to avoid ThinkThread on drawned gear
   301          FreeActionsList; // to avoid ThinkThread on drawned gear
   295       PHedgehog(Gear.Hedgehog).Gear:= nil;
   302       PHedgehog(Gear.Hedgehog).Gear:= nil;
       
   303       inc(KilledHHs);
   296       RecountTeamHealth(team);
   304       RecountTeamHealth(team);
   297       end;
   305       end;
   298 {$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF}
   306 {$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF}
   299 if CurAmmoGear = Gear then CurAmmoGear:= nil;
   307 if CurAmmoGear = Gear then CurAmmoGear:= nil;
   300 if FollowGear = Gear then FollowGear:= nil;
   308 if FollowGear = Gear then FollowGear:= nil;
   311       begin
   319       begin
   312       if Gear.Kind = gtHedgehog then
   320       if Gear.Kind = gtHedgehog then
   313          if Gear.Damage <> 0 then
   321          if Gear.Damage <> 0 then
   314             begin
   322             begin
   315             Result:= false;
   323             Result:= false;
       
   324             inc(StepDamage, Gear.Damage);
   316             if Gear.Health < Gear.Damage then Gear.Health:= 0
   325             if Gear.Health < Gear.Damage then Gear.Health:= 0
   317                                          else dec(Gear.Health, Gear.Damage);
   326                                          else dec(Gear.Health, Gear.Damage);
   318             AddGear(Round(Gear.X), round(Gear.Y) - cHHRadius - 12 - PHedgehog(Gear.Hedgehog)^.HealthTag.h,
   327             AddGear(Round(Gear.X), round(Gear.Y) - cHHRadius - 12 - PHedgehog(Gear.Hedgehog)^.HealthTag.h,
   319                     gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog;
   328                     gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog;
   320             RenderHealth(PHedgehog(Gear.Hedgehog)^);
   329             RenderHealth(PHedgehog(Gear.Hedgehog)^);
   372                  inc(step)
   381                  inc(step)
   373                  end;
   382                  end;
   374         stNTurn: begin
   383         stNTurn: begin
   375                  AwareOfExplosion(0, 0, 0);
   384                  AwareOfExplosion(0, 0, 0);
   376                  if isInMultiShoot then isInMultiShoot:= false
   385                  if isInMultiShoot then isInMultiShoot:= false
   377                                    else ParseCommand('/nextturn');
   386                     else begin
       
   387                     with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
       
   388                          if MaxStepDamage < StepDamage then MaxStepDamage:= StepDamage;
       
   389                     StepDamage:= 0;
       
   390                     ParseCommand('/nextturn');
       
   391                     end;
   378                  step:= Low(step)
   392                  step:= Low(step)
   379                  end;
   393                  end;
   380         end;
   394         end;
   381 
   395 
   382 if TurnTimeLeft > 0 then
   396 if TurnTimeLeft > 0 then
   671 end;
   685 end;
   672 
   686 
   673 procedure AmmoShove(Ammo: PGear; Damage, Power: integer);
   687 procedure AmmoShove(Ammo: PGear; Damage, Power: integer);
   674 var t: PGearArray;
   688 var t: PGearArray;
   675     i: integer;
   689     i: integer;
       
   690     hh: PHedgehog;
   676 begin
   691 begin
   677 t:= CheckGearsCollision(Ammo);
   692 t:= CheckGearsCollision(Ammo);
   678 i:= t.Count;
   693 i:= t.Count;
       
   694 hh:= Ammo.Hedgehog;
   679 while i > 0 do
   695 while i > 0 do
   680     begin
   696     begin
   681     dec(i);
   697     dec(i);
   682     if (t.ar[i].State and gstNoDamage) = 0 then
   698     if (t.ar[i].State and gstNoDamage) = 0 then
   683        case t.ar[i].Kind of
   699        case t.ar[i].Kind of
   684            gtHedgehog,
   700            gtHedgehog,
   685                gtMine,
   701                gtMine,
   686                gtCase: begin
   702                gtCase: begin
   687                        inc(t.ar[i].Damage, Damage);
   703                        inc(t.ar[i].Damage, Damage);
       
   704                        inc(hh.DamageGiven, Damage);
   688                        t.ar[i].dX:= Ammo.dX * Power * 0.01;
   705                        t.ar[i].dX:= Ammo.dX * Power * 0.01;
   689                        t.ar[i].dY:= Ammo.dY * Power * 0.01;
   706                        t.ar[i].dY:= Ammo.dY * Power * 0.01;
   690                        t.ar[i].Active:= true;
   707                        t.ar[i].Active:= true;
   691                        DeleteCI(t.ar[i]);
   708                        DeleteCI(t.ar[i]);
   692                        FollowGear:= t.ar[i]
   709                        FollowGear:= t.ar[i]