hedgewars/uGearsHandlers.pas
author sheepluva
Tue, 04 Sep 2012 13:18:26 +0200
changeset 7669 a85e1c167b69
parent 7416 2f2f78fc65a3
child 7671 43f38923bc6e
permissions -rw-r--r--
I didn't want to do this since it seems less clean, but... moving the stats-fix into CheckForWin, since that function is the one sending the damage stats (whyyyy?) therefore it's not sufficient to update stats after calling it, some of the stats won't be transfered to frontend then
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     1
(*
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     4
 *
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     8
 *
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    13
 *
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    17
 *)
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    18
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    20
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    21
unit uGearsHandlers;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    22
interface
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    23
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    24
uses uTypes;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    25
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    26
procedure cakeStep(Gear: PGear);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    27
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    28
implementation
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    29
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    30
uses SDLh, uFloat, uCollisions;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    31
7398
2b7b939014b5 Start TestCake
unc0rr
parents: 7370
diff changeset
    32
2b7b939014b5 Start TestCake
unc0rr
parents: 7370
diff changeset
    33
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    34
const dirs: array[0..3] of TPoint =   ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0));
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    35
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    36
procedure PrevAngle(Gear: PGear; dA: LongInt); inline;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    37
begin
7405
63f56edae4c6 Replace stupid 'mod' with 'and'
unc0rr
parents: 7402
diff changeset
    38
    Gear^.Angle := (Gear^.Angle - dA) and 3
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    39
end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    40
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    41
procedure NextAngle(Gear: PGear; dA: LongInt); inline;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    42
begin
7405
63f56edae4c6 Replace stupid 'mod' with 'and'
unc0rr
parents: 7402
diff changeset
    43
    Gear^.Angle := (Gear^.Angle + dA) and 3
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    44
end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    45
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    46
procedure cakeStep(Gear: PGear);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    47
var
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    48
    xx, yy, xxn, yyn: LongInt;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    49
    dA: LongInt;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    50
    tdx, tdy: hwFloat;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    51
begin
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    52
    dA := hwSign(Gear^.dX);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    53
    xx := dirs[Gear^.Angle].x;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    54
    yy := dirs[Gear^.Angle].y;
7416
2f2f78fc65a3 AI uses cake! Known issues: AI could damage itself for no reason, could let cake go looping in a hole with exit closed by AI hog.
unc0rr
parents: 7405
diff changeset
    55
    xxn := dirs[(Gear^.Angle + dA) and 3].x;
2f2f78fc65a3 AI uses cake! Known issues: AI could damage itself for no reason, could let cake go looping in a hole with exit closed by AI hog.
unc0rr
parents: 7405
diff changeset
    56
    yyn := dirs[(Gear^.Angle + dA) and 3].y;
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    57
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    58
    if (xx = 0) then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    59
        if TestCollisionYwithGear(Gear, yy) <> 0 then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    60
            PrevAngle(Gear, dA)
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    61
    else
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    62
        begin
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    63
        Gear^.Tag := 0;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    64
        Gear^.Y := Gear^.Y + int2hwFloat(yy);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    65
        if not TestCollisionXwithGear(Gear, xxn) then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    66
            begin
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    67
            Gear^.X := Gear^.X + int2hwFloat(xxn);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    68
            NextAngle(Gear, dA)
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    69
            end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    70
        end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    71
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    72
    if (yy = 0) then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    73
        if TestCollisionXwithGear(Gear, xx) then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    74
            PrevAngle(Gear, dA)
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    75
    else
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    76
        begin
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    77
        Gear^.Tag := 0;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    78
        Gear^.X := Gear^.X + int2hwFloat(xx);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    79
        if TestCollisionYwithGear(Gear, yyn) = 0 then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    80
            begin
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    81
            Gear^.Y := Gear^.Y + int2hwFloat(yyn);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    82
            NextAngle(Gear, dA)
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    83
            end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    84
        end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    85
end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    86
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    87
end.