hedgewars/uGears.pas
branchwebgl
changeset 9950 2759212a27de
parent 9521 8054d9d775fd
parent 9818 ff07ac765f45
child 9954 bf51bc7e2808
equal deleted inserted replaced
9521:8054d9d775fd 9950:2759212a27de
    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;
    36 uses uConsts, uFloat, uTypes, uChat;
    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;
    45 procedure FreeGearsList;
    45 procedure FreeGearsList;
    46 procedure AddMiscGears;
    46 procedure AddMiscGears;
    47 procedure AssignHHCoords;
    47 procedure AssignHHCoords;
    48 function  GearByUID(uid : Longword) : PGear;
    48 function  GearByUID(uid : Longword) : PGear;
    49 implementation
    49 implementation
    50 uses uStore, uSound, uTeams, uRandom, uIO, uLandGraphics, {$IFDEF SDL2}uTouch,{$ENDIF}
    50 uses uStore, uSound, uTeams, uRandom, uIO, uLandGraphics,
       
    51     {$IFDEF USE_TOUCH_INTERFACE}uTouch,{$ENDIF}
    51     uLocale, uAmmos, uStats, uVisualGears, uScript, uVariables,
    52     uLocale, uAmmos, uStats, uVisualGears, uScript, uVariables,
    52     uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
    53     uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
    53     uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlersRope
    54     uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlersRope
    54     , uVisualGearsList, uGearsHandlersMess, uAI;
    55     , uVisualGearsList, uGearsHandlersMess, uAI;
    55 
    56 
    74     if (Gear^.Kind = gtHedgehog) and (((GameFlags and gfInfAttack) = 0) or ((Gear^.dX.QWordValue < _0_000004.QWordValue)
    75     if (Gear^.Kind = gtHedgehog) and (((GameFlags and gfInfAttack) = 0) or ((Gear^.dX.QWordValue < _0_000004.QWordValue)
    75     and (Gear^.dY.QWordValue < _0_000004.QWordValue))) then
    76     and (Gear^.dY.QWordValue < _0_000004.QWordValue))) then
    76         begin
    77         begin
    77         if (not isInMultiShoot) then
    78         if (not isInMultiShoot) then
    78             inc(Gear^.Damage, Gear^.Karma);
    79             inc(Gear^.Damage, Gear^.Karma);
    79         if ((Gear^.Damage <> 0) and (not Gear^.Invulnerable)) then
    80         if (Gear^.Damage <> 0) and ((Gear^.Hedgehog^.Effects[heInvulnerable] = 0)) then
    80             begin
    81             begin
    81             CheckNoDamage:= false;
    82             CheckNoDamage:= false;
    82 
    83 
    83             dmg:= Gear^.Damage;
    84             dmg:= Gear^.Damage;
    84             if Gear^.Health < dmg then
    85             if Gear^.Health < dmg then
   163 
   164 
   164 procedure ProcessGears;
   165 procedure ProcessGears;
   165 var t: PGear;
   166 var t: PGear;
   166     i, AliveCount: LongInt;
   167     i, AliveCount: LongInt;
   167     s: shortstring;
   168     s: shortstring;
   168 begin
   169     prevtime: LongWord;
       
   170 begin
       
   171 prevtime:= TurnTimeLeft;
   169 ScriptCall('onGameTick');
   172 ScriptCall('onGameTick');
   170 if GameTicks mod 20 = 0 then ScriptCall('onGameTick20');
   173 if GameTicks mod 20 = 0 then ScriptCall('onGameTick20');
   171 if GameTicks = NewTurnTick then
   174 if GameTicks = NewTurnTick then
   172     begin
   175     begin
   173     ScriptCall('onNewTurn');
   176     ScriptCall('onNewTurn');
   174 {$IFDEF SDL2}
   177 {$IFDEF USE_TOUCH_INTERFACE}
   175     uTouch.NewTurnBeginning();
   178     uTouch.NewTurnBeginning();
   176 {$ENDIF}
   179 {$ENDIF}
   177     end;
   180     end;
   178 
   181 
   179 PrvInactive:= AllInactive;
   182 PrvInactive:= AllInactive;
   417         end
   420         end
   418     end;
   421     end;
   419 
   422 
   420 if TurnTimeLeft > 0 then
   423 if TurnTimeLeft > 0 then
   421     if CurrentHedgehog^.Gear <> nil then
   424     if CurrentHedgehog^.Gear <> nil then
   422         if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) and
   425         if (((CurrentHedgehog^.Gear^.State and gstAttacking) = 0)
   423             (not (isInMultiShoot and (CurrentHedgehog^.CurAmmoType in [amShotgun, amDEagle, amSniperRifle]))) then
   426             or (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_DoesntStopTimerWhileAttacking <> 0))
       
   427             and not(isInMultiShoot and ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_DoesntStopTimerInMultiShoot) <> 0)) then
       
   428             //(CurrentHedgehog^.CurAmmoType in [amShotgun, amDEagle, amSniperRifle])
   424                 begin
   429                 begin
   425                 if (TurnTimeLeft = 5000)
   430                 if (TurnTimeLeft = 5000)
   426                 and (cHedgehogTurnTime >= 10000)
   431                 and (cHedgehogTurnTime >= 10000)
   427                 and (not PlacingHogs)
   432                 and (not PlacingHogs)
   428                 and (CurrentHedgehog^.Gear <> nil)
   433                 and (CurrentHedgehog^.Gear <> nil)
   457 
   462 
   458     if (not CurrentTeam^.ExtDriven) or CurrentTeam^.hasGone then
   463     if (not CurrentTeam^.ExtDriven) or CurrentTeam^.hasGone then
   459         inc(hiTicks) // we do not recieve a message for this
   464         inc(hiTicks) // we do not recieve a message for this
   460     end;
   465     end;
   461 AddRandomness(CheckSum);
   466 AddRandomness(CheckSum);
   462 
   467 TurnClockActive:= prevtime <> TurnTimeLeft;
   463 inc(GameTicks)
   468 inc(GameTicks)
   464 end;
   469 end;
   465 
   470 
   466 //Purpose, to reset all transient attributes toggled by a utility and clean up various gears and effects at end of turn
   471 //Purpose, to reset all transient attributes toggled by a utility and clean up various gears and effects at end of turn
   467 //If any of these are set as permanent toggles in the frontend, that needs to be checked and skipped here.
   472 //If any of these are set as permanent toggles in the frontend, that needs to be checked and skipped here.
   502 *)
   507 *)
   503 
   508 
   504                     if (Gear <> nil) then
   509                     if (Gear <> nil) then
   505                         begin
   510                         begin
   506                         if (GameFlags and gfInvulnerable) = 0 then
   511                         if (GameFlags and gfInvulnerable) = 0 then
   507                             Gear^.Invulnerable:= false;
   512                             Gear^.Hedgehog^.Effects[heInvulnerable]:= 0;
   508                         end;
   513                         end;
   509                     end;
   514                     end;
   510     t:= GearsList;
   515     t:= GearsList;
   511     while t <> nil do
   516     while t <> nil do
   512         begin
   517         begin
   556         Dispose(t)
   561         Dispose(t)
   557     end;
   562     end;
   558 end;
   563 end;
   559 
   564 
   560 procedure AddMiscGears;
   565 procedure AddMiscGears;
   561 var i,rx, ry: Longword;
   566 var p,i,j,rx, ry: Longword;
   562     rdx, rdy: hwFloat;
   567     rdx, rdy: hwFloat;
   563     Gear: PGear;
   568     Gear: PGear;
   564     temp: Longword;
   569     temp: Longword;
   565 begin
   570 begin
   566 AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000);
   571 AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000);
   592 if (GameFlags and gfVampiric) <> 0 then
   597 if (GameFlags and gfVampiric) <> 0 then
   593     cVampiric:= true;
   598     cVampiric:= true;
   594 
   599 
   595 Gear:= GearsList;
   600 Gear:= GearsList;
   596 if (GameFlags and gfInvulnerable) <> 0 then
   601 if (GameFlags and gfInvulnerable) <> 0 then
   597     while Gear <> nil do
   602     for p:= 0 to Pred(ClansCount) do
   598         begin
   603         with ClansArray[p]^ do
   599         Gear^.Invulnerable:= true;  // this is only checked on hogs right now, so no need for gear type check
   604             for j:= 0 to Pred(TeamsNumber) do
   600         Gear:= Gear^.NextGear
   605                 with Teams[j]^ do
   601         end;
   606                     for i:= 0 to cMaxHHIndex do
       
   607                         with Hedgehogs[i] do
       
   608                             Effects[heInvulnerable]:= 1;
   602 
   609 
   603 if (GameFlags and gfLaserSight) <> 0 then
   610 if (GameFlags and gfLaserSight) <> 0 then
   604     cLaserSighting:= true;
   611     cLaserSighting:= true;
   605 
   612 
   606 if (GameFlags and gfArtillery) <> 0 then
   613 if (GameFlags and gfArtillery) <> 0 then
   615     end;
   622     end;
   616 
   623 
   617 snowRight:= max(LAND_WIDTH,4096)+512;
   624 snowRight:= max(LAND_WIDTH,4096)+512;
   618 snowLeft:= -(snowRight-LAND_WIDTH);
   625 snowLeft:= -(snowRight-LAND_WIDTH);
   619 
   626 
   620 if (not hasBorder) and ((Theme = 'Snow') or (Theme = 'Christmas')) then
   627 if (not hasBorder) and cSnow then
   621     for i:= vobCount * Longword(max(LAND_WIDTH,4096)) div 2048 downto 1 do
   628     for i:= vobCount * Longword(max(LAND_WIDTH,4096)) div 2048 downto 1 do
   622         AddGear(LongInt(GetRandom(snowRight - snowLeft)) + snowLeft, LAND_HEIGHT + LongInt(GetRandom(750)) - 1300, gtFlake, 0, _0, _0, 0);
   629         AddGear(LongInt(GetRandom(snowRight - snowLeft)) + snowLeft, LAND_HEIGHT + LongInt(GetRandom(750)) - 1300, gtFlake, 0, _0, _0, 0);
   623 end;
   630 end;
   624 
   631 
   625 procedure AssignHHCoords;
   632 procedure AssignHHCoords;
   838         text:= copy(s, 4, Length(s) - 1)
   845         text:= copy(s, 4, Length(s) - 1)
   839     else if x < 4 then
   846     else if x < 4 then
   840         text:= copy(s, 3, Length(s) - 1)
   847         text:= copy(s, 3, Length(s) - 1)
   841     else text:= copy(s, 2, Length(s) - 1);
   848     else text:= copy(s, 2, Length(s) - 1);
   842 
   849 
       
   850     if text = '' then text:= '...';
       
   851 
   843     (*
   852     (*
   844     if CheckNoTeamOrHH then
   853     if CheckNoTeamOrHH then
   845         begin
   854         begin
   846         ParseCommand('say ' + text, true);
   855         ParseCommand('say ' + text, true);
   847         exit
   856         exit
   875             if Gear <> nil then
   884             if Gear <> nil then
   876                 begin
   885                 begin
   877                 Gear^.Hedgehog:= hh;
   886                 Gear^.Hedgehog:= hh;
   878                 Gear^.Text:= text;
   887                 Gear^.Text:= text;
   879                 Gear^.FrameTicks:= x
   888                 Gear^.FrameTicks:= x
   880                 end
   889                 end;
       
   890             //ParseCommand('/say [' + hh^.Name + '] '+text, true)
       
   891             AddChatString(#1+'[' + HH^.Name + '] '+text);
   881             end
   892             end
   882         //else ParseCommand('say ' + text, true)
       
   883         end
   893         end
   884     else if (x >= 4) then
   894     else if (x >= 4) then
   885         begin
   895         begin
   886         SpeechType:= x-3;
   896         SpeechType:= x-3;
   887         SpeechText:= text
   897         SpeechText:= text