hedgewars/uGearsHandlersMess.pas
changeset 14554 397b2f4502c1
parent 14514 5ac181cb2396
child 14557 3be619402d6b
equal deleted inserted replaced
14553:5ae97eab70eb 14554:397b2f4502c1
  1189             DeleteGear(Gear);
  1189             DeleteGear(Gear);
  1190             AfterAttack
  1190             AfterAttack
  1191             end
  1191             end
  1192         end
  1192         end
  1193     else
  1193     else
  1194         begin
  1194 		DeleteGear(Gear);
  1195         DeleteGear(Gear);
       
  1196         end
       
  1197 end;
  1195 end;
  1198 
  1196 
  1199 procedure CreateShellForGear(Gear: PGear; startFrame: Longword);
  1197 procedure CreateShellForGear(Gear: PGear; startFrame: Longword);
  1200 var
  1198 var
  1201     shell: PVisualGear;
  1199     shell: PVisualGear;
  2039                 if ((Gear^.State and gstWait) <> 0)
  2037                 if ((Gear^.State and gstWait) <> 0)
  2040                 or (cMineDudPercent = 0)
  2038                 or (cMineDudPercent = 0)
  2041                 or (getRandom(100) > cMineDudPercent) then
  2039                 or (getRandom(100) > cMineDudPercent) then
  2042                     begin
  2040                     begin
  2043                     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
  2041                     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
  2044                     DeleteGear(Gear)
  2042                     DeleteGear(Gear);
       
  2043 					exit   // redundant but we've had too many delete gear bugs
  2045                     end
  2044                     end
  2046                 else
  2045                 else
  2047                     begin
  2046                     begin
  2048                     vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
  2047                     vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
  2049                     if vg <> nil then
  2048                     if vg <> nil then
  2082                 // Remove land created by frozen air mine sprite pixel-perfectly
  2081                 // Remove land created by frozen air mine sprite pixel-perfectly
  2083                 EraseLand(
  2082                 EraseLand(
  2084                     hwRound(Gear^.X) - SpritesData[sprFrozenAirMine].Width div 2,
  2083                     hwRound(Gear^.X) - SpritesData[sprFrozenAirMine].Width div 2,
  2085                     hwRound(Gear^.Y) - SpritesData[sprFrozenAirMine].Height div 2,
  2084                     hwRound(Gear^.Y) - SpritesData[sprFrozenAirMine].Height div 2,
  2086                     sprFrozenAirMine, 0, 0, false, false, false, false);
  2085                     sprFrozenAirMine, 0, 0, false, false, false, false);
  2087             DeleteGear(Gear)
  2086             DeleteGear(Gear);
       
  2087 			exit
  2088             end;
  2088             end;
  2089         doStepFallingGear(Gear);
  2089         doStepFallingGear(Gear);
  2090         exit
  2090         exit
  2091         end;
  2091         end;
  2092     isUnderwater:= CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y) + Gear^.Radius);
  2092     isUnderwater:= CheckCoordInWater(hwRound(Gear^.X), hwRound(Gear^.Y) + Gear^.Radius);
  2462         begin
  2462         begin
  2463         x := hwRound(Gear^.X);
  2463         x := hwRound(Gear^.X);
  2464         y := hwRound(Gear^.Y);
  2464         y := hwRound(Gear^.Y);
  2465         hog:= Gear^.Hedgehog;
  2465         hog:= Gear^.Hedgehog;
  2466 
  2466 
  2467         DeleteGear(Gear);
       
  2468         // <-- delete gear!
       
  2469 
       
  2470         if k = gtCase then
  2467         if k = gtCase then
  2471             begin
  2468             begin
  2472             doMakeExplosion(x, y, Gear^.Boom, hog, EXPLAutoSound);
  2469             doMakeExplosion(x, y, Gear^.Boom, hog, EXPLAutoSound);
  2473             for i:= 0 to 63 do
  2470             for i:= 0 to 63 do
  2474                 AddGear(x, y, gtFlame, 0, _0, _0, 0);
  2471                 AddGear(x, y, gtFlame, 0, _0, _0, 0);
  2475             end
  2472             end
  2476         else if k = gtTarget then
  2473         else if k = gtTarget then
  2477             uStats.TargetHit()
  2474             uStats.TargetHit()
  2478         else if k = gtExplosives then
  2475         else if k = gtExplosives then
  2479                 begin
  2476 			begin
  2480                 doMakeExplosion(x, y, Gear^.Boom, hog, EXPLAutoSound);
  2477 			doMakeExplosion(x, y, Gear^.Boom, hog, EXPLAutoSound);
  2481                 for i:= 0 to 31 do
  2478 			for i:= 0 to 31 do
  2482                     begin
  2479 				begin
  2483                     dX := AngleCos(i * 64) * _0_5 * (getrandomf + _1);
  2480 				dX := AngleCos(i * 64) * _0_5 * (getrandomf + _1);
  2484                     dY := AngleSin(i * 64) * _0_5 * (getrandomf + _1);
  2481 				dY := AngleSin(i * 64) * _0_5 * (getrandomf + _1);
  2485                     AddGear(x, y, gtFlame, 0, dX, dY, 0);
  2482 				AddGear(x, y, gtFlame, 0, dX, dY, 0);
  2486                     AddGear(x, y, gtFlame, gstTmpFlag, -dX, -dY, 0);
  2483 				AddGear(x, y, gtFlame, gstTmpFlag, -dX, -dY, 0);
  2487                     end
  2484 				end
  2488                 end;
  2485 			end;
  2489             exit
  2486         DeleteGear(Gear);
       
  2487 		exit
  2490         end;
  2488         end;
  2491 
  2489 
  2492     if k = gtExplosives then
  2490     if k = gtExplosives then
  2493         begin
  2491         begin
  2494         //if V > _0_03 then Gear^.State:= Gear^.State or gstAnimation;
  2492         //if V > _0_03 then Gear^.State:= Gear^.State or gstAnimation;
  2863         else
  2861         else
  2864             for i:= Random(3) downto 0 do
  2862             for i:= Random(3) downto 0 do
  2865                 AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke);
  2863                 AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke);
  2866 
  2864 
  2867         DeleteGear(Gear)
  2865         DeleteGear(Gear)
  2868         end;
  2866         end
  2869 end;
  2867 end;
  2870 
  2868 
  2871 ////////////////////////////////////////////////////////////////////////////////
  2869 ////////////////////////////////////////////////////////////////////////////////
  2872 procedure doStepFirePunchWork(Gear: PGear);
  2870 procedure doStepFirePunchWork(Gear: PGear);
  2873 var
  2871 var
  2956             Message := 0;
  2954             Message := 0;
  2957             SetLittle(dX);
  2955             SetLittle(dX);
  2958             dY := _0;
  2956             dY := _0;
  2959             State := State or gstMoving;
  2957             State := State or gstMoving;
  2960             end;
  2958             end;
  2961         DeleteGear(Gear);
       
  2962         if (GetAmmoEntry(HHGear^.Hedgehog^, amParachute)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
  2959         if (GetAmmoEntry(HHGear^.Hedgehog^, amParachute)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
  2963             HHGear^.Hedgehog^.CurAmmoType:= amParachute;
  2960             HHGear^.Hedgehog^.CurAmmoType:= amParachute;
  2964         isCursorVisible := false;
  2961         isCursorVisible := false;
  2965         ApplyAmmoChanges(HHGear^.Hedgehog^);
  2962         ApplyAmmoChanges(HHGear^.Hedgehog^);
       
  2963         DeleteGear(Gear);
  2966         exit
  2964         exit
  2967         end;
  2965         end;
  2968 
  2966 
  2969     HHGear^.X := HHGear^.X + cWindSpeed * 200;
  2967     HHGear^.X := HHGear^.X + cWindSpeed * 200;
  2970 
  2968 
  3040     if (hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) then
  3038     if (hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) then
  3041         begin
  3039         begin
  3042         // avoid to play forever (is this necessary?)
  3040         // avoid to play forever (is this necessary?)
  3043         StopSoundChan(Gear^.SoundChannel);
  3041         StopSoundChan(Gear^.SoundChannel);
  3044         DeleteGear(Gear)
  3042         DeleteGear(Gear)
  3045         end;
  3043         end
  3046 end;
  3044 end;
  3047 
  3045 
  3048 procedure doStepAirAttack(Gear: PGear);
  3046 procedure doStepAirAttack(Gear: PGear);
  3049 begin
  3047 begin
  3050     AllInactive := false;
  3048     AllInactive := false;
  3083     AllInactive := false;
  3081     AllInactive := false;
  3084     doStepFallingGear(Gear);
  3082     doStepFallingGear(Gear);
  3085     if (Gear^.State and gstCollision) <> 0 then
  3083     if (Gear^.State and gstCollision) <> 0 then
  3086         begin
  3084         begin
  3087         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
  3085         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Boom, Gear^.Hedgehog, EXPLAutoSound);
  3088         DeleteGear(Gear);
       
  3089         {$IFNDEF PAS2C}
  3086         {$IFNDEF PAS2C}
  3090         with mobileRecord do
  3087         with mobileRecord do
  3091             if (performRumble <> nil) and (not fastUntilLag) then
  3088             if (performRumble <> nil) and (not fastUntilLag) then
  3092                 performRumble(kSystemSoundID_Vibrate);
  3089                 performRumble(kSystemSoundID_Vibrate);
  3093         {$ENDIF}
  3090         {$ENDIF}
       
  3091         DeleteGear(Gear);
  3094         exit
  3092         exit
  3095         end;
  3093         end;
  3096     if (GameTicks and $3F) = 0 then
  3094     if (GameTicks and $3F) = 0 then
  3097         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace)
  3095         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace)
  3098 end;
  3096 end;
  3144         end
  3142         end
  3145     else
  3143     else
  3146         begin
  3144         begin
  3147         PlaySound(sndPlaced);
  3145         PlaySound(sndPlaced);
  3148         DeleteGear(Gear);
  3146         DeleteGear(Gear);
  3149         AfterAttack;
  3147         AfterAttack
  3150         end;
  3148         end;
  3151 
  3149 
  3152     HHGear^.State := HHGear^.State and (not (gstAttacking or gstAttacked));
  3150     HHGear^.State := HHGear^.State and (not (gstAttacking or gstAttacked));
  3153     HHGear^.Message := HHGear^.Message and (not gmAttack);
  3151     HHGear^.Message := HHGear^.Message and (not gmAttack);
  3154 end;
  3152 end;
  3176 begin
  3174 begin
  3177     if (Gear^.Hedgehog^.Gear = nil) or (Gear^.Hedgehog^.Gear^.Damage > 0) then
  3175     if (Gear^.Hedgehog^.Gear = nil) or (Gear^.Hedgehog^.Gear^.Damage > 0) then
  3178         begin
  3176         begin
  3179         DeleteGear(Gear);
  3177         DeleteGear(Gear);
  3180         AfterAttack;
  3178         AfterAttack;
       
  3179 		exit
  3181         end;
  3180         end;
  3182     inc(Gear^.Timer);
  3181     inc(Gear^.Timer);
  3183     if Gear^.Timer = 65 then
  3182     if Gear^.Timer = 65 then
  3184         begin
  3183         begin
  3185         Gear^.Timer := 0;
  3184         Gear^.Timer := 0;
  3279 
  3278 
  3280     if ((Gear^.Message and (not (gmSwitch or gmPrecise))) <> 0) or (TurnTimeLeft = 0) then
  3279     if ((Gear^.Message and (not (gmSwitch or gmPrecise))) <> 0) or (TurnTimeLeft = 0) then
  3281         begin
  3280         begin
  3282         hedgehog := Gear^.Hedgehog;
  3281         hedgehog := Gear^.Hedgehog;
  3283         //Msg := Gear^.Message and (not gmSwitch);
  3282         //Msg := Gear^.Message and (not gmSwitch);
  3284         DeleteGear(Gear);
       
  3285         ApplyAmmoChanges(hedgehog^);
  3283         ApplyAmmoChanges(hedgehog^);
  3286 
  3284 
  3287         HHGear := CurrentHedgehog^.Gear;
  3285         HHGear := CurrentHedgehog^.Gear;
  3288         ApplyAmmoChanges(HHGear^.Hedgehog^);
  3286         ApplyAmmoChanges(HHGear^.Hedgehog^);
  3289         //HHGear^.Message := Msg;
  3287         //HHGear^.Message := Msg;
       
  3288         DeleteGear(Gear);
  3290         exit
  3289         exit
  3291         end;
  3290         end;
  3292 
  3291 
  3293     if (Gear^.Message and gmSwitch) <> 0 then
  3292     if (Gear^.Message and gmSwitch) <> 0 then
  3294         begin
  3293         begin
  4488                 begin
  4487                 begin
  4489                 Message := 0;
  4488                 Message := 0;
  4490                 Active := true;
  4489                 Active := true;
  4491                 State := State or gstMoving
  4490                 State := State or gstMoving
  4492                 end;
  4491                 end;
  4493             DeleteGear(Gear);
       
  4494             if (GetAmmoEntry(HHGear^.Hedgehog^, amJetpack)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
  4492             if (GetAmmoEntry(HHGear^.Hedgehog^, amJetpack)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and (HHGear^.Hedgehog^.MultiShootAttacks = 0) then
  4495                 HHGear^.Hedgehog^.CurAmmoType:= amJetpack;
  4493                 HHGear^.Hedgehog^.CurAmmoType:= amJetpack;
  4496             isCursorVisible := false;
  4494             isCursorVisible := false;
  4497             ApplyAmmoChanges(HHGear^.Hedgehog^);
  4495             ApplyAmmoChanges(HHGear^.Hedgehog^);
  4498         //    if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
  4496         //    if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
  4499 
  4497 
  4500 //    Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', cWhiteColor, fntSmall)
  4498 //    Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', cWhiteColor, fntSmall)
  4501 
  4499 
  4502 //AddCaption(trmsg[sidFuel]+': '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
  4500 //AddCaption(trmsg[sidFuel]+': '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
       
  4501             DeleteGear(Gear);
  4503             end
  4502             end
  4504 end;
  4503 end;
  4505 
  4504 
  4506 procedure doStepJetpack(Gear: PGear);
  4505 procedure doStepJetpack(Gear: PGear);
  4507 var
  4506 var
  4535     AllInactive := false;
  4534     AllInactive := false;
  4536     Gear^.Pos := 0;
  4535     Gear^.Pos := 0;
  4537     if Gear^.Timer < 2000 then
  4536     if Gear^.Timer < 2000 then
  4538         inc(Gear^.Timer, 1)
  4537         inc(Gear^.Timer, 1)
  4539     else
  4538     else
  4540         begin
  4539         DeleteGear(Gear)
  4541         DeleteGear(Gear);
       
  4542         end;
       
  4543 end;
  4540 end;
  4544 
  4541 
  4545 procedure doStepBirdyFly(Gear: PGear);
  4542 procedure doStepBirdyFly(Gear: PGear);
  4546 var
  4543 var
  4547     HHGear: PGear;
  4544     HHGear: PGear;