Triggers proof-of-concept
authorunc0rr
Fri, 14 Sep 2007 20:51:40 +0000
changeset 593 1f5e66379a43
parent 592 b1189f31e354
child 594 221ffeb92f30
Triggers proof-of-concept
QTfrontend/game.cpp
hedgewars/CCHandlers.inc
hedgewars/CMakeLists.txt
hedgewars/uGears.pas
hedgewars/uTriggers.pas
--- a/QTfrontend/game.cpp	Tue Sep 11 17:04:24 2007 +0000
+++ b/QTfrontend/game.cpp	Fri Sep 14 20:51:40 2007 +0000
@@ -136,8 +136,12 @@
 	team2.difficulty = 4;
 	team2.teamColor = QColor(16776960);
 	team2.numHedgehogs = 4;
-	RawSendIPC(HWProto::addStringListToBuffer(teamscfg,
-			team2.TeamGameConfig(100)));
+	HWProto::addStringListToBuffer(teamscfg,
+			team2.TeamGameConfig(100));
+
+	HWProto::addStringToBuffer(teamscfg, "eaddtrig 2147483649");
+
+	RawSendIPC(teamscfg);
 }
 
 void HWGame::SendNetConfig()
--- a/hedgewars/CCHandlers.inc	Tue Sep 11 17:04:24 2007 +0000
+++ b/hedgewars/CCHandlers.inc	Fri Sep 14 20:51:40 2007 +0000
@@ -263,6 +263,7 @@
 if AllInactive then
    begin
    if not CurrentTeam^.ExtDriven then SendIPC('N');
+   TickTrigger(trigTurns);
    {$IFDEF DEBUGFILE}AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));{$ENDIF}
    SwitchHedgehog;
    end
@@ -465,8 +466,8 @@
 end;
 
 procedure chAddTrigger(var s: shortstring);
-var t: integer;
+var t: LongWord;
 begin
 val(s, t);
-AddTrigger(t)
+AddTrigger(t, 1)
 end;
--- a/hedgewars/CMakeLists.txt	Tue Sep 11 17:04:24 2007 +0000
+++ b/hedgewars/CMakeLists.txt	Fri Sep 14 20:51:40 2007 +0000
@@ -31,6 +31,7 @@
 	uSound.pas
 	uStore.pas
 	uTeams.pas
+	uTriggers.pas
 	uWorld.pas
 	CCHandlers.inc
 	GSHandlers.inc
--- a/hedgewars/uGears.pas	Tue Sep 11 17:04:24 2007 +0000
+++ b/hedgewars/uGears.pas	Fri Sep 14 20:51:40 2007 +0000
@@ -69,7 +69,7 @@
 
 implementation
 uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions,
-     uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos;
+     uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers;
 var RopePoints: record
                 Count: Longword;
                 HookAngle: LongInt;
@@ -292,6 +292,9 @@
     gtSwitcher: begin
                 Result^.Z:= cCurrHHZ
                 end;
+      gtTarget: begin
+                Result^.Radius:= 16
+                end;
      end;
 InsertGearToList(Result);
 AddGear:= Result
@@ -608,6 +611,7 @@
                                      else DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 1, Surface);
          gtAirBomb: DrawSprite(sprAirBomb , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface);
         gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, 0, Surface);
+          gtTarget: DrawSprite(sprTarget, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0, Surface);
               end;
       Gear:= Gear^.NextGear
       end;
@@ -672,6 +676,7 @@
               gtHedgehog,
                   gtMine,
                   gtCase,
+                gtTarget,
                  gtFlame: begin
                           {$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
                           if (Mask and EXPLNoDamage) = 0 then
@@ -717,7 +722,8 @@
        case t^.Kind of
            gtHedgehog,
                gtMine,
-               gtCase: begin
+               gtCase,
+             gtTarget: begin
                        inc(t^.Damage, dmg);
                        if t^.Kind = gtHedgehog then
                           begin
@@ -756,6 +762,7 @@
        case t^.ar[i]^.Kind of
            gtHedgehog,
                gtMine,
+             gtTarget,
                gtCase: begin
                        inc(t^.ar[i]^.Damage, Damage);
                        if t^.ar[i]^.Kind = gtHedgehog then
--- a/hedgewars/uTriggers.pas	Tue Sep 11 17:04:24 2007 +0000
+++ b/hedgewars/uTriggers.pas	Fri Sep 14 20:51:40 2007 +0000
@@ -21,32 +21,61 @@
 interface
 uses SDLh, uConsts;
 {$INCLUDE options.inc}
+const trigTurns = $80000001;
 
-procedure AddTrigger(id: Longword);
-procedure DoTrigger(id: Longword);
+procedure AddTrigger(id, Ticks: Longword);
+procedure TickTrigger(id: Longword);
 
 implementation
-uses uGears;
+uses uGears, uFloat, uMisc;
 type PTrigger = ^TTrigger;
      TTrigger = record
                 id: Longword;
+                Ticks: Longword;
                 Next: PTrigger;
                 end;
 var TriggerList: PTrigger = nil;
 
-procedure AddTrigger(id: Longword);
+procedure AddTrigger(id, Ticks: Longword);
 var tmp: PTrigger;
 begin
+if (Ticks = 0) then exit;
+{$IFDEF DEBUGFILE}AddFileLog('Add trigger: ' + inttostr(id));{$ENDIF}
 new(tmp);
 FillChar(tmp^, sizeof(TGear), 0);
 
 tmp^.id:= id;
+tmp^.Ticks:= Ticks;
 if TriggerList <> nil then tmp^.Next:= TriggerList;
 TriggerList:= tmp
 end;
 
-procedure DoTrigger(id: Longword);
+procedure TickTriggerT(Trigger: PTrigger);
+begin
+AddGear(1024, -140, gtTarget, 0, _0, _0, 0)
+end;
+
+procedure TickTrigger(id: Longword);
+var t, tt: PTrigger;
 begin
+t:= TriggerList;
+
+while (t <> nil) do
+  begin
+  if t^.id = id then
+    begin
+    tt:= t;
+    dec(t^.Ticks);
+    if (t^.Ticks = 0) then
+       begin
+       TickTriggerT(t);
+       if t = TriggerList then TriggerList:= t^.Next
+                          else tt^.Next:= t^.Next;
+       Dispose(t)
+       end
+       else t:= t^.Next
+    end else t:= t^.Next
+  end
 end;
 
 end.
\ No newline at end of file