hedgewars/uGears.pas
changeset 10818 f642a28cab0c
parent 10789 acbf69e2e5cf
child 10820 e86ba0e821a6
equal deleted inserted replaced
10816:37410518628e 10818:f642a28cab0c
    31  *
    31  *
    32  * Note: Gears that do not have an effect on the game but are just visual
    32  * Note: Gears that do not have an effect on the game but are just visual
    33  *       effects are called "Visual Gears" and defined in the respective unit!
    33  *       effects are called "Visual Gears" and defined in the respective unit!
    34  *)
    34  *)
    35 interface
    35 interface
    36 uses uConsts, uFloat, uTypes, uChat;
    36 uses uConsts, uFloat, uTypes, uChat, uCollisions;
    37 
    37 
    38 procedure initModule;
    38 procedure initModule;
    39 procedure freeModule;
    39 procedure freeModule;
    40 function  SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content, cnt: Longword): PGear;
    40 function  SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content, cnt: Longword): PGear;
    41 function  SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean ): PGear;
    41 function  SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean ): PGear;
   392         and (not CurrentHedgehog^.Unplaced) then
   392         and (not CurrentHedgehog^.Unplaced) then
   393             begin
   393             begin
   394             if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0)
   394             if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0)
   395             and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then
   395             and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then
   396                 begin
   396                 begin
   397                 CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstHHChooseTarget;
   397                 CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstChooseTarget;
   398                 isCursorVisible := true
   398                 isCursorVisible := true
   399                 end;
   399                 end;
   400             CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and (not gstAttacked);
   400             CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and (not gstAttacked);
   401             end;
   401             end;
   402         if delay2 = 0 then
   402         if delay2 = 0 then
   565         Dispose(t)
   565         Dispose(t)
   566     end;
   566     end;
   567 end;
   567 end;
   568 
   568 
   569 procedure AddMiscGears;
   569 procedure AddMiscGears;
   570 var p,i,j, unplaced: Longword;
   570 var p,i,j,t,h,unplaced: Longword;
   571     rx, ry: LongInt;
   571     rx, ry: LongInt;
   572     rdx, rdy: hwFloat;
   572     rdx, rdy: hwFloat;
   573     Gear: PGear;
   573     Gear: PGear;
   574 begin
   574 begin
   575 AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000);
   575 AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000);
   601     else
   601     else
   602         unplaced:= 0;
   602         unplaced:= 0;
   603 
   603 
   604     inc(i)
   604     inc(i)
   605     end;
   605     end;
       
   606 
       
   607 i:= 0;
       
   608 j:= 0;
       
   609 p:= 0; // 0 searching, 1 bad position, 2 added.
       
   610 unplaced:= 0;
       
   611 if cAirMines > 0 then
       
   612     Gear:= AddGear(0, 0, gtAirMine, 0, _0, _0, 0);
       
   613 while (i < cAirMines) and (j < 1000*cAirMines) do
       
   614     begin
       
   615     p:= 0;
       
   616     if hasBorder then
       
   617         begin
       
   618         rx:= leftX+GetRandom(rightX-leftX-16)+8;
       
   619         ry:= topY+GetRandom(LAND_HEIGHT-topY-16)+8
       
   620         end
       
   621     else
       
   622         begin
       
   623         rx:= leftX+GetRandom(rightX-leftX+400)-200;
       
   624         ry:= topY+GetRandom(LAND_HEIGHT-topY+400)-200
       
   625         end;
       
   626     Gear^.X:= int2hwFloat(rx);
       
   627     Gear^.Y:= int2hwFloat(ry);
       
   628     if CheckLandValue(rx, ry, $FFFF) and
       
   629        (TestCollisionYwithGear(Gear,-1) = 0) and
       
   630        (TestCollisionXwithGear(Gear, 1) = 0) and
       
   631        (TestCollisionXwithGear(Gear,-1) = 0) and
       
   632        (TestCollisionYwithGear(Gear, 1) = 0) then
       
   633         begin
       
   634         t:= 0;
       
   635         h:= 0;
       
   636         while (t < TeamsCount) and (p = 0) do
       
   637             begin
       
   638             with TeamsArray[t]^ do
       
   639                 while (h < cMaxHHIndex) and (p = 0) do
       
   640                     begin
       
   641                     if (Hedgehogs[h].Gear <> nil) then
       
   642                         begin
       
   643                         rdx:=Gear^.X-Hedgehogs[h].Gear^.X;
       
   644                         rdy:=Gear^.Y-Hedgehogs[h].Gear^.Y;
       
   645                         if (Gear^.Angle < $FFFFFFFF) and
       
   646                             ((rdx.Round+rdy.Round < Gear^.Angle) and
       
   647                             (hwRound(hwSqr(rdx) + hwSqr(rdy)) < sqr(Gear^.Angle))) then
       
   648                             begin
       
   649 // Debug line. Remove later
       
   650 AddFileLog('Too Close to Hog @ (' + inttostr(rx) + ',' + inttostr(ry) + ')');
       
   651 
       
   652                             p:= 1
       
   653                             end
       
   654                         end;
       
   655                     inc(h)
       
   656                     end;
       
   657             inc(t)
       
   658             end;
       
   659         if p = 0 then
       
   660             begin
       
   661             inc(i);
       
   662             AddFileLog('Placed Air Mine @ (' + inttostr(rx) + ',' + inttostr(ry) + ')');
       
   663             if i < cAirMines then
       
   664                 Gear:= AddGear(0, 0, gtAirMine, 0, _0, _0, 0)
       
   665             end
       
   666         end;
       
   667     inc(j)
       
   668     end;
       
   669 if p <> 0 then DeleteGear(Gear);
   606 
   670 
   607 if (GameFlags and gfLowGravity) <> 0 then
   671 if (GameFlags and gfLowGravity) <> 0 then
   608     begin
   672     begin
   609     cGravity:= cMaxWindSpeed;
   673     cGravity:= cMaxWindSpeed;
   610     cGravityf:= 0.00025
   674     cGravityf:= 0.00025