author | nemo |
Mon, 12 Oct 2009 19:40:01 +0000 | |
changeset 2435 | 7afc9edac4cf |
parent 2428 | 6800f8aa0184 |
child 2457 | ecf0c7e7995b |
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 |
|
2357
babe1a55e284
Add an empty weapon to avoid selection of weapons which aren't yet ready. Might all be useful to switch to amNothing in certain situations, like after using up all ropes, instead of bazooka.
nemo
parents:
2185
diff
changeset
|
21 |
type TAmmoStrId = (sidNothing, 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, |
|
2376 | 27 |
sidHellishBomb, sidDrill, sidBallgun, sidNapalm, sidRCPlane, |
28 |
sidLowGravity, sidExtraDamage, sidInvulnerable, sidExtraTime, |
|
2177
c045698e044f
Initial attempt at jetpack. Pluses, more like lunar lander (takes fall damage). Minuses, can't seem to cancel it or use alt weapon
nemo
parents:
2144
diff
changeset
|
29 |
sidLaserSight, sidVampiric, sidSniperRifle, sidJetpack); |
285 | 30 |
|
1263 | 31 |
TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused, |
2397
2ca4ca6b4bab
- Patch for "Syncronizing" message by Smaxx + some tweaks by me
unc0rr
parents:
2376
diff
changeset
|
32 |
sidConfirm, sidSuddenDeath, sidRemaining, sidFuel, sidSync); |
2376 | 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, |
2428 | 35 |
eidNewHealthPack, eidNewAmmoPack, eidNewUtilityPack, eidTurnSkipped, eidHurtSelf, |
36 |
eidHomerun); |
|
285 | 37 |
|
2142 | 38 |
const MAX_EVENT_STRINGS = 100; |
184 | 39 |
var trammo: array[TAmmoStrId] of string; |
40 |
trmsg: array[TMsgStrId] of string; |
|
41 |
||
42 |
procedure LoadLocale(FileName: string); |
|
43 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
|
44 |
||
2140 | 45 |
function GetEventString(e: TEventId): string; |
46 |
||
184 | 47 |
implementation |
2142 | 48 |
uses uMisc, uRandom; |
49 |
||
50 |
var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of string; |
|
51 |
trevt_n: array[TEventId] of integer; |
|
184 | 52 |
|
53 |
procedure LoadLocale(FileName: string); |
|
54 |
var s: shortstring; |
|
55 |
f: textfile; |
|
371 | 56 |
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
|
57 |
first: array[TEventId] of boolean; |
2144 | 58 |
e: TEventId; |
184 | 59 |
begin |
2357
babe1a55e284
Add an empty weapon to avoid selection of weapons which aren't yet ready. Might all be useful to switch to amNothing in certain situations, like after using up all ropes, instead of bazooka.
nemo
parents:
2185
diff
changeset
|
60 |
trammo[sidNothing]:= ' '; |
2144 | 61 |
for e:= Low(TEventId) to High(TEventId) do first[e]:= true; |
2140 | 62 |
|
184 | 63 |
{$I-} |
351 | 64 |
Assign(f, FileName); |
184 | 65 |
reset(f); |
66 |
TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', true); |
|
67 |
while not eof(f) do |
|
1263 | 68 |
begin |
69 |
readln(f, s); |
|
70 |
if Length(s) = 0 then continue; |
|
2039 | 71 |
if not (s[1] in ['0'..'9']) then continue; |
1263 | 72 |
TryDo(Length(s) > 6, 'Load locale: empty string', true); |
73 |
val(s[1]+s[2], a, c); |
|
74 |
TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
|
75 |
TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
|
76 |
val(s[4]+s[5], b, c); |
|
77 |
TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
|
78 |
TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
|
79 |
Delete(s, 1, 6); |
|
80 |
case a of |
|
2357
babe1a55e284
Add an empty weapon to avoid selection of weapons which aren't yet ready. Might all be useful to switch to amNothing in certain situations, like after using up all ropes, instead of bazooka.
nemo
parents:
2185
diff
changeset
|
81 |
0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s; |
1263 | 82 |
1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; |
2140 | 83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
end; |
2142 | 90 |
trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
2140 | 91 |
inc(trevt_n[TEventId(b)]); |
92 |
end; |
|
1263 | 93 |
end; |
94 |
end; |
|
351 | 95 |
Close(f) |
184 | 96 |
{$I+} |
97 |
end; |
|
98 |
||
2140 | 99 |
function GetEventString(e: TEventId): string; |
100 |
begin |
|
101 |
if trevt_n[e] = 0 then // no messages for this event type? |
|
102 |
GetEventString:= '*missing translation*' |
|
103 |
else |
|
2142 | 104 |
GetEventString:= trevt[e][GetRandom(trevt_n[e])]; // Pick a random message and return it |
2140 | 105 |
end; |
106 |
||
184 | 107 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
371 | 108 |
var i: LongInt; |
184 | 109 |
begin |
110 |
i:= Pos('%1', fmt); |
|
351 | 111 |
if i = 0 then Format:= fmt |
112 |
else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
|
184 | 113 |
end; |
114 |
||
115 |
end. |