author | unc0rr |
Wed, 27 Sep 2006 20:13:29 +0000 | |
changeset 174 | 0b2c5b22f644 |
parent 143 | 3dacbd83209b |
child 183 | 57c2ef19f719 |
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 = ''; |
174 | 84 |
cInitVolume : integer = 128; |
85 |
cVolumeDelta : integer = 0; |
|
4 | 86 |
|
87 |
const |
|
88 |
cMaxPower = 1500; |
|
89 |
cMaxAngle = 2048; |
|
90 |
cPowerDivisor = 1500; |
|
91 |
||
92 |
var |
|
93 |
cSendEmptyPacketTime : LongWord = 2000; |
|
94 |
cSendCursorPosTime : LongWord = 50; |
|
13 | 95 |
ShowCrosshair : boolean; |
4 | 96 |
|
97 |
flagMakeCapture: boolean = false; |
|
98 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
99 |
InitStepsFlags: Longword = 0; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
100 |
|
79 | 101 |
AttackBar: integer = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 102 |
|
108 | 103 |
function hwSign(r: Double): integer; |
4 | 104 |
function Min(a, b: integer): integer; |
105 |
function Max(a, b: integer): integer; |
|
106 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
107 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
108 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
109 |
function IntToStr(n: integer): shortstring; |
|
107 | 110 |
function FloatToStr(n: Double): shortstring; |
4 | 111 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
100 | 112 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 113 |
procedure AdjustColor(var Color: Longword); |
114 |
{$IFDEF DEBUGFILE} |
|
115 |
procedure AddFileLog(s: shortstring); |
|
24 | 116 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 117 |
{$ENDIF} |
118 |
||
119 |
var CursorPoint: TPoint; |
|
120 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
121 |
||
122 |
implementation |
|
100 | 123 |
uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF}; |
4 | 124 |
{$IFDEF DEBUGFILE} |
125 |
var f: textfile; |
|
126 |
{$ENDIF} |
|
127 |
||
128 |
||
108 | 129 |
function hwSign(r: Double): integer; |
4 | 130 |
begin |
131 |
if r < 0 then Result:= -1 else Result:= 1 |
|
132 |
end; |
|
133 |
||
134 |
function Min(a, b: integer): integer; |
|
135 |
begin |
|
136 |
if a < b then Result:= a else Result:= b |
|
137 |
end; |
|
138 |
||
139 |
function Max(a, b: integer): integer; |
|
140 |
begin |
|
141 |
if a > b then Result:= a else Result:= b |
|
142 |
end; |
|
143 |
||
144 |
procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
145 |
begin |
|
146 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 147 |
WriteLnToConsole(Msg); |
4 | 148 |
if isFatalError then |
149 |
begin |
|
53 | 150 |
SendIPC('E' + GetLastConsoleLine); |
4 | 151 |
SDL_Quit; |
152 |
halt(1) |
|
53 | 153 |
end |
4 | 154 |
end; |
155 |
||
156 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
157 |
begin |
|
70 | 158 |
if not Assert then OutError(Msg, isFatal) |
4 | 159 |
end; |
160 |
||
161 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
162 |
begin |
|
163 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
164 |
end; |
|
165 |
||
166 |
procedure AdjustColor(var Color: Cardinal); |
|
167 |
begin |
|
168 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
169 |
end; |
|
170 |
||
171 |
function IntToStr(n: integer): shortstring; |
|
172 |
begin |
|
173 |
str(n, Result) |
|
174 |
end; |
|
175 |
||
107 | 176 |
function FloatToStr(n: Double): shortstring; |
4 | 177 |
begin |
53 | 178 |
str(n:5:5, Result) |
4 | 179 |
end; |
180 |
||
100 | 181 |
{$IFNDEF FPC} |
107 | 182 |
function arctan2(const Y, X: Double): Double; |
4 | 183 |
asm |
184 |
fld Y |
|
185 |
fld X |
|
186 |
fpatan |
|
187 |
fwait |
|
188 |
end; |
|
100 | 189 |
{$ENDIF} |
4 | 190 |
|
191 |
function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
100 | 192 |
const _16divPI: Extended = 16/pi; |
193 |
begin |
|
194 |
Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f |
|
4 | 195 |
end; |
196 |
||
100 | 197 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
198 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
|
199 |
begin |
|
200 |
Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle |
|
201 |
end; |
|
4 | 202 |
|
203 |
{$IFDEF DEBUGFILE} |
|
204 |
procedure AddFileLog(s: shortstring); |
|
205 |
begin |
|
206 |
writeln(f, GameTicks: 6, ': ', s); |
|
207 |
flush(f) |
|
208 |
end; |
|
209 |
||
24 | 210 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
211 |
begin |
|
212 |
Result:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
213 |
end; |
|
214 |
||
4 | 215 |
initialization |
108 | 216 |
AssignFile(f, 'debug.txt'); |
4 | 217 |
rewrite(f); |
17 | 218 |
|
4 | 219 |
finalization |
220 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
221 |
Flush(f); |
|
222 |
closefile(f) |
|
223 |
{$ENDIF} |
|
224 |
||
225 |
end. |