# HG changeset patch # User unc0rr # Date 1243888725 0 # Node ID 48ed98cfd1195955a3358674e0f25c56f85b7a11 # Parent 3b06505dbd5d4e1287773926f275078c0d0e01ea Make code suck less diff -r 3b06505dbd5d -r 48ed98cfd119 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Mon Jun 01 18:30:48 2009 +0000 +++ b/hedgewars/GSHandlers.inc Mon Jun 01 20:38:45 2009 +0000 @@ -41,7 +41,7 @@ CheckGearDrowning:= true; Gear^.State:= gstDrowning; Gear^.doStep:= @doStepDrowningGear; - if Gear^.Kind = gtHedgehog then AddCaption(Format(GetEventString(eidDrowned), PHedgehog(Gear^.Hedgehog)^.Name), $FFFFFF, capgrpGameState); + if Gear^.Kind = gtHedgehog then AddCaption(Format(GetEventString(eidDrowned), PHedgehog(Gear^.Hedgehog)^.Name), $FFFFFF, capgrpMessage); end; PlaySound(sndSplash, false, nil) end diff -r 3b06505dbd5d -r 48ed98cfd119 hedgewars/HHHandlers.inc --- a/hedgewars/HHHandlers.inc Mon Jun 01 18:30:48 2009 +0000 +++ b/hedgewars/HHHandlers.inc Mon Jun 01 20:38:45 2009 +0000 @@ -685,7 +685,7 @@ AllInactive:= false; // Death message - AddCaption(Format(GetEventString(eidDied), PHedgehog(Gear^.Hedgehog)^.Name), $FFFFFF, capgrpGameState); + AddCaption(Format(GetEventString(eidDied), PHedgehog(Gear^.Hedgehog)^.Name), $FFFFFF, capgrpMessage); end; exit end; diff -r 3b06505dbd5d -r 48ed98cfd119 hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Mon Jun 01 18:30:48 2009 +0000 +++ b/hedgewars/uConsts.pas Mon Jun 01 20:38:45 2009 +0000 @@ -102,7 +102,8 @@ THWFont = (fnt16, fntBig, fntSmall); - TCapGroup = (capgrpGameState, capgrpAmmoinfo, capgrpNetSay, capgrpVolume); + TCapGroup = (capgrpGameState, capgrpAmmoinfo, capgrpVolume, + capgrpMessage); TStatInfoType = (siGameResult, siMaxStepDamage, siMaxStepKills, siKilledHHs, siClanHealth); diff -r 3b06505dbd5d -r 48ed98cfd119 hedgewars/uLocale.pas --- a/hedgewars/uLocale.pas Mon Jun 01 18:30:48 2009 +0000 +++ b/hedgewars/uLocale.pas Mon Jun 01 20:38:45 2009 +0000 @@ -33,10 +33,10 @@ TEventId = (eidDied, eidDrowned, eidRoundStart); +const MAX_EVENT_STRINGS = 100; + var trammo: array[TAmmoStrId] of string; trmsg: array[TMsgStrId] of string; - trevt: array[TEventId] of array[1..100] of string; - trevt_n: array[TEventId] of integer; procedure LoadLocale(FileName: string); function Format(fmt: shortstring; var arg: shortstring): shortstring; @@ -44,16 +44,20 @@ function GetEventString(e: TEventId): string; implementation -uses uMisc; +uses uMisc, uRandom; + +var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of string; + trevt_n: array[TEventId] of integer; procedure LoadLocale(FileName: string); var s: shortstring; f: textfile; a, b, c: LongInt; + e: TEventId; begin // clear event locales -for a:= 0 to ord(High(TEventId)) do trevt_n[TEventId(a)]:= 0; +for e:= Low(TEventId) to High(TEventId) do trevt_n[e]:= 0; {$I-} Assign(f, FileName); @@ -76,8 +80,9 @@ 0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s; 1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; 2: if (b >=0) and (b <= ord(High(TEventId))) then begin + TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings', true); + trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; inc(trevt_n[TEventId(b)]); - trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; end; end; end; @@ -90,7 +95,7 @@ if trevt_n[e] = 0 then // no messages for this event type? GetEventString:= '*missing translation*' else - GetEventString:= trevt[e][Random(trevt_n[e]) + 1]; // Pick a random message and return it + GetEventString:= trevt[e][GetRandom(trevt_n[e])]; // Pick a random message and return it end; function Format(fmt: shortstring; var arg: shortstring): shortstring; diff -r 3b06505dbd5d -r 48ed98cfd119 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Mon Jun 01 18:30:48 2009 +0000 +++ b/hedgewars/uWorld.pas Mon Jun 01 20:38:45 2009 +0000 @@ -446,11 +446,16 @@ procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); begin -if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); +//if Group in [capgrpGameState] then WriteLnToConsole(s); if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex); Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); -Captions[Group].EndTime:= RealTicks + 1500 + +case Group of + capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200 + else + Captions[Group].EndTime:= RealTicks + 1570 + end; end; procedure MoveCamera;