|
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 TurnTimeLeft : Longword = 0; |
|
47 cHedgehogTurnTime: Longword = 30000; |
|
48 |
|
49 cLandYShift : integer = 888; |
|
50 cCloudsNumber : integer = 9; |
|
51 cConsoleHeight : integer = 320; |
|
52 cConsoleYAdd : integer = 0; |
|
53 cTimerInterval : Cardinal = 15; |
|
54 cScreenWidth : integer = 1024; |
|
55 cScreenHeight : integer = 768; |
|
56 cBits : integer = 16; |
|
57 cWaterLine : integer = 1024; |
|
58 cVisibleWater : integer = 64; |
|
59 cScreenEdgesDist : integer = 240; |
|
60 |
|
61 GameTicks : LongWord = 0; |
|
62 |
|
63 cSkyColor : Cardinal = 0; |
|
64 cWaterColor : Cardinal = $32397A; |
|
65 cMapBackColor : Cardinal = $FFFFFF; |
|
66 cWhiteColor : Cardinal = $FFFFFF; |
|
67 cConsoleSplitterColor : Cardinal = $FF0000; |
|
68 cColorNearBlack : Cardinal = 16; |
|
69 cExplosionBorderColor : LongWord = $808080; |
|
70 |
|
71 cDrownSpeed : Real = 0.06; |
|
72 cMaxWindSpeed : Real = 0.0003; |
|
73 cWindSpeed : Real = 0.0001; |
|
74 cGravity : Real = 0.0005; |
|
75 |
|
76 cShowFPS : boolean = true; |
|
77 cFullScreen : boolean = true; |
|
78 |
|
79 const |
|
80 cMaxPower = 1500; |
|
81 cMaxAngle = 2048; |
|
82 cPowerDivisor = 1500; |
|
83 |
|
84 var |
|
85 cSendEmptyPacketTime : LongWord = 2000; |
|
86 cSendCursorPosTime : LongWord = 50; |
|
87 |
|
88 flagMakeCapture: boolean = false; |
|
89 |
|
90 AttackBar : integer = 0; // 0 - отсутствует, 1 - внизу, 2 - как в wwp |
|
91 |
|
92 function Sign(r: real): integer; |
|
93 function Min(a, b: integer): integer; |
|
94 function Max(a, b: integer): integer; |
|
95 procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
96 procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
97 procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
98 function IntToStr(n: integer): shortstring; |
|
99 function FloatToStr(n: real): shortstring; |
|
100 function arctan(const Y, X: real): real; |
|
101 function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
102 procedure AdjustColor(var Color: Longword); |
|
103 {$IFDEF DEBUGFILE} |
|
104 procedure AddFileLog(s: shortstring); |
|
105 {$ENDIF} |
|
106 |
|
107 var CursorPoint: TPoint; |
|
108 TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
109 |
|
110 implementation |
|
111 uses uConsole, uStore; |
|
112 {$IFDEF DEBUGFILE} |
|
113 var f: textfile; |
|
114 {$ENDIF} |
|
115 |
|
116 |
|
117 function Sign(r: real): integer; |
|
118 begin |
|
119 if r < 0 then Result:= -1 else Result:= 1 |
|
120 end; |
|
121 |
|
122 function Min(a, b: integer): integer; |
|
123 begin |
|
124 if a < b then Result:= a else Result:= b |
|
125 end; |
|
126 |
|
127 function Max(a, b: integer): integer; |
|
128 begin |
|
129 if a > b then Result:= a else Result:= b |
|
130 end; |
|
131 |
|
132 procedure OutError(Msg: String; const isFatalError: boolean=false); |
|
133 begin |
|
134 {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
135 if isFatalError then |
|
136 begin |
|
137 WriteLn(Msg); |
|
138 SDL_Quit; |
|
139 Readln; |
|
140 halt(1) |
|
141 end else WriteLnToConsole(Msg) |
|
142 end; |
|
143 |
|
144 procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
145 begin |
|
146 if not Assert then OutError(msg, isFatal) |
|
147 end; |
|
148 |
|
149 procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
150 begin |
|
151 if not Assert then OutError(SDL_GetError, isFatal) |
|
152 end; |
|
153 |
|
154 procedure AdjustColor(var Color: Cardinal); |
|
155 begin |
|
156 Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
157 end; |
|
158 |
|
159 function IntToStr(n: integer): shortstring; |
|
160 begin |
|
161 str(n, Result) |
|
162 end; |
|
163 |
|
164 function FloatToStr(n: real): shortstring; |
|
165 begin |
|
166 str(n, Result) |
|
167 end; |
|
168 |
|
169 function arctan(const Y, X: real): real; |
|
170 asm |
|
171 fld Y |
|
172 fld X |
|
173 fpatan |
|
174 fwait |
|
175 end; |
|
176 |
|
177 function DxDy2Angle32(const _dY, _dX: Extended): integer; |
|
178 const piDIV32: Extended = pi/32; |
|
179 asm |
|
180 fld _dY |
|
181 fld _dX |
|
182 fpatan |
|
183 fld piDIV32 |
|
184 fdiv |
|
185 sub esp, 4 |
|
186 fistp dword ptr [esp] |
|
187 pop eax |
|
188 shr eax, 1 |
|
189 and eax, $1F |
|
190 end; |
|
191 |
|
192 |
|
193 {$IFDEF DEBUGFILE} |
|
194 procedure AddFileLog(s: shortstring); |
|
195 begin |
|
196 writeln(f, GameTicks: 6, ': ', s); |
|
197 flush(f) |
|
198 end; |
|
199 |
|
200 initialization |
|
201 assignfile(f, 'debug.txt'); |
|
202 rewrite(f); |
|
203 finalization |
|
204 writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
|
205 Flush(f); |
|
206 closefile(f) |
|
207 {$ENDIF} |
|
208 |
|
209 end. |