hedgewars/uMisc.pas
branchexperimental3D
changeset 4004 b1c2c2f6fc5e
parent 3696 6009d8378422
parent 3988 044cc945b2f8
child 4343 19cbea33e4d2
equal deleted inserted replaced
3698:793386610068 4004:b1c2c2f6fc5e
    15 * along with this program; if not, write to the Free Software
    15 * along with this program; if not, write to the Free Software
    16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17 *)
    17 *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 {$INLINE ON}
       
    21 
    20 
    22 unit uMisc;
    21 unit uMisc;
    23 interface
    22 interface
    24 
    23 
    25 uses    SDLh, uConsts, uFloat, GLunit, Math;
    24 uses    SDLh, uConsts, uFloat, GLunit, Math;
    26 
    25 
    27 var
    26 var
       
    27 /////// init flags ///////
       
    28     cScreenWidth    : LongInt     = 1024;
       
    29     cScreenHeight   : LongInt     = 768;
       
    30     cBits           : LongInt     = 32;
       
    31     //ipcPort is in uIO
       
    32     cFullScreen     : boolean     = false;
       
    33     isSoundEnabled  : boolean     = true;
       
    34     isMusicEnabled  : boolean     = false;
       
    35     cLocaleFName    : shortstring = 'en.txt';
       
    36     cInitVolume     : LongInt     = 100;
       
    37     cTimerInterval  : LongInt     = 8;
       
    38     PathPrefix      : shortstring = './';
       
    39     cShowFPS        : boolean     = false;
       
    40     cAltDamage      : boolean     = true;
       
    41     cReducedQuality : LongInt     = rqNone;
       
    42     //userNick is in uChat
       
    43     recordFileName  : shortstring = '';
       
    44     cReadyDelay     : Longword    = 0;
       
    45     cLogfileBase    : shortstring = 'debug';
       
    46 //////////////////////////
       
    47     
    28     isCursorVisible : boolean;
    48     isCursorVisible : boolean;
    29     isTerminated    : boolean;
    49     isTerminated    : boolean;
    30     isInLag         : boolean;
    50     isInLag         : boolean;
    31     isPaused        : boolean;
    51     isPaused        : boolean;
    32 
    52 
    33     isSEBackup      : boolean;
    53     isSEBackup      : boolean;
    34     isInMultiShoot  : boolean;
    54     isInMultiShoot  : boolean;
    35     isSpeed         : boolean;
    55     isSpeed         : boolean;
    36     isFirstFrame    : boolean;
    56     isFirstFrame    : boolean;
    37 
    57 
    38     //isStereoEnabled : boolean;
       
    39     cStereoMode     : TStereoMode;
    58     cStereoMode     : TStereoMode;
    40 
       
    41     fastUntilLag    : boolean;
    59     fastUntilLag    : boolean;
    42 
    60 
    43     GameState       : TGameState;
    61     GameState       : TGameState;
    44     GameType        : TGameType;
    62     GameType        : TGameType;
    45     GameFlags       : Longword;
    63     GameFlags       : Longword;
    46     TrainingFlags   : Longword;
    64     TrainingFlags   : Longword;
    47     TurnTimeLeft    : Longword;
    65     TurnTimeLeft    : Longword;
       
    66     ReadyTimeLeft   : Longword;
    48     cSuddenDTurns   : LongInt;
    67     cSuddenDTurns   : LongInt;
    49     cDamagePercent  : LongInt;
    68     cDamagePercent  : LongInt;
    50     cMineDudPercent : LongWord;
    69     cMineDudPercent : LongWord;
    51     cTemplateFilter : LongInt;
    70     cTemplateFilter : LongInt;
    52     cMapGen         : LongInt;
    71     cMapGen         : LongInt;
    71     TrainingTimeInM : Longword;
    90     TrainingTimeInM : Longword;
    72     TrainingTimeMax : Longword;
    91     TrainingTimeMax : Longword;
    73 
    92 
    74     TimeTrialStartTime: Longword;
    93     TimeTrialStartTime: Longword;
    75     TimeTrialStopTime : Longword;
    94     TimeTrialStopTime : Longword;
    76     
    95 
    77     // init flags
    96     // originally from uConsts
    78     cScreenWidth    : LongInt = 1024;
    97     Pathz: array[TPathType] of shortstring;
    79     cScreenHeight   : LongInt = 768;
    98     CountTexz: array[1..Pred(AMMO_INFINITE)] of PTexture;
    80     cBits           : LongInt = 32;
    99     LAND_WIDTH       : LongInt;
    81     cBitsStr        : string[2] = '32';
   100     LAND_HEIGHT      : LongInt;
    82     //ipcPort is in uIO
   101     LAND_WIDTH_MASK  : LongWord;
    83     cFullScreen     : boolean = false;
   102     LAND_HEIGHT_MASK : LongWord;
    84     isSoundEnabled  : boolean = true;
   103     cMaxCaptions     : LongInt;
    85     isMusicEnabled  : boolean = false;
   104 
    86     cLocaleFName    : shortstring = 'en.txt';
   105     cLeftScreenBorder     : LongInt;
    87     cInitVolume     : LongInt = 50;
   106     cRightScreenBorder    : LongInt;
    88     cTimerInterval  : LongInt = 8;
   107     cScreenSpace          : LongInt;
    89     //pathPrefix is in uConsts
   108 
    90     cShowFPS        : boolean = false;
       
    91     cAltDamage      : boolean = true;
       
    92     cReducedQuality : LongInt = rqNone;
       
    93 
       
    94     recordFileName  : shortstring = '';
       
    95     
       
    96     cCaseFactor     : Longword;
   109     cCaseFactor     : Longword;
    97     cLandAdditions  : Longword;
   110     cLandAdditions  : Longword;
    98     cExplosives     : Longword;
   111     cExplosives     : Longword;
    99 
   112 
   100     cSeed           : shortstring;
   113     cSeed           : shortstring;
   148 procedure SplitBySpace(var a, b: shortstring);
   161 procedure SplitBySpace(var a, b: shortstring);
   149 procedure SplitByChar(var a, b: ansistring; c: char);
   162 procedure SplitByChar(var a, b: ansistring; c: char);
   150 function  EnumToStr(const en : TGearType) : shortstring; overload;
   163 function  EnumToStr(const en : TGearType) : shortstring; overload;
   151 function  EnumToStr(const en : TSound) : shortstring; overload;
   164 function  EnumToStr(const en : TSound) : shortstring; overload;
   152 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
   165 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
       
   166 function  EnumToStr(const en : THogEffect) : shortstring; overload;
   153 procedure movecursor(dx, dy: LongInt);
   167 procedure movecursor(dx, dy: LongInt);
   154 function  hwSign(r: hwFloat): LongInt;
   168 function  hwSign(r: hwFloat): LongInt; inline;
   155 function  Min(a, b: LongInt): LongInt;
   169 function  Min(a, b: LongInt): LongInt; inline;
   156 function  Max(a, b: LongInt): LongInt;
   170 function  Max(a, b: LongInt): LongInt; inline;
   157 procedure OutError(Msg: shortstring; isFatalError: boolean);
   171 procedure OutError(Msg: shortstring; isFatalError: boolean);
   158 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
   172 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
   159 procedure SDLTry(Assert: boolean; isFatal: boolean);
   173 procedure SDLTry(Assert: boolean; isFatal: boolean);
   160 function  IntToStr(n: LongInt): shortstring;
   174 function  IntToStr(n: LongInt): shortstring;
   161 function  FloatToStr(n: hwFloat): shortstring;
   175 function  FloatToStr(n: hwFloat): shortstring;
   162 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
   176 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
   163 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
   177 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
   164 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
   178 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
       
   179 (*
   165 procedure AdjustColor(var Color: Longword);
   180 procedure AdjustColor(var Color: Longword);
   166 procedure SetKB(n: Longword);
   181 procedure SetKB(n: Longword);
       
   182 *)
   167 procedure SendKB;
   183 procedure SendKB;
   168 procedure SetLittle(var r: hwFloat);
   184 procedure SetLittle(var r: hwFloat);
   169 procedure SendStat(sit: TStatInfoType; s: shortstring);
   185 procedure SendStat(sit: TStatInfoType; s: shortstring);
   170 function  Str2PChar(const s: shortstring): PChar;
   186 function  Str2PChar(const s: shortstring): PChar;
   171 function  NewTexture(width, height: Longword; buf: Pointer): PTexture;
   187 function  NewTexture(width, height: Longword; buf: Pointer): PTexture;
   172 function  Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
   188 function  Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
   173 procedure FreeTexture(tex: PTexture);
   189 procedure FreeTexture(tex: PTexture);
   174 function  toPowerOf2(i: Longword): Longword; inline;
   190 function  toPowerOf2(i: Longword): Longword; inline;
   175 function  DecodeBase64(s: shortstring): shortstring;
   191 function  DecodeBase64(s: shortstring): shortstring;
   176 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   192 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   177 function  endian(independent: LongWord): LongWord;
   193 function  endian(independent: LongWord): LongWord; inline;
   178 {$IFDEF DEBUGFILE}
   194 {$IFDEF DEBUGFILE}
   179 procedure AddFileLog(s: shortstring);
   195 procedure AddFileLog(s: shortstring);
   180 function  RectToStr(Rect: TSDL_Rect): shortstring;
   196 (* function  RectToStr(Rect: TSDL_Rect): shortstring; *)
   181 {$ENDIF}
   197 {$ENDIF}
   182 procedure MakeScreenshot(filename: shortstring);
   198 procedure MakeScreenshot(filename: shortstring);
   183 
   199 
   184 implementation
   200 implementation
   185 uses uConsole, uStore, uIO, uSound, typinfo, sysutils;
   201 uses uConsole, uStore, uIO, uSound, typinfo, sysutils, uMobile;
   186 
   202 
   187 var KBnum: Longword;
   203 var KBnum: Longword;
   188 {$IFDEF DEBUGFILE}
   204 {$IFDEF DEBUGFILE}
   189     f: textfile;
   205     f: textfile;
   190 {$ENDIF}
   206 {$ENDIF}
   227 function EnumToStr(const en : TAmmoType) : shortstring; overload;
   243 function EnumToStr(const en : TAmmoType) : shortstring; overload;
   228 begin
   244 begin
   229 EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en))
   245 EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en))
   230 end;
   246 end;
   231 
   247 
       
   248 function EnumToStr(const en: THogEffect) : shortstring; overload;
       
   249 begin
       
   250     EnumToStr := GetEnumName(TypeInfo(THogEffect), ord(en))
       
   251 end;
       
   252 
   232 procedure movecursor(dx, dy: LongInt);
   253 procedure movecursor(dx, dy: LongInt);
   233 var x, y: LongInt;
   254 var x, y: LongInt;
   234 begin
   255 begin
   235 if (dx = 0) and (dy = 0) then exit;
   256 if (dx = 0) and (dy = 0) then exit;
   236 
   257 
   258 
   279 
   259 procedure OutError(Msg: shortstring; isFatalError: boolean);
   280 procedure OutError(Msg: shortstring; isFatalError: boolean);
   260 begin
   281 begin
   261 // obsolete? written in WriteLnToConsole() anyway
   282 // obsolete? written in WriteLnToConsole() anyway
   262 // {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF}
   283 // {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF}
   263 WriteLnToConsole(Msg);
   284     WriteLnToConsole(Msg);
   264 if isFatalError then
   285     if isFatalError then
   265     begin
   286     begin
   266     SendIPC('E' + GetLastConsoleLine);
   287         SendIPC('E' + GetLastConsoleLine);
   267     SDL_Quit;
   288         SDL_Quit;
   268     halt(1)
   289         halt(1)
   269     end
   290     end
   270 end;
   291 end;
   271 
   292 
   272 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
   293 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
   273 begin
   294 begin
   277 procedure SDLTry(Assert: boolean; isFatal: boolean);
   298 procedure SDLTry(Assert: boolean; isFatal: boolean);
   278 begin
   299 begin
   279 if not Assert then OutError(SDL_GetError, isFatal)
   300 if not Assert then OutError(SDL_GetError, isFatal)
   280 end;
   301 end;
   281 
   302 
       
   303 (*
   282 procedure AdjustColor(var Color: Longword);
   304 procedure AdjustColor(var Color: Longword);
   283 begin
   305 begin
   284 Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF)
   306 Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF)
   285 end;
   307 end;
       
   308 
       
   309 procedure SetKB(n: Longword);
       
   310 begin
       
   311 KBnum:= n
       
   312 end;
       
   313 *)
       
   314 
   286 
   315 
   287 function IntToStr(n: LongInt): shortstring;
   316 function IntToStr(n: LongInt): shortstring;
   288 begin
   317 begin
   289 str(n, IntToStr)
   318 str(n, IntToStr)
   290 end;
   319 end;
   335 dX:= _dX.QWordValue / $100000000;
   364 dX:= _dX.QWordValue / $100000000;
   336 if _dX.isNegative then dX:= - dX;
   365 if _dX.isNegative then dX:= - dX;
   337 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   366 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   338 end;
   367 end;
   339 
   368 
   340 procedure SetKB(n: Longword);
       
   341 begin
       
   342 KBnum:= n
       
   343 end;
       
   344 
       
   345 procedure SendKB;
   369 procedure SendKB;
   346 var s: shortstring;
   370 var s: shortstring;
   347 begin
   371 begin
   348 if KBnum <> 0 then
   372 if KBnum <> 0 then
   349 begin
   373 begin
   356 begin
   380 begin
   357 r:= SignAs(cLittle, r)
   381 r:= SignAs(cLittle, r)
   358 end;
   382 end;
   359 
   383 
   360 procedure SendStat(sit: TStatInfoType; s: shortstring);
   384 procedure SendStat(sit: TStatInfoType; s: shortstring);
   361 const stc: array [TStatInfoType] of char = 'rDkKHT';
   385 const stc: array [TStatInfoType] of char = 'rDkKHTPsSB';
   362 var buf: shortstring;
   386 var buf: shortstring;
   363 begin
   387 begin
   364 buf:= 'i' + stc[sit] + s;
   388 buf:= 'i' + stc[sit] + s;
   365 SendIPCRaw(@buf[0], length(buf) + 1)
   389 SendIPCRaw(@buf[0], length(buf) + 1)
   366 end;
   390 end;
   455 
   479 
   456 Surface2Tex^.w:= surf^.w;
   480 Surface2Tex^.w:= surf^.w;
   457 Surface2Tex^.h:= surf^.h;
   481 Surface2Tex^.h:= surf^.h;
   458 
   482 
   459 if (surf^.format^.BytesPerPixel <> 4) then
   483 if (surf^.format^.BytesPerPixel <> 4) then
   460 begin
   484     begin
   461     TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true);
   485     TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true);
   462     Surface2Tex^.id:= 0;
   486     Surface2Tex^.id:= 0;
   463     exit
   487     exit
   464 end;
   488     end;
   465 
   489 
   466 
   490 
   467 glGenTextures(1, @Surface2Tex^.id);
   491 glGenTextures(1, @Surface2Tex^.id);
   468 
   492 
   469 glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id);
   493 glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id);
   470 
   494 
   471 if SDL_MustLock(surf) then
   495 if SDL_MustLock(surf) then
   472     SDLTry(SDL_LockSurface(surf) >= 0, true);
   496     SDLTry(SDL_LockSurface(surf) >= 0, true);
   473 
   497 
   474 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
   498 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
   475 begin
   499     begin
   476     tw:= toPowerOf2(Surf^.w);
   500     tw:= toPowerOf2(Surf^.w);
   477     th:= toPowerOf2(Surf^.h);
   501     th:= toPowerOf2(Surf^.h);
   478 
   502 
   479     Surface2Tex^.rx:= Surf^.w / tw;
   503     Surface2Tex^.rx:= Surf^.w / tw;
   480     Surface2Tex^.ry:= Surf^.h / th;
   504     Surface2Tex^.ry:= Surf^.h / th;
   481 
   505 
   482     GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel);
   506     GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel);
   483 
   507 
   484         fromP4:= Surf^.pixels;
   508     fromP4:= Surf^.pixels;
   485         toP4:= tmpp;
   509     toP4:= tmpp;
   486 
   510 
   487         for y:= 0 to Pred(Surf^.h) do
   511     for y:= 0 to Pred(Surf^.h) do
   488         begin
   512         begin
   489             for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x];
   513         for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x];
   490             for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0;
   514         for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0;
   491             toP4:= @(toP4^[tw]);
   515         toP4:= @(toP4^[tw]);
   492             fromP4:= @(fromP4^[Surf^.pitch div 4]);
   516         fromP4:= @(fromP4^[Surf^.pitch div 4])
   493         end;
   517         end;
   494 
   518 
   495         for y:= Surf^.h to Pred(th) do
   519     for y:= Surf^.h to Pred(th) do
   496         begin
   520         begin
   497             for x:= 0 to Pred(tw) do toP4^[x]:= 0;
   521         for x:= 0 to Pred(tw) do toP4^[x]:= 0;
   498             toP4:= @(toP4^[tw]);
   522         toP4:= @(toP4^[tw])
   499         end;
   523         end;
   500 
   524 
   501     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp);
   525     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp);
   502 
   526 
   503     FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel)
   527     FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel)
   504 end
   528     end
   505 else
   529 else
   506 begin
   530     begin
   507     Surface2Tex^.rx:= 1.0;
   531     Surface2Tex^.rx:= 1.0;
   508     Surface2Tex^.ry:= 1.0;
   532     Surface2Tex^.ry:= 1.0;
   509     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels);
   533     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels);
   510 end;
   534     end;
   511 
   535 
   512 ResetVertexArrays(Surface2Tex);
   536 ResetVertexArrays(Surface2Tex);
   513 
   537 
   514 if SDL_MustLock(surf) then
   538 if SDL_MustLock(surf) then
   515     SDL_UnlockSurface(surf);
   539     SDL_UnlockSurface(surf);
   519 
   543 
   520 procedure FreeTexture(tex: PTexture);
   544 procedure FreeTexture(tex: PTexture);
   521 begin
   545 begin
   522     if tex <> nil then
   546     if tex <> nil then
   523     begin
   547     begin
   524         if tex^.NextTexture <> nil then 
   548         if tex^.NextTexture <> nil then
   525             tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
   549             tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
   526         if tex^.PrevTexture <> nil then 
   550         if tex^.PrevTexture <> nil then
   527             tex^.PrevTexture^.NextTexture:= tex^.NextTexture
   551             tex^.PrevTexture^.NextTexture:= tex^.NextTexture
   528         else 
   552         else
   529             TextureList:= tex^.NextTexture;
   553             TextureList:= tex^.NextTexture;
   530         glDeleteTextures(1, @tex^.id);
   554         glDeleteTextures(1, @tex^.id);
   531         Dispose(tex);
   555         Dispose(tex);
   532     end
   556     end
   533 end;
   557 end;
   636 procedure AddFileLog(s: shortstring);
   660 procedure AddFileLog(s: shortstring);
   637 begin
   661 begin
   638 writeln(f, GameTicks: 6, ': ', s);
   662 writeln(f, GameTicks: 6, ': ', s);
   639 flush(f)
   663 flush(f)
   640 end;
   664 end;
   641 
   665 (*
   642 function RectToStr(Rect: TSDL_Rect): shortstring;
   666 function RectToStr(Rect: TSDL_Rect): shortstring;
   643 begin
   667 begin
   644 RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
   668 RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
   645 end;
   669 end;
       
   670 *)
   646 {$ENDIF}
   671 {$ENDIF}
   647 
   672 
   648 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   673 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   649 {* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *}
   674 {* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *}
   650 var convertedSurf: PSDL_Surface = nil;
   675 var convertedSurf: PSDL_Surface = nil;
   657     end;
   682     end;
   658 
   683 
   659     exit(tmpsurf);
   684     exit(tmpsurf);
   660 end;
   685 end;
   661 
   686 
   662 function endian(independent: LongWord): LongWord;
   687 function endian(independent: LongWord): LongWord; inline;
   663 begin
   688 begin
   664 {$IFDEF ENDIAN_LITTLE}
   689 {$IFDEF ENDIAN_LITTLE}
   665 endian:= independent;
   690 endian:= independent;
   666 {$ELSE}
   691 {$ELSE}
   667 endian:= (((independent and $FF000000) shr 24) or
   692 endian:= (((independent and $FF000000) shr 24) or
   673 
   698 
   674 
   699 
   675 procedure initModule;
   700 procedure initModule;
   676 {$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF}
   701 {$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF}
   677 begin
   702 begin
       
   703     Pathz:= cPathz;
       
   704         {*  REFERENCE
       
   705       4096 -> $FFFFF000
       
   706       2048 -> $FFFFF800
       
   707       1024 -> $FFFFFC00
       
   708        512 -> $FFFFFE00  *}
       
   709     if (cReducedQuality and rqLowRes) <> 0 then
       
   710     begin
       
   711         LAND_WIDTH:= 2048;
       
   712         LAND_HEIGHT:= 1024;
       
   713         LAND_WIDTH_MASK:= $FFFFF800;
       
   714         LAND_HEIGHT_MASK:= $FFFFFC00;
       
   715     end
       
   716     else
       
   717     begin
       
   718         LAND_WIDTH:= 4096;
       
   719         LAND_HEIGHT:= 2048;
       
   720         LAND_WIDTH_MASK:= $FFFFF000;
       
   721         LAND_HEIGHT_MASK:= $FFFFF800
       
   722     end;
       
   723 
   678     cDrownSpeed.QWordValue  := 257698038;       // 0.06
   724     cDrownSpeed.QWordValue  := 257698038;       // 0.06
   679     cDrownSpeedf            := 0.06;
   725     cDrownSpeedf            := 0.06;
   680     cMaxWindSpeed.QWordValue:= 1073742;     // 0.00025
   726     cMaxWindSpeed.QWordValue:= 1073742;     // 0.00025
   681     cWindSpeed.QWordValue   := 429496;      // 0.0001
   727     cWindSpeed.QWordValue   := 429496;      // 0.0001
   682     cWindSpeedf             := 0.0001;
   728     cWindSpeedf             := 0.0001;
   683     cGravity                := cMaxWindSpeed * 2;
   729     cGravity                := cMaxWindSpeed * 2;
   684     cGravityf               := 0.00025 * 2;
   730     cGravityf               := 0.00025 * 2;
   685     cDamageModifier         := _1;
   731     cDamageModifier         := _1;
   686     TargetPoint             := cTargetPointRef;
   732     TargetPoint             := cTargetPointRef;
   687     TextureList             := nil;
   733     TextureList             := nil;
   688     
   734 
   689     // int, longint longword and byte
   735     // int, longint longword and byte
   690     CursorMovementX     := 0;
   736     CursorMovementX     := 0;
   691     CursorMovementY     := 0;
   737     CursorMovementY     := 0;
   692     GameTicks           := 0;
   738     GameTicks           := 0;
   693     TrainingTimeInc     := 10000;
   739     TrainingTimeInc     := 10000;
   720     RealTicks       := 0;
   766     RealTicks       := 0;
   721     AttackBar       := 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP
   767     AttackBar       := 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP
   722     cCaseFactor     := 5;  {0..9}
   768     cCaseFactor     := 5;  {0..9}
   723     cLandAdditions  := 4;
   769     cLandAdditions  := 4;
   724     cExplosives     := 2;
   770     cExplosives     := 2;
   725         
   771 
   726     GameState       := Low(TGameState);
   772     GameState       := Low(TGameState);
   727     GameType        := gmtLocal;
   773     GameType        := gmtLocal;
   728     zoom            := cDefaultZoomLevel;
   774     zoom            := cDefaultZoomLevel;
   729     ZoomValue       := cDefaultZoomLevel;
   775     ZoomValue       := cDefaultZoomLevel;
   730     WeaponTooltipTex:= nil;
   776     WeaponTooltipTex:= nil;
   745     isSEBackup      := true;
   791     isSEBackup      := true;
   746     cSeed           := '';
   792     cSeed           := '';
   747     cVolumeDelta    := 0;
   793     cVolumeDelta    := 0;
   748     cHasFocus       := true;
   794     cHasFocus       := true;
   749     cInactDelay     := 1250;
   795     cInactDelay     := 1250;
       
   796     ReadyTimeLeft   := 0;
   750 
   797 
   751     ScreenFade      := sfNone;
   798     ScreenFade      := sfNone;
   752     
   799 
   753 {$IFDEF SDL13}
   800 {$IFDEF SDL13}
   754     SDLwindow       := nil;
   801     SDLwindow       := nil;
   755 {$ENDIF}    
   802 {$ENDIF}
       
   803 
       
   804     // those values still aren't perfect
       
   805     cLeftScreenBorder:= round(-cMinZoomLevel * cScreenWidth);
       
   806     cRightScreenBorder:= round(cMinZoomLevel * cScreenWidth + LAND_WIDTH);
       
   807     cScreenSpace:= cRightScreenBorder - cLeftScreenBorder;
       
   808 
       
   809     if isPhone() then
       
   810         cMaxCaptions:= 3
       
   811     else
       
   812         cMaxCaptions:= 4;
       
   813 
   756 {$IFDEF DEBUGFILE}
   814 {$IFDEF DEBUGFILE}
   757 {$I-}
   815 {$I-}
   758 {$IFDEF IPHONEOS}
   816 {$IFDEF IPHONEOS}
   759     Assign(f,'../Documents/debug.txt');
   817     Assign(f,'../Documents/hw-' + cLogfileBase + '.log');
   760     Rewrite(f);
   818     Rewrite(f);
   761 {$ELSE}
   819 {$ELSE}
   762     if (ParamStr(1) <> '') and (ParamStr(2) <> '') then
   820     if (ParamStr(1) <> '') and (ParamStr(2) <> '') then
   763         if (ParamCount <> 3) and (ParamCount <> 19) then
   821         if (ParamCount <> 3) and (ParamCount <> cDefaultParamNum) then
   764         begin
   822         begin
   765             for i:= 0 to 7 do
   823             for i:= 0 to 7 do
   766             begin
   824             begin
   767                 assign(f, ExtractFileDir(ParamStr(2)) + '/debug' + inttostr(i) + '.txt');
   825                 assign(f, ExtractFileDir(ParamStr(2)) + '/' + cLogfileBase + inttostr(i) + '.log');
   768                 rewrite(f);
   826                 rewrite(f);
   769                 if IOResult = 0 then break;
   827                 if IOResult = 0 then break;
   770             end;
   828             end;
   771             if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
   829             if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
   772         end
   830         end
   773         else
   831         else
   774         begin
   832         begin
   775             for i:= 0 to 7 do
   833             for i:= 0 to 7 do
   776             begin
   834             begin
   777                 assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt');
   835                 assign(f, ParamStr(1) + '/Logs/' + cLogfileBase + inttostr(i) + '.log');
   778                 rewrite(f);
   836                 rewrite(f);
   779                 if IOResult = 0 then break;
   837                 if IOResult = 0 then break;
   780             end;
   838             end;
   781             if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
   839             if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
   782         end
   840         end
   795 {$IFDEF DEBUGFILE}
   853 {$IFDEF DEBUGFILE}
   796     writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft);
   854     writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft);
   797     flush(f);
   855     flush(f);
   798     close(f);
   856     close(f);
   799 {$ENDIF}
   857 {$ENDIF}
       
   858 
       
   859     // re-init flags so they will always contain safe values
       
   860     cScreenWidth    := 1024;
       
   861     cScreenHeight   := 768;
       
   862     cBits           := 32;
       
   863     //ipcPort is in uIO
       
   864     cFullScreen     := false;
       
   865     isSoundEnabled  := true;
       
   866     isMusicEnabled  := false;
       
   867     cLocaleFName    := 'en.txt';
       
   868     cInitVolume     := 100;
       
   869     cTimerInterval  := 8;
       
   870     PathPrefix := './';
       
   871     cShowFPS        := false;
       
   872     cAltDamage      := true;
       
   873     cReducedQuality := rqNone;
       
   874     //userNick is in uChat
       
   875     recordFileName  := '';
       
   876     cReadyDelay     := 5000;
   800 end;
   877 end;
   801 
   878 
   802 end.
   879 end.