hedgewars/uGearsUtils.pas
author lovelacer
Tue, 17 Jan 2012 09:01:31 -0500
changeset 6580 6155187bf599
parent 6543 697e9b730189
child 6581 e510d1245bd7
permissions -rw-r--r--
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent. Some switch statements (uVisualGears.pas) are not lined up on the : so the internal code blocks are not aligned (lined up on the start of the label instead). Some function contents are indented against begin/end of function, some are not, some function begin/end are themselves indented (adler32). Also inconsistency in things like assigning of variables (whitespace before :=) and use of brackets in tests. Probably needs further review for possible code errors.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     1
(*
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     4
 *
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     8
 *
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    13
 *
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    17
 *)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    18
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    20
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    21
unit uGearsUtils;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    22
interface
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    23
uses uTypes;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    24
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    25
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    26
function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    27
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    28
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    29
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    30
procedure CheckHHDamage(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    31
procedure CalcRotationDirAngle(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    32
procedure ResurrectHedgehog(gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    33
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean = false);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    34
function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    35
function  CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
6543
697e9b730189 Fix build
unc0rr
parents: 6531
diff changeset
    36
function  CheckGearDrowning(Gear: PGear): boolean;
697e9b730189 Fix build
unc0rr
parents: 6531
diff changeset
    37
697e9b730189 Fix build
unc0rr
parents: 6531
diff changeset
    38
var doStepHandlers: array[TGearType] of TGearStepProcedure;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    39
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    40
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    41
implementation
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    42
uses uFloat, uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc,
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    43
    uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore,
6543
697e9b730189 Fix build
unc0rr
parents: 6531
diff changeset
    44
    uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, uGears,
697e9b730189 Fix build
unc0rr
parents: 6531
diff changeset
    45
    uGearsList;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    46
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    47
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    48
var Gear: PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    49
    dmg, dmgRadius, dmgBase: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    50
    fX, fY: hwFloat;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    51
    vg: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    52
    i, cnt: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    53
begin
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    54
if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    55
if Radius > 25 then KickFlakes(Radius, X, Y);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    56
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    57
if ((Mask and EXPLNoGfx) = 0) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    58
    begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    59
    vg:= nil;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    60
    if Radius > 50 then vg:= AddVisualGear(X, Y, vgtBigExplosion)
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    61
    else if Radius > 10 then vg:= AddVisualGear(X, Y, vgtExplosion);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    62
    if vg <> nil then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    63
        vg^.Tint:= Tint;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    64
    end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    65
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion);
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    66
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    67
if (Mask and EXPLAllDamageInRadius) = 0 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    68
    dmgRadius:= Radius shl 1
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    69
else
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    70
    dmgRadius:= Radius;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    71
dmgBase:= dmgRadius + cHHRadius div 2;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    72
fX:= int2hwFloat(X);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    73
fY:= int2hwFloat(Y);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    74
Gear:= GearsList;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    75
while Gear <> nil do
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    76
    begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    77
    dmg:= 0;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    78
    //dmg:= dmgRadius  + cHHRadius div 2 - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    79
    //if (dmg > 1) and
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    80
    if (Gear^.State and gstNoDamage) = 0 then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
    81
        begin
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    82
        case Gear^.Kind of
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    83
            gtHedgehog,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    84
                gtMine,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    85
                gtBall,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    86
                gtMelonPiece,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    87
                gtGrenade,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    88
                gtClusterBomb,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    89
            //    gtCluster, too game breaking I think
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    90
                gtSMine,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    91
                gtCase,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    92
                gtTarget,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    93
                gtFlame,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    94
                gtExplosives,
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    95
                gtStructure: begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    96
// Run the calcs only once we know we have a type that will need damage
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    97
                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    98
                            dmg:= dmgBase - max(hwRound(Distance(Gear^.X - fX, Gear^.Y - fY)),Gear^.Radius);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
    99
                        if dmg > 1 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   100
                            begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   101
                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   102
                            //AddFileLog('Damage: ' + inttostr(dmg));
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   103
                            if (Mask and EXPLNoDamage) = 0 then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   104
                                begin
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   105
                                if not Gear^.Invulnerable then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   106
                                    ApplyDamage(Gear, AttackingHog, dmg, dsExplosion)
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   107
                                else
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   108
                                    Gear^.State:= Gear^.State or gstWinner;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   109
                                end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   110
                            if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   111
                                begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   112
                                DeleteCI(Gear);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   113
                                Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - fX)/(Gear^.Density/_3);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   114
                                Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - fY)/(Gear^.Density/_3);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   115
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   116
                                Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   117
                                if not Gear^.Invulnerable then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   118
                                    Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   119
                                Gear^.Active:= true;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   120
                                if Gear^.Kind <> gtFlame then FollowGear:= Gear
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   121
                                end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   122
                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (not Gear^.Invulnerable) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   123
                                Gear^.Hedgehog^.Effects[hePoisoned] := true;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   124
                            end;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   125
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   126
                        end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   127
                gtGrave: begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   128
