author | nemo |
Tue, 02 Jun 2009 18:27:15 +0000 | |
changeset 2143 | ad05f6b2d1c0 |
parent 2142 | 48ed98cfd119 |
child 2144 | c76a2f7bd452 |
permissions | -rw-r--r-- |
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, |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
28 |
sidLowGravity, sidExtraDamage, sidInvulnerable, sidExtraTime, |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
29 |
sidLaserSight, sidVampiric, sidSniperRifle); |
285 | 30 |
|
1263 | 31 |
TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused, |
32 |
sidConfirm, sidSuddenDeath); |
|
2140 | 33 |
|
2143
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
34 |
TEventId = (eidDied, eidDrowned, eidRoundStart, eidRoundWin, eidRoundDraw, |
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
35 |
eidNewHealthPack, eidNewAmmoPack, eidNewUtilityPack, eidTurnSkipped, eidHurtSelf); |
285 | 36 |
|
2142 | 37 |
const MAX_EVENT_STRINGS = 100; |
184 | 38 |
var trammo: array[TAmmoStrId] of string; |
39 |
trmsg: array[TMsgStrId] of string; |
|
40 |
||
41 |
procedure LoadLocale(FileName: string); |
|
42 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
|
43 |
||
2140 | 44 |
function GetEventString(e: TEventId): string; |
45 |
||
184 | 46 |
implementation |
2142 | 47 |
uses uMisc, uRandom; |
48 |
||
49 |
var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of string; |
|
50 |
trevt_n: array[TEventId] of integer; |
|
184 | 51 |
|
52 |
procedure LoadLocale(FileName: string); |
|
53 |
var s: shortstring; |
|
54 |
f: textfile; |
|
371 | 55 |
a, b, c: LongInt; |
2143
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
56 |
first: array[TEventId] of boolean; |
184 | 57 |
begin |
2140 | 58 |
|
59 |
// clear event locales |
|
2143
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
60 |
//for a:= 0 to ord(High(TEventId)) do trevt_n[TEventId(a)]:= 0; |
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
61 |
|
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
62 |
for a:= ord(Low(TEventId)) to ord(High(TEventId)) do first[TEventId(a)]:= true; |
2140 | 63 |
|
184 | 64 |
{$I-} |
351 | 65 |
Assign(f, FileName); |
184 | 66 |
reset(f); |
67 |
TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', true); |
|
68 |
while not eof(f) do |
|
1263 | 69 |
begin |
70 |
readln(f, s); |
|
71 |
if Length(s) = 0 then continue; |
|
2039 | 72 |
if not (s[1] in ['0'..'9']) then continue; |
1263 | 73 |
TryDo(Length(s) > 6, 'Load locale: empty string', true); |
74 |
val(s[1]+s[2], a, c); |
|
75 |
TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
|
76 |
TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
|
77 |
val(s[4]+s[5], b, c); |
|
78 |
TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
|
79 |
TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
|
80 |
Delete(s, 1, 6); |
|
81 |
case a of |
|
82 |
0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s; |
|
83 |
1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; |
|
2140 | 84 |
2: if (b >=0) and (b <= ord(High(TEventId))) then begin |
2143
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
85 |
TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false); |
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
86 |
if first[TEventId(b)] then |
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
87 |
begin |
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
88 |
trevt_n[TEventId(b)]:= 0; |
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
89 |
first[TEventId(b)]:= false; |
ad05f6b2d1c0
New baseball bat sound, steam when fire lands on water (needs new hiss sound), bubbles when hedgehog drowns, more messages on
nemo
parents:
2142
diff
changeset
|
90 |
end; |
2142 | 91 |
trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
2140 | 92 |
inc(trevt_n[TEventId(b)]); |
93 |
end; |
|
1263 | 94 |
end; |
95 |
end; |
|
351 | 96 |
Close(f) |
184 | 97 |
{$I+} |
98 |
end; |
|
99 |
||
2140 | 100 |
function GetEventString(e: TEventId): string; |
101 |
begin |
|
102 |
if trevt_n[e] = 0 then // no messages for this event type? |
|
103 |
GetEventString:= '*missing translation*' |
|
104 |
else |
|
2142 | 105 |
GetEventString:= trevt[e][GetRandom(trevt_n[e])]; // Pick a random message and return it |
2140 | 106 |
end; |
107 |
||
184 | 108 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
371 | 109 |
var i: LongInt; |
184 | 110 |
begin |
111 |
i:= Pos('%1', fmt); |
|
351 | 112 |
if i = 0 then Format:= fmt |
113 |
else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
|
184 | 114 |
end; |
115 |
||
116 |
end. |