author | unc0rr |
Wed, 13 Sep 2006 19:26:16 +0000 | |
changeset 144 | e6084b0c9316 |
parent 143 | 3dacbd83209b |
child 174 | 0b2c5b22f644 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
47 | 3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 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; |
|
72 | 42 |
isSEBackup : boolean = true; |
4 | 43 |
isInMultiShoot : boolean = false; |
44 |
||
39 | 45 |
GameState : TGameState = Low(TGameState); |
4 | 46 |
GameType : TGameType = gmtLocal; |
47 |
GameFlags : Longword = 0; |
|
48 |
TurnTimeLeft : Longword = 0; |
|
95 | 49 |
cHedgehogTurnTime: Longword = 45000; |
143 | 50 |
cMaxAIThinkTime : Longword = 5000; |
4 | 51 |
|
52 |
cCloudsNumber : integer = 9; |
|
53 |
cConsoleHeight : integer = 320; |
|
54 |
cConsoleYAdd : integer = 0; |
|
39 | 55 |
cTimerInterval : Cardinal = 5; |
4 | 56 |
cScreenWidth : integer = 1024; |
57 |
cScreenHeight : integer = 768; |
|
58 |
cBits : integer = 16; |
|
74 | 59 |
cBitsStr : string[2] = '16'; |
60 |
||
4 | 61 |
cWaterLine : integer = 1024; |
75 | 62 |
cVisibleWater : integer = 128; |
4 | 63 |
cScreenEdgesDist : integer = 240; |
47 | 64 |
cTeamHealthWidth : integer = 128; |
4 | 65 |
|
66 |
GameTicks : LongWord = 0; |
|
67 |
||
68 |
cSkyColor : Cardinal = 0; |
|
56 | 69 |
cWaterColor : Cardinal = $005ACE; |
4 | 70 |
cWhiteColor : Cardinal = $FFFFFF; |
71 |
cConsoleSplitterColor : Cardinal = $FF0000; |
|
72 |
cColorNearBlack : Cardinal = 16; |
|
73 |
cExplosionBorderColor : LongWord = $808080; |
|
74 |
||
108 | 75 |
cDrownSpeed : Double = 0.06; |
76 |
cMaxWindSpeed : Double = 0.0005; |
|
77 |
cWindSpeed : Double = 0.0001; |
|
78 |
cGravity : Double = 0.0005; |
|
4 | 79 |
|
80 |
cShowFPS : boolean = true; |
|
81 |
cFullScreen : boolean = true; |
|
80 | 82 |
cLocaleFName : shortstring = 'en.txt'; |
81 | 83 |
cSeed : shortstring = ''; |
4 | 84 |
|
85 |
const |
|
86 |
cMaxPower = 1500; |
|
87 |
cMaxAngle = 2048; |
|
88 |
cPowerDivisor = 1500; |
|
89 |
||
90 |
var |
|
91 |
cSendEmptyPacketTime : LongWord = 2000; |
|
92 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 93 |
ShowCrosshair : boolean; |
4 | 94 |
|
95 |
flagMakeCapture: boolean = false; |
|
96 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
97 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
98 |
|
79 | 99 |
AttackBar: integer = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 100 |
|
108 | 101 |
function hwSign(r: Double): integer; |
4 | 102 |
function Min(a, b: integer): integer; |
103 |
function Max(a, b: integer): integer; |
|
104 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
105 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
106 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
107 |
function IntToStr(n: integer): shortstring; |
|
107 | 108 |
function FloatToStr(n: Double): shortstring; |
4 | 109 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
100 | 110 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 111 |
procedure AdjustColor(var Color: Longword); |
112 |
{$IFDEF DEBUGFILE} |
|
113 |
procedure AddFileLog(s: shortstring); |
|
24 | 114 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 115 |
{$ENDIF} |
116 |
||
117 |
var CursorPoint: TPoint; |
|
118 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
119 |
||
120 |
implementation |
|
100 | 121 |
uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF}; |
4 | 122 |
{$IFDEF DEBUGFILE} |
123 |
var f: textfile; |
|
124 |
{$ENDIF} |
|
125 |
||
126 |
||
108 | 127 |
function hwSign(r: Double): integer; |
4 | 128 |
begin |
129 |
if r < 0 then Result:= -1 else Result:= 1 |
|
130 |
end; |
|
131 |
||
132 |
function Min(a, b: integer): integer; |
|
133 |
begin |
|
134 |
if a < b then Result:= a else Result:= b |
|
135 |
end; |
|
136 |
||
137 |
function Max(a, b: integer): integer; |
|
138 |
begin |
|
139 |
if a > b then Result:= a else Result:= b |
|
140 |
end; |
|
141 |
||
142 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
143 |
begin |
|
144 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 145 |
WriteLnToConsole(Msg); |
4 | 146 |
if isFatalError then |
147 |
begin |
|
53 | 148 |
SendIPC('E' + GetLastConsoleLine); |
4 | 149 |
SDL_Quit; |
150 |
halt(1) |
|
53 | 151 |
end |
4 | 152 |
end; |
153 |
||
154 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
155 |
begin |
|
70 | 156 |
if not Assert then OutError(Msg, isFatal) |
4 | 157 |
end; |
158 |
||
159 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
160 |
begin |
|
161 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
162 |
end; |
|
163 |
||
164 |
procedure AdjustColor(var Color: Cardinal); |
|
165 |
begin |
|
166 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
167 |
end; |
|
168 |
||
169 |
function IntToStr(n: integer): shortstring; |
|
170 |
begin |
|
171 |
str(n, Result) |
|
172 |
end; |
|
173 |
||
107 | 174 |
function FloatToStr(n: Double): shortstring; |
4 | 175 |
begin |
53 | 176 |
str(n:5:5, Result) |
4 | 177 |
end; |
178 |
||
100 | 179 |
{$IFNDEF FPC} |
107 | 180 |
function arctan2(const Y, X: Double): Double; |
4 | 181 |
asm |
182 |
fld Y |
|
183 |
fld X |
|
184 |
fpatan |
|
185 |
fwait |
|
186 |
end; |
|
100 | 187 |
{$ENDIF} |
4 | 188 |
|
189 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
100 | 190 |
const _16divPI: Extended = 16/pi; |
191 |
begin |
|
192 |
Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f |
|
4 | 193 |
end; |
194 |
||
100 | 195 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
196 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
197 |
begin |
|
198 |
Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle |
|
199 |
end; |
|
4 | 200 |
|
201 |
{$IFDEF DEBUGFILE} |
|
202 |
procedure AddFileLog(s: shortstring); |
|
203 |
begin |
|
204 |
writeln(f, GameTicks: 6, ': ', s); |
|
205 |
flush(f) |
|
206 |
end; |
|
207 |
||
24 | 208 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
209 |
begin |
|
210 |
Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
211 |
end; |
|
212 |
||
4 | 213 |
initialization |
108 | 214 |
AssignFile(f, 'debug.txt'); |
4 | 215 |
rewrite(f); |
17 | 216 |
|
4 | 217 |
finalization |
218 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
219 |
Flush(f); |
|
220 |
closefile(f) |
|
221 |
{$ENDIF} |
|
222 |
||
223 |
end. |