author | sheepluva |
Sun, 16 May 2010 23:43:45 +0000 | |
changeset 3468 | c7b80bdbc384 |
parent 3407 | dcc129c4352e |
child 3476 | 1ec68b8d3bd1 |
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, |
3384 | 32 |
sidMolotov, sidBirdy, sidPortalGun, sidPiano, sidGasBomb, sidSineGun); |
285 | 33 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
34 |
TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
35 |
sidConfirm, sidSuddenDeath, sidRemaining, sidFuel, sidSync, |
3331 | 36 |
sidNoEndTurn, sidNotYetAvailable, sidRoundSD, sidRoundsSD); |
2376 | 37 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
38 |
TEventId = (eidDied, eidDrowned, eidRoundStart, eidRoundWin, eidRoundDraw, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
39 |
eidNewHealthPack, eidNewAmmoPack, eidNewUtilityPack, eidTurnSkipped, eidHurtSelf, |
3310 | 40 |
eidHomerun, eidGone); |
285 | 41 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
42 |
TGoalStrId = (gidCaption, gidSubCaption, gidForts, gidLowGravity, gidInvulnerable, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
43 |
gidVampiric, gidKarma, gidKing, gidPlaceHog, gidArtillery, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
44 |
gidSolidLand, gidSharedAmmo, gidMineTimer, gidNoMineTimer, gidRandomMineTimer, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
45 |
gidDamageModifier); |
2863 | 46 |
|
2142 | 47 |
const MAX_EVENT_STRINGS = 100; |
2905 | 48 |
var trammo: array[TAmmoStrId] of ansistring; |
49 |
trammoc: array[TAmmoStrId] of ansistring; |
|
50 |
trammod: array[TAmmoStrId] of ansistring; |
|
51 |
trmsg: array[TMsgStrId] of ansistring; |
|
52 |
trgoal: array[TGoalStrId] of ansistring; |
|
184 | 53 |
|
2905 | 54 |
procedure LoadLocale(FileName: shortstring); |
184 | 55 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
2905 | 56 |
function Format(fmt: ansistring; var arg: ansistring): ansistring; |
184 | 57 |
|
2905 | 58 |
function GetEventString(e: TEventId): ansistring; |
2140 | 59 |
|
184 | 60 |
implementation |
3407 | 61 |
uses uMisc, uRandom; |
2142 | 62 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
63 |
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
|
64 |
trevt_n: array[TEventId] of integer; |
184 | 65 |
|
2905 | 66 |
procedure LoadLocale(FileName: shortstring); |
2999 | 67 |
var s: ansistring; |
184 | 68 |
f: textfile; |
371 | 69 |
a, b, c: LongInt; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
70 |
first: array[TEventId] of boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
71 |
e: TEventId; |
2722 | 72 |
loaded: boolean; |
184 | 73 |
begin |
2722 | 74 |
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
|
75 |
trammo[sidNothing]:= ' '; |
2144 | 76 |
for e:= Low(TEventId) to High(TEventId) do first[e]:= true; |
2140 | 77 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2693
diff
changeset
|
78 |
{$I-} // iochecks off |
2747 | 79 |
Assign(f, FileName); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2693
diff
changeset
|
80 |
filemode:= 0; // readonly |
2747 | 81 |
Reset(f); |
2722 | 82 |
if IOResult = 0 then loaded:= true; |
83 |
TryDo(loaded, 'Cannot load locale "' + FileName + '"', false); |
|
84 |
if loaded then |
|
85 |
begin |
|
86 |
while not eof(f) do |
|
87 |
begin |
|
88 |
readln(f, s); |
|
89 |
if Length(s) = 0 then continue; |
|
90 |
if not (s[1] in ['0'..'9']) then continue; |
|
91 |
TryDo(Length(s) > 6, 'Load locale: empty string', true); |
|
92 |
val(s[1]+s[2], a, c); |
|
93 |
TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); |
|
94 |
TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
|
95 |
val(s[4]+s[5], b, c); |
|
96 |
TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); |
|
97 |
TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
|
98 |
Delete(s, 1, 6); |
|
99 |
case a of |
|
100 |
0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s; |
|
101 |
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 |
|
103 |
TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false); |
|
104 |
if first[TEventId(b)] then |
|
105 |
begin |
|
106 |
trevt_n[TEventId(b)]:= 0; |
|
107 |
first[TEventId(b)]:= false; |
|
108 |
end; |
|
109 |
trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; |
|
110 |
inc(trevt_n[TEventId(b)]); |
|
111 |
end; |
|
2747 | 112 |
3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammoc[TAmmoStrId(b+1)]:= s; |
113 |
4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammod[TAmmoStrId(b+1)]:= s; |
|
2863 | 114 |
5: if (b >=0) and (b <= ord(High(TGoalStrId))) then trgoal[TGoalStrId(b)]:= s; |
2722 | 115 |
end; |
116 |
end; |
|
117 |
Close(f) |
|
118 |
end; |
|
184 | 119 |
{$I+} |
120 |
end; |
|
121 |
||
2905 | 122 |
function GetEventString(e: TEventId): ansistring; |
2140 | 123 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
124 |
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
|
125 |
GetEventString:= '*missing translation*' |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
126 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2908
diff
changeset
|
127 |
GetEventString:= trevt[e][GetRandom(trevt_n[e])]; // Pick a random message and return it |
2140 | 128 |
end; |
129 |
||
184 | 130 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
371 | 131 |
var i: LongInt; |
184 | 132 |
begin |
133 |
i:= Pos('%1', fmt); |
|
351 | 134 |
if i = 0 then Format:= fmt |
135 |
else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
|
184 | 136 |
end; |
137 |
||
2905 | 138 |
function Format(fmt: ansistring; var arg: ansistring): ansistring; |
139 |
var i: LongInt; |
|
140 |
begin |
|
141 |
i:= Pos('%1', fmt); |
|
142 |
if i = 0 then Format:= fmt |
|
143 |
else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
|
144 |
end; |
|
145 |
||
184 | 146 |
end. |