184
|
1 |
(*
|
1066
|
2 |
* Hedgewars, a free turn based strategy game
|
925
|
3 |
* Copyright (c) 2006-2008 Andrey Korotaev <unC0Rr@gmail.com>
|
184
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
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
|
|
17 |
*)
|
|
18 |
|
|
19 |
unit uLocale;
|
|
20 |
interface
|
|
21 |
type TAmmoStrId = (sidGrenade, sidClusterBomb, sidBazooka, sidUFO, sidShotgun,
|
1263
|
22 |
sidPickHammer, sidSkip, sidRope, sidMine, sidDEagle,
|
|
23 |
sidDynamite, sidBaseballBat, sidFirePunch, sidSeconds,
|
|
24 |
sidParachute, sidAirAttack, sidMineStrike, sidBlowTorch,
|
|
25 |
sidGirder, sidTeleport, sidSwitch, sidMortar, sidWhip,
|
|
26 |
sidKamikaze, sidCake, sidSeduction, sidWatermelon,
|
1854
|
27 |
sidHellishBomb, sidDrill, sidBallgun, sidNapalm, sidRCPlane,
|
2017
|
28 |
sidLowGravity, sidExtraDamage, sidInvulnerable, sidExtraTime, sidLaserSight, sidVampiric);
|
285
|
29 |
|
1263
|
30 |
TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused,
|
|
31 |
sidConfirm, sidSuddenDeath);
|
285
|
32 |
|
184
|
33 |
var trammo: array[TAmmoStrId] of string;
|
|
34 |
trmsg: array[TMsgStrId] of string;
|
|
35 |
|
|
36 |
procedure LoadLocale(FileName: string);
|
|
37 |
function Format(fmt: shortstring; var arg: shortstring): shortstring;
|
|
38 |
|
|
39 |
implementation
|
|
40 |
uses uMisc;
|
|
41 |
|
|
42 |
procedure LoadLocale(FileName: string);
|
|
43 |
var s: shortstring;
|
|
44 |
f: textfile;
|
371
|
45 |
a, b, c: LongInt;
|
184
|
46 |
begin
|
|
47 |
{$I-}
|
351
|
48 |
Assign(f, FileName);
|
184
|
49 |
reset(f);
|
|
50 |
TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', true);
|
|
51 |
while not eof(f) do
|
1263
|
52 |
begin
|
|
53 |
readln(f, s);
|
|
54 |
if Length(s) = 0 then continue;
|
|
55 |
if s[1] = ';' then continue;
|
|
56 |
TryDo(Length(s) > 6, 'Load locale: empty string', true);
|
|
57 |
val(s[1]+s[2], a, c);
|
|
58 |
TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true);
|
|
59 |
TryDo(s[3] = ':', 'Load locale: ":" expected', true);
|
|
60 |
val(s[4]+s[5], b, c);
|
|
61 |
TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true);
|
|
62 |
TryDo(s[6] = '=', 'Load locale: "=" expected', true);
|
|
63 |
Delete(s, 1, 6);
|
|
64 |
case a of
|
|
65 |
0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s;
|
|
66 |
1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s;
|
|
67 |
end;
|
|
68 |
end;
|
351
|
69 |
Close(f)
|
184
|
70 |
{$I+}
|
|
71 |
end;
|
|
72 |
|
|
73 |
function Format(fmt: shortstring; var arg: shortstring): shortstring;
|
371
|
74 |
var i: LongInt;
|
184
|
75 |
begin
|
|
76 |
i:= Pos('%1', fmt);
|
351
|
77 |
if i = 0 then Format:= fmt
|
|
78 |
else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
|
184
|
79 |
end;
|
|
80 |
|
|
81 |
end.
|