author | unc0rr |
Sun, 07 Nov 2010 20:29:25 +0300 | |
changeset 4179 | 3e582f6b7b41 |
parent 4132 | ca33a3737064 |
child 4246 | e5cb885492df |
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, |
3963
6090d2a2472e
New Weapon: Resurrector (TODO: ammo icon + sprites)
Tobias Neumann <mail@tobias-neumann.eu>
parents:
3926
diff
changeset
|
33 |
sidSMine, sidHammer, sidResurrector); |
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, |
4132 | 46 |
gidDamageModifier, gidResetHealth, gidAISurvival, gidInfAttack, gidResetWeps, gidPerHogAmmo); |
2863 | 47 |
|
2142 | 48 |
const MAX_EVENT_STRINGS = 100; |
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
49 |
var trammo: array[TAmmoStrId] of ansistring; // name of the weapon |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
50 |
trammoc: array[TAmmoStrId] of ansistring; // caption of the weapon |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
51 |
trammod: array[TAmmoStrId] of ansistring; // description of the weapon |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
52 |
trmsg: array[TMsgStrId] of ansistring; // message of the event |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
53 |
trgoal: array[TGoalStrId] of ansistring; // message of the goal |
184 | 54 |
|
2905 | 55 |
procedure LoadLocale(FileName: shortstring); |
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
56 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
57 |
function Format(fmt: ansistring; var arg: ansistring): ansistring; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
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 |
||
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
146 |
procedure LoadLocaleWrapper(str: pchar); cdecl; export; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
147 |
begin |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
148 |
LoadLocale(Strpas(str)); |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
149 |
end; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3774
diff
changeset
|
150 |
|
184 | 151 |
end. |