27 interface |
27 interface |
28 {$ELSE} |
28 {$ELSE} |
29 program hwengine; |
29 program hwengine; |
30 {$ENDIF} |
30 {$ENDIF} |
31 |
31 |
32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, |
32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, |
33 uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, sysutils; |
33 uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, uMobile, sysutils; |
34 |
34 |
35 type arrayofpchar = array[0..9] of PChar; |
|
36 var isTerminated: boolean = false; |
35 var isTerminated: boolean = false; |
37 alsoShutdownFrontend: boolean = false; |
36 alsoShutdownFrontend: boolean = false; |
38 |
37 |
39 {$IFDEF HWLIBRARY} |
38 {$IFDEF HWLIBRARY} |
40 procedure initEverything(complete:boolean); |
39 procedure initEverything(complete:boolean); |
213 cTimerInterval:= 8; |
212 cTimerInterval:= 8; |
214 PathPrefix:= 'Data'; |
213 PathPrefix:= 'Data'; |
215 {$IFDEF DEBUGFILE} |
214 {$IFDEF DEBUGFILE} |
216 cShowFPS:= true; |
215 cShowFPS:= true; |
217 {$ELSE} |
216 {$ELSE} |
218 cShowFPS:= true; // update me at release time |
217 cShowFPS:= false; |
219 {$ENDIF} |
218 {$ENDIF} |
220 cInitVolume:= 100; |
219 val(gameArgs[0], ipcPort); |
221 |
220 val(gameArgs[1], cScreenWidth); |
222 UserNick:= gameArgs[0]; |
221 val(gameArgs[2], cScreenHeight); |
223 val(gameArgs[1], ipcPort); |
222 val(gameArgs[3], cReducedQuality); |
224 isSoundEnabled:= gameArgs[2] = '1'; |
|
225 isMusicEnabled:= gameArgs[3] = '1'; |
|
226 cLocaleFName:= gameArgs[4]; |
223 cLocaleFName:= gameArgs[4]; |
227 cAltDamage:= gameArgs[5] = '1'; |
224 UserNick:= gameArgs[5]; |
228 val(gameArgs[6], cScreenHeight); |
225 isSoundEnabled:= gameArgs[6] = '1'; |
229 val(gameArgs[7], cScreenWidth); |
226 isMusicEnabled:= gameArgs[7] = '1'; |
230 recordFileName:= gameArgs[8]; |
227 cAltDamage:= gameArgs[8] = '1'; |
231 |
228 val(gameArgs[9], rotationQt); |
232 val(gameArgs[9], cReducedQuality); |
229 recordFileName:= gameArgs[10]; |
233 cStereoMode:= smNone; // TODO: Enable anaglyph rendering on iPhone? |
230 cStereoMode:= smNone; // TODO: Enable anaglyph rendering on iPhone? |
234 {$ENDIF} |
231 {$ENDIF} |
235 |
232 |
|
233 cLogfileBase:= 'game'; |
236 initEverything(true); |
234 initEverything(true); |
237 |
235 |
238 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
236 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
239 {$IFDEF DEBUGFILE} |
237 {$IFDEF DEBUGFILE} |
240 AddFileLog('Prefix: "' + PathPrefix +'"'); |
238 AddFileLog('Prefix: "' + PathPrefix +'"'); |
267 AddProgress(); |
265 AddProgress(); |
268 |
266 |
269 ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
267 ControllerInit(); // has to happen before InitKbdKeyTable to map keys |
270 InitKbdKeyTable(); |
268 InitKbdKeyTable(); |
271 |
269 |
272 if recordFileName = '' then |
|
273 InitIPC; |
|
274 WriteLnToConsole(msgGettingConfig); |
|
275 |
|
276 LoadLocale(Pathz[ptLocale] + '/en.txt'); // Do an initial load with english |
270 LoadLocale(Pathz[ptLocale] + '/en.txt'); // Do an initial load with english |
277 if cLocaleFName <> 'en.txt' then |
271 if cLocaleFName <> 'en.txt' then |
278 begin |
272 begin |
279 // Try two letter locale first before trying specific locale overrides |
273 // Try two letter locale first before trying specific locale overrides |
280 if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then |
274 if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then |
281 LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt'); |
275 LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt'); |
282 LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
276 LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
283 end; |
277 end; |
284 |
278 |
|
279 WriteLnToConsole(msgGettingConfig); |
285 if recordFileName = '' then |
280 if recordFileName = '' then |
286 SendIPCAndWaitReply('C') // ask for game config |
281 begin |
|
282 InitIPC; |
|
283 SendIPCAndWaitReply('C'); // ask for game config |
|
284 end |
287 else |
285 else |
|
286 begin |
288 LoadRecordFromFile(recordFileName); |
287 LoadRecordFromFile(recordFileName); |
|
288 perfExt_SaveBeganSynching(); |
|
289 end; |
289 |
290 |
290 ScriptOnGameInit; |
291 ScriptOnGameInit; |
291 |
292 |
292 s:= 'eproto ' + inttostr(cNetProtoVersion); |
293 s:= 'eproto ' + inttostr(cNetProtoVersion); |
293 SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
294 SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
417 procedure DisplayUsage; |
418 procedure DisplayUsage; |
418 var i: LongInt; |
419 var i: LongInt; |
419 begin |
420 begin |
420 WriteLn('Wrong argument format: correct configurations is'); |
421 WriteLn('Wrong argument format: correct configurations is'); |
421 WriteLn(); |
422 WriteLn(); |
422 WriteLn(' hwengine <path to data folder> <path to replay file> [option]'); |
423 WriteLn(' hwengine <path to data folder> <path to replay file> [options]'); |
423 WriteLn(); |
424 WriteLn(); |
424 WriteLn('where [option] must be specified either as'); |
425 WriteLn('where [options] must be specified either as:'); |
425 WriteLn(' --set-video [screen width] [screen height] [color dept]'); |
426 WriteLn(' --set-video [screen width] [screen height] [color dept]'); |
426 WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
427 WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); |
427 WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
428 WriteLn(' --set-other [language file] [full screen] [show FPS]'); |
428 WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
429 WriteLn(' --set-multimedia [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); |
429 WriteLn(' --set-everything [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]'); |
430 WriteLn(' --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]'); |
430 WriteLn(); |
431 WriteLn(); |
431 WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); |
432 WriteLn('Read documentation online at http://code.google.com/p/hedgewars/wiki/CommandLineOptions for more information'); |
432 Write('parsed command: '); |
433 WriteLn(); |
|
434 Write('PARSED COMMAND: '); |
433 for i:=0 to ParamCount do |
435 for i:=0 to ParamCount do |
434 Write(ParamStr(i) + ' '); |
436 Write(ParamStr(i) + ' '); |
435 WriteLn(); |
437 WriteLn(); |
436 end; |
438 end; |
437 |
439 |
438 //////////////////// |
440 //////////////////// |
|
441 {$INCLUDE "ArgParsers.inc"} |
|
442 |
439 procedure GetParams; |
443 procedure GetParams; |
440 var i : LongInt; |
444 begin |
441 begin |
445 if (ParamCount < 2) then |
442 case ParamCount of |
446 GameType:= gmtSyntax |
443 19: begin |
447 else |
444 val(ParamStr(2), cScreenWidth); |
448 if (ParamCount = 3) then |
445 val(ParamStr(3), cScreenHeight); |
449 internalSetGameTypeLandPreviewFromParameters() |
446 cBitsStr:= ParamStr(4); |
450 else |
447 val(cBitsStr, cBits); |
451 if (ParamCount = cDefaultParamNum) then |
448 val(ParamStr(5), ipcPort); |
452 internalStartGameWithParameters() |
449 cFullScreen:= ParamStr(6) = '1'; |
|
450 isSoundEnabled:= ParamStr(7) = '1'; |
|
451 //cVSyncInUse:= ParamStr(8) = '1'; //merged with rqFlags |
|
452 //cWeaponTooltips:= ParamStr(9) = '1'; //merged with rqFlags |
|
453 cLocaleFName:= ParamStr(10); |
|
454 val(ParamStr(11), cInitVolume); |
|
455 val(ParamStr(12), cTimerInterval); |
|
456 PathPrefix:= ParamStr(13); |
|
457 cShowFPS:= ParamStr(14) = '1'; |
|
458 cAltDamage:= ParamStr(15) = '1'; |
|
459 UserNick:= DecodeBase64(ParamStr(16)); |
|
460 isMusicEnabled:= ParamStr(17) = '1'; |
|
461 val(ParamStr(18), cReducedQuality); |
|
462 val(ParamStr(19), i); |
|
463 cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), i))); |
|
464 end; |
|
465 3: begin |
|
466 val(ParamStr(2), ipcPort); |
|
467 GameType:= gmtLandPreview; |
|
468 if ParamStr(3) <> 'landpreview' then |
|
469 OutError(errmsgShouldntRun, true); |
|
470 end; |
|
471 2: begin |
|
472 PathPrefix:= ParamStr(1); |
|
473 recordFileName:= ParamStr(2); |
|
474 end; |
|
475 6: begin |
|
476 PathPrefix:= ParamStr(1); |
|
477 recordFileName:= ParamStr(2); |
|
478 |
|
479 if ParamStr(3) = '--set-video' then |
|
480 begin |
|
481 val(ParamStr(4), cScreenWidth); |
|
482 val(ParamStr(5), cScreenHeight); |
|
483 cBitsStr:= ParamStr(6); |
|
484 val(cBitsStr, cBits); |
|
485 end |
|
486 else |
453 else |
487 begin |
454 playReplayFileWithParameters(); |
488 if ParamStr(3) = '--set-audio' then |
|
489 begin |
|
490 val(ParamStr(4), cInitVolume); |
|
491 isMusicEnabled:= ParamStr(5) = '1'; |
|
492 isSoundEnabled:= ParamStr(6) = '1'; |
|
493 end |
|
494 else |
|
495 begin |
|
496 if ParamStr(3) = '--set-other' then |
|
497 begin |
|
498 cLocaleFName:= ParamStr(4); |
|
499 cFullScreen:= ParamStr(5) = '1'; |
|
500 cShowFPS:= ParamStr(6) = '1'; |
|
501 end |
|
502 else GameType:= gmtSyntax; |
|
503 end |
|
504 end; |
|
505 end; |
|
506 11: begin |
|
507 PathPrefix:= ParamStr(1); |
|
508 recordFileName:= ParamStr(2); |
|
509 |
|
510 if ParamStr(3) = '--set-multimedia' then |
|
511 begin |
|
512 val(ParamStr(4), cScreenWidth); |
|
513 val(ParamStr(5), cScreenHeight); |
|
514 cBitsStr:= ParamStr(6); |
|
515 val(cBitsStr, cBits); |
|
516 val(ParamStr(7), cInitVolume); |
|
517 isMusicEnabled:= ParamStr(8) = '1'; |
|
518 isSoundEnabled:= ParamStr(9) = '1'; |
|
519 cLocaleFName:= ParamStr(10); |
|
520 cFullScreen:= ParamStr(11) = '1'; |
|
521 end |
|
522 else GameType:= gmtSyntax; |
|
523 end; |
|
524 15: begin |
|
525 PathPrefix:= ParamStr(1); |
|
526 recordFileName:= ParamStr(2); |
|
527 if ParamStr(3) = '--set-everything' then |
|
528 begin |
|
529 val(ParamStr(4), cScreenWidth); |
|
530 val(ParamStr(5), cScreenHeight); |
|
531 cBitsStr:= ParamStr(6); |
|
532 val(cBitsStr, cBits); |
|
533 val(ParamStr(7), cInitVolume); |
|
534 isMusicEnabled:= ParamStr(8) = '1'; |
|
535 isSoundEnabled:= ParamStr(9) = '1'; |
|
536 cLocaleFName:= ParamStr(10); |
|
537 cFullScreen:= ParamStr(11) = '1'; |
|
538 cAltDamage:= ParamStr(12) = '1'; |
|
539 cShowFPS:= ParamStr(13) = '1'; |
|
540 val(ParamStr(14), cTimerInterval); |
|
541 if (ParamStr(15) = '1') then //HACK |
|
542 cReducedQuality:= $FFFFFFFF xor rqLowRes |
|
543 else |
|
544 val(ParamStr(15), cReducedQuality); |
|
545 end |
|
546 else GameType:= gmtSyntax; |
|
547 end; |
|
548 else GameType:= gmtSyntax; |
|
549 end; |
|
550 end; |
455 end; |
551 |
456 |
552 //////////////////////////////////////////////////////////////////////////////// |
457 //////////////////////////////////////////////////////////////////////////////// |
553 /////////////////////////////// m a i n //////////////////////////////////////// |
458 /////////////////////////////// m a i n //////////////////////////////////////// |
554 //////////////////////////////////////////////////////////////////////////////// |
459 //////////////////////////////////////////////////////////////////////////////// |