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