hedgewars/GSHandlers.inc
changeset 4047 6c07a302b7c0
parent 4034 634a8c8682de
parent 4045 e3a2a39a8277
child 4050 8e4f4b72c132
equal deleted inserted replaced
4034:634a8c8682de 4047:6c07a302b7c0
  3412            or (iterator^.Y > Gear^.Y + acptRadius) then
  3412            or (iterator^.Y > Gear^.Y + acptRadius) then
  3413             continue;
  3413             continue;
  3414 
  3414 
  3415         hasdxy := ((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0));
  3415         hasdxy := ((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0));
  3416 
  3416 
       
  3417         // in case the object is not moving, let's asume it's moving towards the portal
       
  3418         if not hasdxy then
       
  3419         begin
       
  3420             ox:= Gear^.X - iterator^.X;
       
  3421             oy:= Gear^.Y - iterator^.Y;
       
  3422         end
       
  3423         else
       
  3424         begin
       
  3425             ox:= iterator^.dX;
       
  3426             oy:= iterator^.dY;
       
  3427         end;
       
  3428 
  3417         // won't port stuff that moves away from me!
  3429         // won't port stuff that moves away from me!
  3418         if hasdxy and not (Gear^.dX*iterator^.dX + Gear^.dY*iterator^.dY).isNegative then
  3430         if not (Gear^.dX*ox + Gear^.dY*oy).isNegative then
  3419                 continue;
  3431                 continue;
  3420 
  3432 
  3421         if (iterator^.Kind <> gtCake) then
  3433         if (iterator^.Kind <> gtCake) then
  3422         begin
  3434         begin
  3423             // wow! good candidate there, let's see if the distance and direction is okay!
  3435             // wow! good candidate there, let's see if the distance and direction is okay!
  4095     hh: PHedgehog;
  4107     hh: PHedgehog;
  4096     i: LongInt;
  4108     i: LongInt;
  4097 begin
  4109 begin
  4098     AllInactive := false;
  4110     AllInactive := false;
  4099     hh := PHedgehog(Gear^.Hedgehog);
  4111     hh := PHedgehog(Gear^.Hedgehog);
  4100     DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy -
  4112     DrawCentered(hwRound(hh^.Gear^.X) + WorldDx, hwRound(hh^.Gear^.Y) + WorldDy -
  4101             cHHRadius - 14 - hh^.HealthTagTex^.h, hh^.HealthTagTex);
  4113             cHHRadius - 14 - hh^.HealthTagTex^.h, hh^.HealthTagTex);
  4102     (*DrawCircle(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, 1.5, 0, 0, $FF,
  4114     (*DrawCircle(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Radius, 1.5, 0, 0, $FF,
  4103             $FF);*)
  4115             $FF);*)
  4104 
  4116 
  4105     doStepHedgehogMoving(hh^.Gear);
       
  4106     hh^.Gear^.Y := Gear^.Y;
       
  4107 
       
  4108     if ((Gear^.Message and gmUp) <> 0) then 
  4117     if ((Gear^.Message and gmUp) <> 0) then 
  4109         begin
  4118         begin
  4110         if (GameTicks and $F) <> 0 then exit;
  4119         if (GameTicks and $F) <> 0 then exit;
  4111         end 
  4120         end 
  4112     else if (GameTicks and $1FF) <> 0 then exit;
  4121     else if (GameTicks and $1FF) <> 0 then exit;
  4113 
  4122 
  4114     if Gear^.Power < 45 then begin
  4123     if Gear^.Power < 45 then 
       
  4124         begin
  4115         inc(Gear^.Power);
  4125         inc(Gear^.Power);
  4116         Gear^.Y := Gear^.Y - _1;
  4126         if not TestCollisionYwithGear(hh^.Gear, -1) then hh^.Gear^.Y := hh^.Gear^.Y - _1;
  4117     end;
  4127         end;
  4118 
  4128 
  4119     graves := GearsNear(hh^.Gear^.X, hh^.Gear^.Y + int2hwFloat(Gear^.Power),
  4129     graves := GearsNear(Gear^.X, Gear^.Y + int2hwFloat(Gear^.Power),
  4120                     gtGrave, Gear^.Radius);
  4130                     gtGrave, Gear^.Radius);
  4121 
  4131 
  4122     if Length(graves) = 0 then begin
  4132     if Length(graves) = 0 then 
       
  4133         begin
  4123         StopSound(Gear^.SoundChannel);
  4134         StopSound(Gear^.SoundChannel);
  4124         Gear^.Timer := 250;
  4135         Gear^.Timer := 250;
  4125         Gear^.doStep := @doStepIdle;
  4136         Gear^.doStep := @doStepIdle;
  4126         exit;
  4137         exit;
  4127     end;
  4138         end;
  4128 
  4139 
  4129     if ((Gear^.Message and gmAttack) <> 0) and (hh^.Gear^.Health > 0) then begin
  4140     if ((Gear^.Message and gmAttack) <> 0) and (hh^.Gear^.Health > 0) then 
       
  4141         begin
  4130         i := getRandom(Length(graves));
  4142         i := getRandom(Length(graves));
  4131         dec(hh^.Gear^.Health);
  4143         dec(hh^.Gear^.Health);
  4132         if (hh^.Gear^.Health = 0) and (hh^.Gear^.Damage = 0) then
  4144         if (hh^.Gear^.Health = 0) and (hh^.Gear^.Damage = 0) then
  4133             hh^.Gear^.Damage:= 1;
  4145             hh^.Gear^.Damage:= 1;
  4134         RenderHealth(hh^);
  4146         RenderHealth(hh^);
  4137             if hh^.Gear^.Health > 0 then begin
  4149             if hh^.Gear^.Health > 0 then begin
  4138                 dec(hh^.Gear^.Health);
  4150                 dec(hh^.Gear^.Health);
  4139                 inc(graves[i]^.Health);
  4151                 inc(graves[i]^.Health);
  4140             end;
  4152             end;
  4141         end; -}
  4153         end; -}
  4142     end else begin
  4154         end 
       
  4155     else 
       
  4156         begin
  4143         // now really resurrect the hogs with the hp saved in the graves
  4157         // now really resurrect the hogs with the hp saved in the graves
  4144         for i:= 0 to High(graves) do
  4158         for i:= 0 to High(graves) do
  4145             if graves[i]^.Health > 0 then begin
  4159             if graves[i]^.Health > 0 then
       
  4160                 begin
  4146                 resgear := AddGear(hwRound(graves[i]^.X), hwRound(graves[i]^.Y),
  4161                 resgear := AddGear(hwRound(graves[i]^.X), hwRound(graves[i]^.Y),
  4147                         gtHedgehog, gstWait, _0, _0, 0);
  4162                         gtHedgehog, gstWait, _0, _0, 0);
  4148                 resgear^.Hedgehog := graves[i]^.Hedgehog;
  4163                 resgear^.Hedgehog := graves[i]^.Hedgehog;
  4149                 resgear^.Health := graves[i]^.Health;
  4164                 resgear^.Health := graves[i]^.Health;
  4150                 PHedgehog(graves[i]^.Hedgehog)^.Gear := resgear;
  4165                 PHedgehog(graves[i]^.Hedgehog)^.Gear := resgear;
  4151                 DeleteGear(graves[i]);
  4166                 DeleteGear(graves[i]);
  4152                 RenderHealth(PHedgehog(resgear^.Hedgehog)^);
  4167                 RenderHealth(PHedgehog(resgear^.Hedgehog)^);
  4153                 RecountTeamHealth(Phedgehog(resgear^.Hedgehog)^.Team);
  4168                 RecountTeamHealth(Phedgehog(resgear^.Hedgehog)^.Team);
  4154                 FreeTexture(PHedgehog(resgear^.Hedgehog)^.HatTex);
  4169                 PHedgehog(resgear^.Hedgehog)^.Effects[heResurrected]:= true;
  4155                 PHedgehog(resgear^.Hedgehog)^.HatTex := Surface2Tex(
  4170                 if PHedgehog(resgear^.Hedgehog)^.Hat = 'NoHat' then
  4156                     LoadImage(Pathz[ptHats] + '/Reserved/Zombie', ifNone),
  4171                     begin
  4157                     True);
  4172                     FreeTexture(PHedgehog(resgear^.Hedgehog)^.HatTex);
  4158             end;
  4173                     PHedgehog(resgear^.Hedgehog)^.HatTex := Surface2Tex(
       
  4174                         LoadImage(Pathz[ptHats] + '/Reserved/Zombie', ifNone),
       
  4175                         True)
       
  4176                     end
       
  4177                 end;
  4159 
  4178 
  4160         hh^.Gear^.dY := _0;
  4179         hh^.Gear^.dY := _0;
       
  4180         hh^.Gear^.dX := _0;
       
  4181         doStepHedgehogMoving(hh^.Gear);
  4161         StopSound(Gear^.SoundChannel);
  4182         StopSound(Gear^.SoundChannel);
  4162         Gear^.Timer := 250;
  4183         Gear^.Timer := 250;
  4163         Gear^.doStep := @doStepIdle;
  4184         Gear^.doStep := @doStepIdle;
  4164     end;
  4185         end
  4165     //if hh^.Gear^.Health = 0 then doStepHedgehogFree(hh^.Gear);
  4186     //if hh^.Gear^.Health = 0 then doStepHedgehogFree(hh^.Gear);
  4166 end;
  4187 end;
  4167 
  4188 
  4168 procedure doStepResurrector(Gear: PGear);
  4189 procedure doStepResurrector(Gear: PGear);
  4169 var
  4190 var
  4170     graves: TPGearArray;
  4191     graves: TPGearArray;
  4171     hh: PHedgehog;
       
  4172     i: LongInt;
  4192     i: LongInt;
  4173 begin
  4193 begin
  4174     AllInactive := false;
  4194     AllInactive := false;
  4175     hh := PHedgehog(Gear^.Hedgehog);
  4195     graves := GearsNear(Gear^.X, Gear^.Y, gtGrave, Gear^.Radius);
  4176     graves := GearsNear(hh^.Gear^.X, hh^.Gear^.Y, gtGrave, Gear^.Radius);
  4196 
  4177 
  4197     if Length(graves) > 0 then
  4178     if Length(graves) > 0 then begin
  4198         begin
  4179         for i:= 0 to High(graves) do begin
  4199         for i:= 0 to High(graves) do
       
  4200             begin
  4180             PHedgehog(graves[i]^.Hedgehog)^.Gear := nil;
  4201             PHedgehog(graves[i]^.Hedgehog)^.Gear := nil;
  4181             graves[i]^.Health := 0;
  4202             graves[i]^.Health := 0;
  4182         end;
  4203             end;
  4183         Gear^.doStep := @doStepResurrectorWork;
  4204         Gear^.doStep := @doStepResurrectorWork;
  4184     end else begin
  4205         end 
       
  4206     else 
       
  4207         begin
  4185         StopSound(Gear^.SoundChannel);
  4208         StopSound(Gear^.SoundChannel);
  4186         Gear^.Timer := 250;
  4209         Gear^.Timer := 250;
  4187         Gear^.doStep := @doStepIdle;
  4210         Gear^.doStep := @doStepIdle;
  4188     end;
  4211         end
  4189 end;
  4212 end;
  4190 
  4213