// Run the calcs only once we know we have a type that will need damage
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   129
                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   130
                            dmg:= dmgBase - hwRound(Distance(Gear^.X - fX, Gear^.Y - fY));
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   131
                        if dmg > 1 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   132
                            begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   133
                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   134
                            Gear^.dY:= - _0_004 * dmg;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   135
                            Gear^.Active:= true
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   136
                            end
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   137
                        end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   138
            end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   139
        end;
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   140
    Gear:= Gear^.NextGear
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   141
    end;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   142
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   143
if (Mask and EXPLDontDraw) = 0 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   144
    if (GameFlags and gfSolidLand) = 0 then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   145
        begin
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   146
        cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   147
        if (cnt > 0) and (SpritesData[sprChunk].Texture <> nil) then
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   148
            for i:= 0 to cnt do
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   149
                AddVisualGear(X, Y, vgtChunk)
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   150
        end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   151
6531
c938a35588af Remove density adjustment in ammoshove. Means a mine and a barrel will be batted same distance again.
nemo
parents: 6498
diff changeset
   152
uAIMisc.AwareOfExplosion(0, 0, 0)
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   153
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   154
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   155
function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   156
var i: hwFloat;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   157
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   158
(* Invulnerability cannot be placed in here due to still needing kicks
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   159
   Not without a new damage machine.
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   160
   King check should be in here instead of ApplyDamage since Tiy wants them kicked less
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   161
*)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   162
i:= _1;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   163
if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   164
    i:= _1_5;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   165
