4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* Distributed under the terms of the BSD-modified licence:
|
|
6 |
*
|
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 |
* of this software and associated documentation files (the "Software"), to deal
|
|
9 |
* with the Software without restriction, including without limitation the
|
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
12 |
* furnished to do so, subject to the following conditions:
|
|
13 |
*
|
|
14 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
15 |
* this list of conditions and the following disclaimer.
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17 |
* this list of conditions and the following disclaimer in the documentation
|
|
18 |
* and/or other materials provided with the distribution.
|
|
19 |
* 3. The name of the author may not be used to endorse or promote products
|
|
20 |
* derived from this software without specific prior written permission.
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32 |
*)
|
|
33 |
|
|
34 |
unit uMisc;
|
|
35 |
interface
|
|
36 |
uses uConsts, SDLh;
|
|
37 |
{$INCLUDE options.inc}
|
|
38 |
var isCursorVisible : boolean = false;
|
|
39 |
isTerminated : boolean = false;
|
|
40 |
isInLag : boolean = false;
|
|
41 |
isSoundEnabled : boolean = true;
|
|
42 |
isInMultiShoot : boolean = false;
|
|
43 |
|
|
44 |
GameState : TGameState = gsLandGen;
|
|
45 |
GameType : TGameType = gmtLocal;
|
|
46 |
GameFlags : Longword = 0;
|
|
47 |
TurnTimeLeft : Longword = 0;
|
|
48 |
cHedgehogTurnTime: Longword = 30000;
|
|
49 |
|
|
50 |
cLandYShift : integer = 888;
|
|
51 |
cCloudsNumber : integer = 9;
|
|
52 |
cConsoleHeight : integer = 320;
|
|
53 |
cConsoleYAdd : integer = 0;
|
|
54 |
cTimerInterval : Cardinal = 15;
|
|
55 |
cScreenWidth : integer = 1024;
|
|
56 |
cScreenHeight : integer = 768;
|
|
57 |
cBits : integer = 16;
|
|
58 |
cWaterLine : integer = 1024;
|
|
59 |
cVisibleWater : integer = 64;
|
|
60 |
cScreenEdgesDist : integer = 240;
|
|
61 |
|
|
62 |
GameTicks : LongWord = 0;
|
|
63 |
|
|
64 |
cSkyColor : Cardinal = 0;
|
|
65 |
cWaterColor : Cardinal = $32397A;
|
|
66 |
cMapBackColor : Cardinal = $FFFFFF;
|
|
67 |
cWhiteColor : Cardinal = $FFFFFF;
|
|
68 |
cConsoleSplitterColor : Cardinal = $FF0000;
|
|
69 |
cColorNearBlack : Cardinal = 16;
|
|
70 |
cExplosionBorderColor : LongWord = $808080;
|
|
71 |
|
|
72 |
cDrownSpeed : Real = 0.06;
|
|
73 |
cMaxWindSpeed : Real = 0.0003;
|
|
74 |
cWindSpeed : Real = 0.0001;
|
|
75 |
cGravity : Real = 0.0005;
|
|
76 |
|
|
77 |
cShowFPS : boolean = true;
|
|
78 |
cFullScreen : boolean = true;
|
|
79 |
|
|
80 |
const
|
|
81 |
cMaxPower = 1500;
|
|
82 |
cMaxAngle = 2048;
|
|
83 |
cPowerDivisor = 1500;
|
|
84 |
|
|
85 |
var
|
|
86 |
cSendEmptyPacketTime : LongWord = 2000;
|
|
87 |
cSendCursorPosTime : LongWord = 50;
|
13
|
88 |
ShowCrosshair : boolean;
|
4
|
89 |
|
|
90 |
flagMakeCapture: boolean = false;
|
|
91 |
|
|
92 |
AttackBar : integer = 0; // 0 - îòñóòñòâóåò, 1 - âíèçó, 2 - êàê â wwp
|
|
93 |
|
|
94 |
function Sign(r: real): integer;
|
|
95 |
function Min(a, b: integer): integer;
|
|
96 |
function Max(a, b: integer): integer;
|
|
97 |
procedure OutError(Msg: String; const isFatalError: boolean=false);
|
|
98 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean);
|
|
99 |
procedure SDLTry(Assert: boolean; isFatal: boolean);
|
|
100 |
function IntToStr(n: integer): shortstring;
|
|
101 |
function FloatToStr(n: real): shortstring;
|
|
102 |
function arctan(const Y, X: real): real;
|
|
103 |
function DxDy2Angle32(const _dY, _dX: Extended): integer;
|
|
104 |
procedure AdjustColor(var Color: Longword);
|
|
105 |
{$IFDEF DEBUGFILE}
|
|
106 |
procedure AddFileLog(s: shortstring);
|
|
107 |
{$ENDIF}
|
|
108 |
|
|
109 |
var CursorPoint: TPoint;
|
|
110 |
TargetPoint: TPoint = (X: NoPointX; Y: 0);
|
|
111 |
|
|
112 |
implementation
|
|
113 |
uses uConsole, uStore;
|
|
114 |
{$IFDEF DEBUGFILE}
|
|
115 |
var f: textfile;
|
|
116 |
{$ENDIF}
|
|
117 |
|
|
118 |
|
|
119 |
function Sign(r: real): integer;
|
|
120 |
begin
|
|
121 |
if r < 0 then Result:= -1 else Result:= 1
|
|
122 |
end;
|
|
123 |
|
|
124 |
function Min(a, b: integer): integer;
|
|
125 |
begin
|
|
126 |
if a < b then Result:= a else Result:= b
|
|
127 |
end;
|
|
128 |
|
|
129 |
function Max(a, b: integer): integer;
|
|
130 |
begin
|
|
131 |
if a > b then Result:= a else Result:= b
|
|
132 |
end;
|
|
133 |
|
|
134 |
procedure OutError(Msg: String; const isFatalError: boolean=false);
|
|
135 |
begin
|
|
136 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF}
|
|
137 |
if isFatalError then
|
|
138 |
begin
|
|
139 |
WriteLn(Msg);
|
|
140 |
SDL_Quit;
|
|
141 |
Readln;
|
|
142 |
halt(1)
|
|
143 |
end else WriteLnToConsole(Msg)
|
|
144 |
end;
|
|
145 |
|
|
146 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean);
|
|
147 |
begin
|
|
148 |
if not Assert then OutError(msg, isFatal)
|
|
149 |
end;
|
|
150 |
|
|
151 |
procedure SDLTry(Assert: boolean; isFatal: boolean);
|
|
152 |
begin
|
|
153 |
if not Assert then OutError(SDL_GetError, isFatal)
|
|
154 |
end;
|
|
155 |
|
|
156 |
procedure AdjustColor(var Color: Cardinal);
|
|
157 |
begin
|
|
158 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF)
|
|
159 |
end;
|
|
160 |
|
|
161 |
function IntToStr(n: integer): shortstring;
|
|
162 |
begin
|
|
163 |
str(n, Result)
|
|
164 |
end;
|
|
165 |
|
|
166 |
function FloatToStr(n: real): shortstring;
|
|
167 |
begin
|
|
168 |
str(n, Result)
|
|
169 |
end;
|
|
170 |
|
|
171 |
function arctan(const Y, X: real): real;
|
|
172 |
asm
|
|
173 |
fld Y
|
|
174 |
fld X
|
|
175 |
fpatan
|
|
176 |
fwait
|
|
177 |
end;
|
|
178 |
|
|
179 |
function DxDy2Angle32(const _dY, _dX: Extended): integer;
|
|
180 |
const piDIV32: Extended = pi/32;
|
|
181 |
asm
|
|
182 |
fld _dY
|
|
183 |
fld _dX
|
|
184 |
fpatan
|
|
185 |
fld piDIV32
|
|
186 |
fdiv
|
|
187 |
sub esp, 4
|
|
188 |
fistp dword ptr [esp]
|
|
189 |
pop eax
|
|
190 |
shr eax, 1
|
|
191 |
and eax, $1F
|
|
192 |
end;
|
|
193 |
|
|
194 |
|
|
195 |
{$IFDEF DEBUGFILE}
|
|
196 |
procedure AddFileLog(s: shortstring);
|
|
197 |
begin
|
|
198 |
writeln(f, GameTicks: 6, ': ', s);
|
|
199 |
flush(f)
|
|
200 |
end;
|
|
201 |
|
|
202 |
initialization
|
|
203 |
assignfile(f, 'debug.txt');
|
|
204 |
rewrite(f);
|
17
|
205 |
|
4
|
206 |
finalization
|
|
207 |
writeln(f, '-= halt at ',GameTicks,' ticks =-');
|
|
208 |
Flush(f);
|
|
209 |
closefile(f)
|
|
210 |
{$ENDIF}
|
|
211 |
|
|
212 |
end.
|