author | unc0rr |
Fri, 11 Aug 2006 16:17:50 +0000 | |
changeset 107 | b08ce0293a51 |
parent 100 | f324a18698fe |
child 108 | 08f1fe6f21f8 |
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 |
||
74 |
cDrownSpeed : Real = 0.06; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset
|
75 |
cMaxWindSpeed : Real = 0.0005; |
4 | 76 |
cWindSpeed : Real = 0.0001; |
77 |
cGravity : Real = 0.0005; |
|
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 |
|
107 | 100 |
function Sign(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} |
100 | 115 |
{$IFNDEF FPC} |
107 | 116 |
function arctan2(const Y, X: Double): Double; |
100 | 117 |
{$ENDIF} |
4 | 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 |
||
107 | 129 |
function Sign(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 |
216 |
assignfile(f, 'debug.txt'); |
|
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. |