if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.King) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   166
    ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent * _0_5)
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   167
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   168
    ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent)
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   169
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   170
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   171
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   172
var s: shortstring;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   173
    vampDmg, tmpDmg, i: Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   174
    vg: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   175
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   176
    if Damage = 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   177
        exit; // nothing to apply
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   178
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   179
    if (Gear^.Kind = gtHedgehog) then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   180
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   181
        Gear^.LastDamage := AttackerHog;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   182
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   183
        Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   184
        HHHurt(Gear^.Hedgehog, Source);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   185
        AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   186
        tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   187
        if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   188
            begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   189
            if cVampiric then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   190
                begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   191
                vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   192
                if vampDmg >= 1 then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   193
                    begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   194
                    // was considering pulsing on attack, Tiy thinks it should be permanent while in play
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   195
                    //CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   196
                    inc(CurrentHedgehog^.Gear^.Health,vampDmg);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   197
                    str(vampDmg, s);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   198
                    s:= '+' + s;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   199
                    AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   200
                    RenderHealth(CurrentHedgehog^);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   201
                    RecountTeamHealth(CurrentHedgehog^.Team);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   202
                    i:= 0;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   203
                    while i < vampDmg do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   204
                        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   205
                        vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   206
                        if vg <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   207
                            with vg^ do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   208
                                begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   209
                                Tint:= $FF0000FF;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   210
                                State:= ord(sprHealth)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   211
                                end;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   212
                        inc(i, 5);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   213
                        end;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   214
                    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   215
                end;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   216
        if ((GameFlags and gfKarma) <> 0) and 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   217
        ((GameFlags and gfInvulnerable) = 0)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   218
        and (not CurrentHedgehog^.Gear^.Invulnerable) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   219
            begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   220
            inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   221
            CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   222
            spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   223
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   224
        uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   225
        end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   226
    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   227
    else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   228
        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   229
        Gear^.Hedgehog:= AttackerHog;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   230
        end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   231
    inc(Gear^.Damage, Damage);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   232
    
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   233
    ScriptCall('onGearDamage', Gear^.UID, Damage);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   234
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   235
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   236
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   237
var tag: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   238
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   239
tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   240
if (tag <> nil) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   241
    tag^.Hedgehog:= HHGear^.Hedgehog; // the tag needs the tag to determine the text color
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   242
AllInactive:= false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   243
HHGear^.Active:= true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   244
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   245
    
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   246
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   247
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   248
if (Source = dsFall) or (Source = dsExplosion) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   249
    case random(3) of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   250
        0: PlaySound(sndOoff1, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   251
        1: PlaySound(sndOoff2, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   252
        2: PlaySound(sndOoff3, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   253
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   254
else if (Source = dsPoison) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   255
    case random(2) of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   256
        0: PlaySound(sndPoisonCough, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   257
        1: PlaySound(sndPoisonMoan, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   258
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   259
else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   260
    case random(4) of
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   261
        0: PlaySound(sndOw1, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   262
        1: PlaySound(sndOw2, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   263
        2: PlaySound(sndOw3, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   264
        3: PlaySound(sndOw4, Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   265
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   266
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   267
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   268
procedure CheckHHDamage(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   269
var 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   270
    dmg: Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   271
    i: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   272
    particle: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   273
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   274
    if _0_4 < Gear^.dY then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   275
        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   276
        dmg := ModifyDamage(1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70), Gear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   277
        PlaySound(sndBump);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   278
        if dmg < 1 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   279
            exit;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   280
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   281
        for i:= min(12, (3 + dmg div 10)) downto 0 do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   282
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   283
            particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   284
            if particle <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   285
                particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480);
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   286
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   287
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   288
        if (Gear^.Invulnerable) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   289
            exit;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   290
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   291
        //if _0_6 < Gear^.dY then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   292
        //    PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   293
        //else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   294
        //    PlaySound(sndOw1, Gear^.Hedgehog^.Team^.voicepack);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   295
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   296
        if Gear^.LastDamage <> nil then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   297
            ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall)
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   298
        else
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   299
            ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   300
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   301
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   302
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   303
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   304
procedure CalcRotationDirAngle(Gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   305
var 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   306
    dAngle: real;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   307
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   308
    dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   309
    if not Gear^.dX.isNegative then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   310
        Gear^.DirAngle := Gear^.DirAngle + dAngle
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   311
    else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   312
        Gear^.DirAngle := Gear^.DirAngle - dAngle;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   313
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   314
    if Gear^.DirAngle < 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   315
        Gear^.DirAngle := Gear^.DirAngle + 360
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   316
    else if 360 < Gear^.DirAngle then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   317
        Gear^.DirAngle := Gear^.DirAngle - 360
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   318
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   319
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   320
function CheckGearDrowning(Gear: PGear): boolean;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   321
var 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   322
    skipSpeed, skipAngle, skipDecay: hwFloat;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   323
    i, maxDrops, X, Y: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   324
    vdX, vdY: real;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   325
    particle: PVisualGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   326
    isSubmersible: boolean;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   327
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   328
    // probably needs tweaking. might need to be in a case statement based upon gear type
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   329
    Y:= hwRound(Gear^.Y);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   330
    if cWaterLine < Y + Gear^.Radius then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   331
        begin
6498
5678806aafca Some tiny optimizations
unc0rr
parents: 6490
diff changeset
   332
        isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   333
        skipSpeed := _0_25;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   334
        skipAngle := _1_9;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   335
        skipDecay := _0_87;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   336
        X:= hwRound(Gear^.X);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   337
        vdX:= hwFloat2Float(Gear^.dX);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   338
        vdY:= hwFloat2Float(Gear^.dY);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   339
        // this could perhaps be a tiny bit higher.
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   340
        if  (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   341
        and (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   342
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   343
            Gear^.dY.isNegative := true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   344
            Gear^.dY := Gear^.dY * skipDecay;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   345
            Gear^.dX := Gear^.dX * skipDecay;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   346
            CheckGearDrowning := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   347
            PlaySound(sndSkip)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   348
            end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   349
        else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   350
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   351
            if not isSubmersible then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   352
                begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   353
                CheckGearDrowning := true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   354
                Gear^.State := gstDrowning;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   355
                Gear^.RenderTimer := false;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   356
                if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   357
                and (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   358
                    if Gear^.Kind = gtHedgehog then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   359
                        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   360
                        if Gear^.Hedgehog^.Effects[heResurrectable] then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   361
                            ResurrectHedgehog(Gear)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   362
                        else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   363
                            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   364
                            Gear^.doStep := @doStepDrowningGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   365
                            Gear^.State := Gear^.State and (not gstHHDriven);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   366
                            AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   367
                            end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   368
                        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   369
                    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   370
                        Gear^.doStep := @doStepDrowningGear;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   371
                        if Gear^.Kind = gtFlake then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   372
                            exit // skip splashes 
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   373
                end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   374
            if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius))
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   375
            or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   376
            and (CurAmmoGear^.dY < _0_01))) then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   377
                // don't play splash if they are already way past the surface
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   378
                PlaySound(sndSplash)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   379
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   380
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   381
        if ((cReducedQuality and rqPlainSplash) = 0)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   382
        and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius))
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   383
        or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   384
        and (CurAmmoGear^.dY < _0_01)))) then
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   385
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   386
            AddVisualGear(X, cWaterLine, vgtSplash);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   387
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   388
            maxDrops := (Gear^.Radius div 2) + round(vdX * Gear^.Radius * 2) + round(vdY * Gear^.Radius * 2);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   389
            for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   390
                begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   391
                particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   392
                if particle <> nil then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   393
                    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   394
                    particle^.dX := particle^.dX - vdX / 10;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   395
                    particle^.dY := particle^.dY - vdY / 5;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   396
                    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   397
                end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   398
            end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   399
        if isSubmersible and (CurAmmoGear^.Pos = 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   400
            CurAmmoGear^.Pos := 1000
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   401
        end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   402
    else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   403
        CheckGearDrowning := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   404
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   405
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   406
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   407
procedure ResurrectHedgehog(gear: PGear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   408
var tempTeam : PTeam;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   409
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   410
    AttackBar:= 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   411
    gear^.dX := _0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   412
    gear^.dY := _0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   413
    gear^.Damage := 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   414
    gear^.Health := gear^.Hedgehog^.InitialHealth;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   415
    gear^.Hedgehog^.Effects[hePoisoned] := false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   416
    if not CurrentHedgehog^.Effects[heResurrectable] then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   417
        with CurrentHedgehog^ do 
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   418
            begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   419
            inc(Team^.stats.AIKills);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   420
            FreeTexture(Team^.AIKillsTex);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   421
            Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   422
            end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   423
    tempTeam := gear^.Hedgehog^.Team;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   424
    DeleteCI(gear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   425
    FindPlace(gear, false, 0, LAND_WIDTH, true); 
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   426
    if gear <> nil then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   427
        begin
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   428
        RenderHealth(gear^.Hedgehog^);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   429
        ScriptCall('onGearResurrect', gear^.uid);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   430
        gear^.State := gstWait;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   431
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   432
    RecountTeamHealth(tempTeam);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   433
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   434
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   435
function CountNonZeroz(x, y, r, c: LongInt): LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   436
var i: LongInt;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   437
    count: LongInt = 0;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   438
begin
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   439
if (y and LAND_HEIGHT_MASK) = 0 then
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   440
    for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   441
        if Land[y, i] <> 0 then
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   442
            begin
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   443
            inc(count);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   444
            if count = c then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   445
                exit(count)
6490
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   446
            end;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   447
CountNonZeroz:= count;
531bf083e8db - Give uLand more modularity
unc0rr
parents: 6468
diff changeset
   448
end;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   449
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   450
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   451
var x: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   452
    y, sy: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   453
    ar: array[0..511] of TPoint;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   454
    ar2: array[0..1023] of TPoint;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   455
    cnt, cnt2: Longword;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   456
    delta: LongInt;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   457
    reallySkip, tryAgain: boolean;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   458
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   459
reallySkip:= false; // try not skipping proximity at first
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   460
tryAgain:= true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   461
while tryAgain do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   462
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   463
    delta:= 250;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   464
    cnt2:= 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   465
    repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   466
        x:= Left + LongInt(GetRandom(Delta));
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   467
        repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   468
            inc(x, Delta);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   469
            cnt:= 0;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   470
            y:= min(1024, topY) - 2 * Gear^.Radius;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   471
            while y < cWaterLine do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   472
                begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   473
                repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   474
                    inc(y, 2);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   475
                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   476
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   477
                sy:= y;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   478
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   479
                repeat
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   480
                    inc(y);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   481
                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   482
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   483
                if (y - sy > Gear^.Radius * 2)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   484
                    and (((Gear^.Kind = gtExplosives)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   485
                    and (y < cWaterLine)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   486
                    and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil))
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   487
                    and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius))
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   488
                or
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   489
                    ((Gear^.Kind <> gtExplosives)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   490
                    and (y < cWaterLine)
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   491
                    and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   492
                 
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   493
                          begin
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   494
                    ar[cnt].X:= x;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   495
                    if withFall then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   496
                        ar[cnt].Y:= sy + Gear^.Radius
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   497
                    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   498
                        ar[cnt].Y:= y - Gear^.Radius;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   499
                    inc(cnt)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   500
                    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   501
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   502
                inc(y, 45)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   503
                end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   504
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   505
            if cnt > 0 then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   506
                with ar[GetRandom(cnt)] do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   507
                    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   508
                    ar2[cnt2].x:= x;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   509
                    ar2[cnt2].y:= y;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   510
                    inc(cnt2)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   511
                    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   512
        until (x + Delta > Right);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   513
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   514
        dec(Delta, 60)
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   515
    until (cnt2 > 0) or (Delta < 70);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   516
    if (cnt2 = 0) and skipProximity and (not reallySkip) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   517
        tryAgain:= true
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   518
    else tryAgain:= false;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   519
    reallySkip:= true;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   520
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   521
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   522
if cnt2 > 0 then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   523
    with ar2[GetRandom(cnt2)] do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   524
        begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   525
        Gear^.X:= int2hwFloat(x);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   526
        Gear^.Y:= int2hwFloat(y);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   527
        AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   528
        end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   529
    else
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   530
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   531
    OutError('Can''t find place for Gear', false);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   532
    if Gear^.Kind = gtHedgehog then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6543
diff changeset
   533
        Gear^.Hedgehog^.Effects[heResurrectable] := false;
6468
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   534
    DeleteGear(Gear);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   535
    Gear:= nil
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   536
    end
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   537
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   538
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   539
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   540
var t: PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   541
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   542
t:= GearsList;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   543
rX:= sqr(rX);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   544
rY:= sqr(rY);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   545
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   546
while t <> nil do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   547
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   548
    if (t <> Gear) and (t^.Kind = Kind) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   549
        if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   550
        exit(t);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   551
    t:= t^.NextGear
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   552
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   553
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   554
CheckGearNear:= nil
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   555
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   556
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   557
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   558
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   559
var t: PGear;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   560
begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   561
t:= GearsList;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   562
rX:= sqr(rX);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   563
rY:= sqr(rY);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   564
while t <> nil do
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   565
    begin
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   566
    if t^.Kind in Kind then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   567
        if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   568
            exit(t);
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   569
    t:= t^.NextGear
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   570
    end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   571
CheckGearsNear:= nil
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   572
end;
da1e7fe7cff7 Start refactoring uGears. Breaks build.
unc0rr
parents:
diff changeset
   573
end.