Triggers PoC: targets are spawned right after the previous damaged
authorunc0rr
Sat, 15 Sep 2007 13:01:44 +0000
changeset 595 5ee863f2f568
parent 594 221ffeb92f30
child 596 38bdde6a54c1
Triggers PoC: targets are spawned right after the previous damaged
QTfrontend/game.cpp
hedgewars/CCHandlers.inc
hedgewars/uGears.pas
hedgewars/uTriggers.pas
--- a/QTfrontend/game.cpp	Sat Sep 15 10:27:34 2007 +0000
+++ b/QTfrontend/game.cpp	Sat Sep 15 13:01:44 2007 +0000
@@ -139,7 +139,11 @@
 	HWProto::addStringListToBuffer(teamscfg,
 			team2.TeamGameConfig(100));
 
-	HWProto::addStringToBuffer(teamscfg, "eaddtrig 2147483649");
+//	HWProto::addStringToBuffer(teamscfg, "eaddtrig 2147483649");
+	HWProto::addStringToBuffer(teamscfg, "eaddtrig s2147483649 1 1 33 1100 -100 1");
+	HWProto::addStringToBuffer(teamscfg, "eaddtrig s1 1 1 33 1200 -100 2");
+	HWProto::addStringToBuffer(teamscfg, "eaddtrig s2 1 1 33 1300 -100 3");
+	HWProto::addStringToBuffer(teamscfg, "eaddtrig s3 1 1 33 1400 -100 0");
 
 	RawSendIPC(teamscfg);
 }
--- a/hedgewars/CCHandlers.inc	Sat Sep 15 10:27:34 2007 +0000
+++ b/hedgewars/CCHandlers.inc	Sat Sep 15 13:01:44 2007 +0000
@@ -466,8 +466,30 @@
 end;
 
 procedure chAddTrigger(var s: shortstring);
-var t: LongWord;
+var ttype, gt, geartrig, Ticks, Lives: LongWord;
+    X, Y: LongInt;
+    c: char;
+    tmp: shortstring;
 begin
-val(s, t);
-AddTrigger(t, 1, 2)
+c:= s[1];
+Delete(s, 1, 1);
+case c of
+  's': begin // s12345 1 1 33 0 0 123456
+       SplitBySpace(s, tmp);
+       val(s, ttype);
+       SplitBySpace(tmp, s);
+       val(tmp, Ticks);
+       SplitBySpace(s, tmp);
+       val(s, Lives);
+       SplitBySpace(tmp, s);
+       val(tmp, gt);
+       SplitBySpace(s, tmp);
+       val(s, X);
+       SplitBySpace(tmp, s);
+       val(tmp, Y);
+       SplitBySpace(s, tmp);
+       val(s, geartrig);
+       AddTriggerSpawner(ttype, Ticks, Lives, X, Y, TGearType(gt), geartrig);
+       end;
+  end
 end;
--- a/hedgewars/uGears.pas	Sat Sep 15 10:27:34 2007 +0000
+++ b/hedgewars/uGears.pas	Sat Sep 15 13:01:44 2007 +0000
@@ -49,6 +49,7 @@
              Surf: PSDL_Surface;
              Z: Longword;
              IntersectGear: PGear;
+             TriggerId: Longword;
              end;
 
 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
@@ -332,6 +333,7 @@
       RecountTeamHealth(team);
       end;
 {$IFDEF DEBUGFILE}AddFileLog('DeleteGear');{$ENDIF}
+if Gear^.TriggerId <> 0 then TickTrigger(Gear^.TriggerId);
 if CurAmmoGear = Gear then CurAmmoGear:= nil;
 if FollowGear = Gear then FollowGear:= nil;
 RemoveGearFromList(Gear);
--- a/hedgewars/uTriggers.pas	Sat Sep 15 10:27:34 2007 +0000
+++ b/hedgewars/uTriggers.pas	Sat Sep 15 13:01:44 2007 +0000
@@ -23,7 +23,9 @@
 {$INCLUDE options.inc}
 const trigTurns = $80000001;
 
-procedure AddTrigger(id, Ticks, Lives: Longword);
+type TTrigAction = (taSpawnGear);
+
+procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword);
 procedure TickTrigger(id: Longword);
 
 implementation
@@ -34,29 +36,41 @@
                 Ticks: Longword;
                 Lives: Longword;
                 TicksPerLife: LongWord;
+                Action: TTrigAction;
+                X, Y: LongInt;
+                SpawnGearType: TGearType;
+                SpawnGearTriggerId: Longword;
                 Next: PTrigger;
                 end;
 var TriggerList: PTrigger = nil;
 
-procedure AddTrigger(id, Ticks, Lives: Longword);
+procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword);
 var tmp: PTrigger;
 begin
 if (Ticks = 0) or (Lives = 0) then exit;
-{$IFDEF DEBUGFILE}AddFileLog('Add trigger: ' + inttostr(id));{$ENDIF}
+{$IFDEF DEBUGFILE}AddFileLog('Add spawner trigger: ' + inttostr(id) + ', gear triggers  ' + inttostr(GearTriggerId));{$ENDIF}
 new(tmp);
-FillChar(tmp^, sizeof(TGear), 0);
+FillChar(tmp^, sizeof(TTrigger), 0);
 
 tmp^.id:= id;
 tmp^.Ticks:= Ticks;
 tmp^.TicksPerLife:= Ticks;
 tmp^.Lives:= Lives;
+tmp^.Action:= taSpawnGear;
+tmp^.X:= X;
+tmp^.Y:= Y;
+tmp^.SpawnGearType:= GearType;
+tmp^.SpawnGearTriggerId:= GearTriggerId;
 if TriggerList <> nil then tmp^.Next:= TriggerList;
 TriggerList:= tmp
 end;
 
 procedure TickTriggerT(Trigger: PTrigger);
 begin
-AddGear(1024, -140, gtTarget, 0, _0, _0, 0)
+with Trigger^ do
+  case Action of
+     taSpawnGear: AddGear(X, Y, SpawnGearType, 0, _0, _0, 0)^.TriggerId:= SpawnGearTriggerId;
+  end
 end;
 
 procedure TickTrigger(id: Longword);