author | smaxx |
Thu, 26 Aug 2010 22:41:36 +0200 | |
changeset 3776 | 28849f5a03c9 |
parent 3774 | af0e68ca273e |
child 3926 | 668b71f31e51 |
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 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
184 | 21 |
unit uLocale; |
22 |
interface |
|
3080 | 23 |
type TAmmoStrId = (sidNothing, sidGrenade, sidClusterBomb, sidBazooka, sidBee, sidShotgun, |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
24 |
sidPickHammer, sidSkip, sidRope, sidMine, sidDEagle, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
25 |
sidDynamite, sidBaseballBat, sidFirePunch, sidSeconds, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
26 |
sidParachute, sidAirAttack, sidMineStrike, sidBlowTorch, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
27 |
sidGirder, sidTeleport, sidSwitch, sidMortar, sidWhip, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
28 |
sidKamikaze, sidCake, sidSeduction, sidWatermelon, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
29 |
sidHellishBomb, sidDrill, sidBallgun, sidNapalm, sidRCPlane, |
2376 | 30 |
sidLowGravity, sidExtraDamage, sidInvulnerable, sidExtraTime, |
3350 | 31 |
sidLaserSight, sidVampiric, sidSniperRifle, sidJetpack, |
3710 | 32 |
sidMolotov, sidBirdy, sidPortalGun, sidPiano, sidGasBomb, sidSineGun, sidFlamethrower, |
3717 | 33 |
sidSMine, sidHammer); |
285 | 34 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
35 |
TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
36 |
sidConfirm, sidSuddenDeath, sidRemaining, sidFuel, sidSync, |
3774 | 37 |
sidNoEndTurn, sidNotYetAvailable, sidRoundSD, sidRoundsSD, sidReady); |
2376 | 38 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
39 |
TEventId = (eidDied, eidDrowned, eidRoundStart, eidRoundWin, eidRoundDraw, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
40 |
eidNewHealthPack, eidNewAmmoPack, eidNewUtilityPack, eidTurnSkipped, eidHurtSelf, |
3310 | 41 |
eidHomerun, eidGone); |
285 | 42 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
43 |
TGoalStrId = (gidCaption, gidSubCaption, gidForts, gidLowGravity, gidInvulnerable, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
44 |
gidVampiric, gidKarma, gidKing, gidPlaceHog, gidArtillery, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
45 |
gidSolidLand, gidSharedAmmo, gidMineTimer, gidNoMineTimer, gidRandomMineTimer, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
46 |
gidDamageModifier); |
2863 | 47 |
|
2142 | 48 |
const MAX_EVENT_STRINGS = 100; |
2905 | 49 |
var trammo: array[TAmmoStrId] of ansistring; |
50 |
trammoc: array[TAmmoStrId] of ansistring; |
|
51 |
trammod: array[TAmmoStrId] of ansistring; |
|
52 |
trmsg: array[TMsgStrId] of ansistring; |
|
53 |
trgoal: array[TGoalStrId] of ansistring; |
|
184 | 54 |
|
2905 | 55 |
procedure LoadLocale(FileName: shortstring); |
184 | 56 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
2905 | 57 |
function Format(fmt: ansistring; var arg: ansistring): ansistring; |
184 | 58 |
|
2905 | 59 |
function GetEventString(e: TEventId): ansistring; |
2140 | 60 |
|
184 | 61 |
implementation |
3407 | 62 |
uses uMisc, uRandom; |
2142 | 63 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
64 |
var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of ansistring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
65 |
trevt_n: array[TEventId] of integer; |
184 | 66 |
|
2905 | 67 |
procedure LoadLocale(FileName: shortstring); |
2999 | 68 |
var s: ansistring; |
184 | 69 |
f: textfile; |
371 | 70 |
a, b, c: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
71 |
first: array[TEventId] of boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
72 |
e: TEventId; |
2722 | 73 |
loaded: boolean; |
184 | 74 |
begin |
2722 | 75 |
loaded:= false; |
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
|
76 |
trammo[sidNothing]:= ' '; |
2144 | 77 |
for e:= Low(TEventId) to High(TEventId) do first[e]:= true; |
2140 | 78 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2693
diff
changeset
|
79 |
{$I-} // iochecks off |
2747 | 80 |
Assign(f, FileName); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2693
diff
changeset
|
81 |
filemode:= 0; // readonly |
2747 | 82 |
Reset(f); |
2722 | 83 |
if IOResult = 0 then loaded:= true; |
84 |
TryDo(loaded, 'Cannot load locale "' + FileName + '"', false); |
|
85 |
if loaded then |
|
86 |
begin |
|
87 |
while not eof(f) do |
|
88 |
begin |
|
89 |
readln(f, s); |
|
90 |
if Length(s) = 0 then continue; |
|
91 |
if not (s[1] in ['0'..'9']) then continue; |
|
92 |
TryDo(Length(s) > 6, 'Load locale: empty string', true); |
|
93 |
val(s[1]+s[2], a, c); |
|
94 |
TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
|
95 |
TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
|
96 |
val(s[4]+s[5], b, c); |
|
97 |
TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
|
98 |
TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
|
99 |
Delete(s, 1, 6); |
|
100 |
case a of |
|
101 |
0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s; |
|
102 |
1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; |
|
103 |
2: if (b >=0) and (b <= ord(High(TEventId))) then begin |
|
104 |
TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false); |
|
105 |
if first[TEventId(b)] then |
|
106 |
begin |
|
107 |
trevt_n[TEventId(b)]:= 0; |
|
108 |
first[TEventId(b)]:= false; |
|
109 |
end; |
|
110 |
trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
|
111 |
inc(trevt_n[TEventId(b)]); |
|
112 |
end; |
|
2747 | 113 |
3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammoc[TAmmoStrId(b+1)]:= s; |
114 |
4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammod[TAmmoStrId(b+1)]:= s; |
|
2863 | 115 |
5: if (b >=0) and (b <= ord(High(TGoalStrId))) then trgoal[TGoalStrId(b)]:= s; |
2722 | 116 |
end; |
117 |
end; |
|
118 |
Close(f) |
|
119 |
end; |
|
184 | 120 |
{$I+} |
121 |
end; |
|
122 |
||
2905 | 123 |
function GetEventString(e: TEventId): ansistring; |
2140 | 124 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
125 |
if trevt_n[e] = 0 then // no messages for this event type? |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
126 |
GetEventString:= '*missing translation*' |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
127 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
128 |
GetEventString:= trevt[e][GetRandom(trevt_n[e])]; // Pick a random message and return it |
2140 | 129 |
end; |
130 |
||
184 | 131 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
371 | 132 |
var i: LongInt; |
184 | 133 |
begin |
134 |
i:= Pos('%1', fmt); |
|
351 | 135 |
if i = 0 then Format:= fmt |
136 |
else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
|
184 | 137 |
end; |
138 |
||
2905 | 139 |
function Format(fmt: ansistring; var arg: ansistring): ansistring; |
140 |
var i: LongInt; |
|
141 |
begin |
|
142 |
i:= Pos('%1', fmt); |
|
143 |
if i = 0 then Format:= fmt |
|
144 |
else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
|
145 |
end; |
|
146 |
||
184 | 147 |
end. |