hedgewars/uGears.pas
changeset 2760 420fe0344e5f
parent 2759 03988f64e146
child 2762 2fbc8d35eb52
equal deleted inserted replaced
2759:03988f64e146 2760:420fe0344e5f
   424 AddGear:= gear;
   424 AddGear:= gear;
   425 end;
   425 end;
   426 
   426 
   427 procedure DeleteGear(Gear: PGear);
   427 procedure DeleteGear(Gear: PGear);
   428 var team: PTeam;
   428 var team: PTeam;
   429 	t,i,k: Longword;
   429 	t,i: Longword;
       
   430     k: boolean;
   430 begin
   431 begin
   431 DeleteCI(Gear);
   432 DeleteCI(Gear);
   432 
   433 
   433 if Gear^.Tex <> nil then
   434 if Gear^.Tex <> nil then
   434 	begin
   435 	begin
   455 
   456 
   456 		team:= PHedgehog(Gear^.Hedgehog)^.Team;
   457 		team:= PHedgehog(Gear^.Hedgehog)^.Team;
   457 		if CurrentHedgehog^.Gear = Gear then
   458 		if CurrentHedgehog^.Gear = Gear then
   458 			FreeActionsList; // to avoid ThinkThread on drawned gear
   459 			FreeActionsList; // to avoid ThinkThread on drawned gear
   459 
   460 
       
   461 		PHedgehog(Gear^.Hedgehog)^.Gear:= nil;
   460         if PHedgehog(Gear^.Hedgehog)^.King then
   462         if PHedgehog(Gear^.Hedgehog)^.King then
   461             begin
   463             begin
   462             // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
   464             // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
   463             k:= 0;
   465             k:= false;
   464             for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
   466             for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
   465                 if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then inc(k);
   467                 if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then k:= true;
   466             if k < 2 then // current dying king is count of 1
   468             if not k then
   467                 for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
   469                 for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
   468                     TeamGoneEffect(team^.Clan^.Teams[i]^)
   470                     TeamGoneEffect(team^.Clan^.Teams[i]^)
   469             end;
   471             end;
   470 
       
   471 		PHedgehog(Gear^.Hedgehog)^.Gear:= nil;
       
   472 		inc(KilledHHs);
   472 		inc(KilledHHs);
   473 		RecountTeamHealth(team)
   473 		RecountTeamHealth(team)
   474 		end;
   474 		end;
   475 {$IFDEF DEBUGFILE}
   475 {$IFDEF DEBUGFILE}
   476 with Gear^ do AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + inttostr(ord(Kind)));
   476 with Gear^ do AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + inttostr(ord(Kind)));