hedgewars/uLocale.pas
branchexperimental3D
changeset 4812 f924be23ffb4
parent 4807 180dbfb13903
child 4976 088d40d8aba2
equal deleted inserted replaced
4347:0ddb100fea61 4812:f924be23ffb4
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uLocale;
    21 unit uLocale;
    22 interface
    22 interface
    23 type TAmmoStrId = (sidNothing, sidGrenade, sidClusterBomb, sidBazooka, sidBee, sidShotgun,
    23 uses uTypes;
    24             sidPickHammer, sidSkip, sidRope, sidMine, sidDEagle,
       
    25             sidDynamite, sidBaseballBat, sidFirePunch, sidSeconds,
       
    26             sidParachute, sidAirAttack, sidMineStrike, sidBlowTorch,
       
    27             sidGirder, sidTeleport, sidSwitch, sidMortar, sidWhip,
       
    28             sidKamikaze, sidCake, sidSeduction, sidWatermelon,
       
    29             sidHellishBomb, sidDrill, sidBallgun, sidNapalm, sidRCPlane,
       
    30             sidLowGravity, sidExtraDamage, sidInvulnerable, sidExtraTime,
       
    31             sidLaserSight, sidVampiric, sidSniperRifle, sidJetpack,
       
    32             sidMolotov, sidBirdy, sidPortalGun, sidPiano, sidGasBomb, sidSineGun, sidFlamethrower,
       
    33             sidSMine, sidHammer, sidResurrector, sidDrillStrike);
       
    34 
       
    35     TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused,
       
    36             sidConfirm, sidSuddenDeath, sidRemaining, sidFuel, sidSync,
       
    37             sidNoEndTurn, sidNotYetAvailable, sidRoundSD, sidRoundsSD, sidReady);
       
    38 
       
    39     TEventId = (eidDied, eidDrowned, eidRoundStart, eidRoundWin, eidRoundDraw,
       
    40             eidNewHealthPack, eidNewAmmoPack, eidNewUtilityPack, eidTurnSkipped, eidHurtSelf,
       
    41             eidHomerun, eidGone);
       
    42 
       
    43     TGoalStrId = (gidCaption, gidSubCaption, gidForts, gidLowGravity, gidInvulnerable,
       
    44             gidVampiric, gidKarma, gidKing, gidPlaceHog, gidArtillery,
       
    45             gidSolidLand, gidSharedAmmo, gidMineTimer, gidNoMineTimer, gidRandomMineTimer,
       
    46             gidDamageModifier, gidResetHealth, gidAISurvival, gidInfAttack, gidResetWeps, gidPerHogAmmo);
       
    47 
    24 
    48 const MAX_EVENT_STRINGS = 100;
    25 const MAX_EVENT_STRINGS = 100;
    49 var trammo:  array[TAmmoStrId] of ansistring;   // name of the weapon
       
    50     trammoc: array[TAmmoStrId] of ansistring;   // caption of the weapon
       
    51     trammod: array[TAmmoStrId] of ansistring;   // description of the weapon
       
    52     trmsg:   array[TMsgStrId]  of ansistring;   // message of the event
       
    53     trgoal:  array[TGoalStrId] of ansistring;   // message of the goal
       
    54 
    26 
    55 procedure LoadLocale(FileName: shortstring);
    27 procedure LoadLocale(FileName: shortstring);
    56 function  Format(fmt: shortstring; var arg: shortstring): shortstring;
    28 function  Format(fmt: shortstring; var arg: shortstring): shortstring;
    57 function  Format(fmt: ansistring; var arg: ansistring): ansistring;
    29 function  Format(fmt: ansistring; var arg: ansistring): ansistring;
    58 function  GetEventString(e: TEventId): ansistring;
    30 function  GetEventString(e: TEventId): ansistring;
    59 
    31 
    60 implementation
    32 implementation
    61 uses uMisc, uRandom;
    33 uses uRandom, uUtils, uVariables, uDebug;
    62 
    34 
    63 var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of ansistring;
    35 var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of ansistring;
    64     trevt_n: array[TEventId] of integer;
    36     trevt_n: array[TEventId] of integer;
    65 
    37 
    66 procedure LoadLocale(FileName: shortstring);
    38 procedure LoadLocale(FileName: shortstring);
    70     first: array[TEventId] of boolean;
    42     first: array[TEventId] of boolean;
    71     e: TEventId;
    43     e: TEventId;
    72     loaded: boolean;
    44     loaded: boolean;
    73 begin
    45 begin
    74 loaded:= false;
    46 loaded:= false;
    75 trammo[sidNothing]:= ' ';
       
    76 for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
    47 for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
    77 
    48 
    78 {$I-} // iochecks off
    49 {$I-} // iochecks off
    79 Assign(f, FileName);
    50 Assign(f, FileName);
    80 filemode:= 0; // readonly
    51 filemode:= 0; // readonly
    95        val(s[4]+s[5], b, c);
    66        val(s[4]+s[5], b, c);
    96        TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true);
    67        TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true);
    97        TryDo(s[6] = '=', 'Load locale: "=" expected', true);
    68        TryDo(s[6] = '=', 'Load locale: "=" expected', true);
    98        Delete(s, 1, 6);
    69        Delete(s, 1, 6);
    99        case a of
    70        case a of
   100            0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s;
    71            0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s;
   101            1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s;
    72            1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s;
   102            2: if (b >=0) and (b <= ord(High(TEventId))) then begin
    73            2: if (b >=0) and (b <= ord(High(TEventId))) then begin
   103                TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false);
    74                TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false);
   104                if first[TEventId(b)] then
    75                if first[TEventId(b)] then
   105                    begin
    76                    begin
   106                    trevt_n[TEventId(b)]:= 0;
    77                    trevt_n[TEventId(b)]:= 0;
   107                    first[TEventId(b)]:= false;
    78                    first[TEventId(b)]:= false;
   108                    end;
    79                    end;
   109                trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s;
    80                trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s;
   110                inc(trevt_n[TEventId(b)]);
    81                inc(trevt_n[TEventId(b)]);
   111                end;
    82                end;
   112            3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammoc[TAmmoStrId(b+1)]:= s;
    83            3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammoc[TAmmoStrId(b)]:= s;
   113            4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammod[TAmmoStrId(b+1)]:= s;
    84            4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammod[TAmmoStrId(b)]:= s;
   114            5: if (b >=0) and (b <= ord(High(TGoalStrId))) then trgoal[TGoalStrId(b)]:= s;
    85            5: if (b >=0) and (b <= ord(High(TGoalStrId))) then trgoal[TGoalStrId(b)]:= s;
   115            end;
    86            end;
   116        end;
    87        end;
   117    Close(f)
    88    Close(f)
   118    end;
    89    end;