Allow hog speech when not your turn. Currently is set to 40% opacity (could be fainter) and drawn behind the hogs instead of in front. Also allows hog targetting using a number.
authornemo
Sun, 05 Dec 2010 22:02:30 -0500
changeset 4465 743673c67d0c
parent 4464 04b4f0c2a2fc
child 4466 8ee58126f7bf
Allow hog speech when not your turn. Currently is set to 40% opacity (could be fainter) and drawn behind the hogs instead of in front. Also allows hog targetting using a number.
hedgewars/uChat.pas
hedgewars/uGears.pas
hedgewars/uTeams.pas
hedgewars/uVariables.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/uChat.pas	Mon Dec 06 03:09:12 2010 +0100
+++ b/hedgewars/uChat.pas	Sun Dec 05 22:02:30 2010 -0500
@@ -183,33 +183,40 @@
 
 procedure AcceptChatString(s: shortstring);
 var i: TWave;
-
+    c, t: LongInt;
 begin
+t:= LocalTeam;
+if not CurrentTeam^.ExtDriven and
+   ((s[1] = '"') and (s[Length(s)] = '"') or
+    (s[1] = '''') and (s[Length(s)] = '''') or
+    (s[1] = '-') and (s[Length(s)] = '-')) then
+    for c:= 0 to Pred(TeamsCount) do
+        if (TeamsArray[c] = CurrentTeam) then t:= c;
 // "Make hedgehog say something"
 if (s[1] = '"') and (s[Length(s)] = '"') then
     begin
-    if CurrentTeam^.ExtDriven then
+    if t = -1 then
         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
     else
-        ParseCommand('/hogsay '#1 + copy(s, 2, Length(s)-2), true);
+        ParseCommand('/hogsay '#1 + char(t) + copy(s, 2, Length(s)-2), true);
     exit
     end;
 // 'Make hedgehog think something'
 if (s[1] = '''') and (s[Length(s)] = '''') then
     begin
-    if CurrentTeam^.ExtDriven then
+    if t = -1 then
         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
     else
-        ParseCommand('/hogsay '#2 + copy(s, 2, Length(s)-2), true);
+        ParseCommand('/hogsay '#2 + char(t) + copy(s, 2, Length(s)-2), true);
     exit
     end;
 // -Make hedgehog yell something-
 if (s[1] = '-') and (s[Length(s)] = '-') then
     begin
-    if CurrentTeam^.ExtDriven then
+    if t = -1 then
         ParseCommand('/say ' + copy(s, 2, Length(s)-2), true)
     else
-        ParseCommand('/hogsay '#3 + copy(s, 2, Length(s)-2), true);
+        ParseCommand('/hogsay '#3 + char(t) + copy(s, 2, Length(s)-2), true);
     exit
     end;
 // These 3 are same as above, only are to make the hedgehog say it on next attack
--- a/hedgewars/uGears.pas	Mon Dec 06 03:09:12 2010 +0100
+++ b/hedgewars/uGears.pas	Sun Dec 05 22:02:30 2010 -0500
@@ -894,11 +894,13 @@
             for i:= 0 to cMaxHHIndex do
                 with Hedgehogs[i] do
                     begin
+(*
                     if (SpeechGear <> nil) then
                         begin
                         DeleteVisualGear(SpeechGear);  // remove to restore persisting beyond end of turn. Tiy says was too much of a gameplay issue
                         SpeechGear:= nil
                         end;
+*)
 
                     if (Gear <> nil) then
                         begin
@@ -1743,10 +1745,20 @@
 procedure chHogSay(var s: shortstring);
 var Gear: PVisualGear;
     text: shortstring;
+    hh: PHedgehog;
+    i, x, t, h: byte;
+    c, j: LongInt;
 begin
-    text:= copy(s, 2, Length(s) - 1);
-    if CheckNoTeamOrHH
-    or ((CurrentHedgehog^.Gear^.State and gstHHDriven) = 0) then
+    hh:= nil;
+    i:= 0;
+    x:= byte(s[1]);  // speech type
+    t:= byte(s[2]);  // team
+    h:= byte(s[3]);  // target hog
+    // allow targetting a hog by specifying a number as the first portion of the text
+    if (h > byte('0')) and (h < byte('9')) then i:= h - 48;
+    if i <> 0 then text:= copy(s, 4, Length(s) - 1)
+    else text:= copy(s, 3, Length(s) - 1);
+    if CheckNoTeamOrHH then
         begin
         ParseCommand('say ' + text, true);
         exit
@@ -1754,19 +1766,38 @@
 
     if not CurrentTeam^.ExtDriven then SendIPC('h' + s);
 
-    if byte(s[1]) < 4 then
+    if (x < 4) and (TeamsArray[t] <> nil) then
         begin
-        Gear:= AddVisualGear(0, 0, vgtSpeechBubble);
+            // if team matches current hedgehog team, default to current hedgehog
+            if (i = 0) and (CurrentHedgehog^.Team = TeamsArray[t]) then hh:= CurrentHedgehog
+            else 
+                begin
+            // otherwise use the first living hog or the hog amongs the remaining ones indicated by i
+                j:= 0;
+                c:= 0;
+                while (j <= cMaxHHIndex) and (hh = nil) do
+                    begin
+                    if (TeamsArray[t]^.Hedgehogs[j].Gear <> nil) then
+                        begin
+                        inc(c);
+                        if (i=0) or (i=c) then
+                            hh:= @TeamsArray[t]^.Hedgehogs[j]
+                        end;
+                    inc(j)
+                    end
+                end;
+        if hh <> nil then Gear:= AddVisualGear(0, 0, vgtSpeechBubble);
         if Gear <> nil then
             begin
-            Gear^.Hedgehog:= CurrentHedgehog;
+            Gear^.Hedgehog:= hh;
             Gear^.Text:= text;
-            Gear^.FrameTicks:= byte(s[1])
+            Gear^.FrameTicks:= x
             end
+        else ParseCommand('say ' + text, true)
         end
     else
         begin
-        SpeechType:= byte(s[1])-3;
+        SpeechType:= x-3;
         SpeechText:= text
         end;
 end;
--- a/hedgewars/uTeams.pas	Mon Dec 06 03:09:12 2010 +0100
+++ b/hedgewars/uTeams.pas	Sun Dec 05 22:02:30 2010 -0500
@@ -311,6 +311,7 @@
         if (not ExtDriven) and (Hedgehogs[0].BotLevel = 0) then
             begin
             LocalClan:= Clan^.ClanIndex;
+            LocalTeam:= t;
             LocalAmmo:= Hedgehogs[0].AmmoStore
             end;
         th:= 0;
@@ -521,6 +522,7 @@
     TeamsCount:= 0;
     ClansCount:= 0;
     LocalClan:= -1;
+    LocalTeam:= -1;
     LocalAmmo:= -1;
     GameOver:= false
 end;
--- a/hedgewars/uVariables.pas	Mon Dec 06 03:09:12 2010 +0100
+++ b/hedgewars/uVariables.pas	Sun Dec 05 22:02:30 2010 -0500
@@ -2021,7 +2021,8 @@
     ClansArray: array[0..Pred(cMaxTeams)] of PClan;
     ClansCount: Longword;
     LocalClan: LongInt;  // last non-bot, non-extdriven clan
-    LocalAmmo: LongInt;  // last non-bot, non-extdriven clan's first team's ammo index
+    LocalTeam: LongInt;  // last non-bot, non-extdriven clan first team
+    LocalAmmo: LongInt;  // last non-bot, non-extdriven clan's first team's ammo index, updated to next upcoming hog for per-hog-ammo
     CurMinAngle, CurMaxAngle: Longword;
     GameOver: boolean;
 
--- a/hedgewars/uVisualGears.pas	Mon Dec 06 03:09:12 2010 +0100
+++ b/hedgewars/uVisualGears.pas	Sun Dec 05 22:02:30 2010 -0500
@@ -395,6 +395,11 @@
             vgtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
             vgtEvilTrace: if Gear^.State < 8 then DrawSprite(sprEvilTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
             vgtLineTrail: DrawLine(Gear^.X, Gear^.Y, Gear^.dX, Gear^.dY, 1.0, $FF, min(Gear^.Timer, $C0), min(Gear^.Timer, $80), min(Gear^.Timer, $FF));
+            vgtSpeechBubble: if (Gear^.Hedgehog^.Team <> CurrentTeam) and (Gear^.Tex <> nil) then 
+                    begin
+                    Tint($FF, $FF, $FF,  $66);
+                    DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex)
+                    end
         end;
             if (cReducedQuality and rqFancyBoom) = 0 then
                 case Gear^.Kind of
@@ -470,7 +475,7 @@
             end;
         case Gear^.Kind of
             vgtSmallDamageTag: DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex);
-            vgtSpeechBubble: if Gear^.Tex <> nil then DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex);
+            vgtSpeechBubble: if (Gear^.Hedgehog^.Team = CurrentTeam) and (Gear^.Tex <> nil) then DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex);
             vgtHealthTag: if Gear^.Tex <> nil then DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex);
             vgtCircle: DrawCircle(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State, Gear^.Timer);
         end;