Make code suck less
authorunc0rr
Mon, 01 Jun 2009 20:38:45 +0000
changeset 2142 48ed98cfd119
parent 2141 3b06505dbd5d
child 2143 ad05f6b2d1c0
Make code suck less
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uConsts.pas
hedgewars/uLocale.pas
hedgewars/uWorld.pas
--- 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
--- 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;
--- 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);
--- 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;
--- 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;