Engine/Frontend:
authorsmxx
Fri, 16 Apr 2010 14:37:28 +0000
changeset 3346 967fd96f7373
parent 3345 25ad24233e77
child 3347 5d0ac8197eb7
Engine/Frontend: * Split ammo store message into 5 different messages (4 to set, 1 to apply)
QTfrontend/game.cpp
QTfrontend/hwconsts.cpp.in
hedgewars/CCHandlers.inc
hedgewars/uAmmos.pas
hedgewars/uConsole.pas
hedgewars/uScript.pas
share/hedgewars/Data/Locale/en.txt
share/hedgewars/Data/Maps/Basketball/map.lua
share/hedgewars/Data/Maps/Knockball/map.lua
share/hedgewars/Data/Missions/Training/Bazooka.lua
share/hedgewars/Data/Missions/Training/Shotgun.lua
share/hedgewars/Data/Missions/Training/SniperRifle.lua
--- a/QTfrontend/game.cpp	Fri Apr 16 12:41:06 2010 +0000
+++ b/QTfrontend/game.cpp	Fri Apr 16 14:37:28 2010 +0000
@@ -86,7 +86,11 @@
         {
             HWProto::addStringListToBuffer(buf,
                 (*it).TeamGameConfig(gamecfg->getInitHealth()));
-            HWProto::addStringToBuffer(buf, QString("eammstore %1").arg(ammostr));
+            HWProto::addStringToBuffer(buf, QString("eammloadt %1").arg(ammostr.mid(0, cAmmoNumber)));
+            HWProto::addStringToBuffer(buf, QString("eammprob %1").arg(ammostr.mid(cAmmoNumber, cAmmoNumber)));
+            HWProto::addStringToBuffer(buf, QString("eammdelay %1").arg(ammostr.mid(2 * cAmmoNumber, cAmmoNumber)));
+            HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber)));
+            HWProto::addStringToBuffer(buf, QString("eammstore"));
         }
     }
     RawSendIPC(buf);
@@ -128,8 +132,12 @@
     HWProto::addStringListToBuffer(teamscfg,
             team2->TeamGameConfig(100));
 
-    HWProto::addStringToBuffer(teamscfg, "eammstore " + *cDefaultAmmoStore);
-    HWProto::addStringToBuffer(teamscfg, "eammstore " + *cDefaultAmmoStore);
+    HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber)));
+    HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber)));
+    HWProto::addStringToBuffer(teamscfg, QString("eammdelay %1").arg(cDefaultAmmoStore->mid(2 * cAmmoNumber, cAmmoNumber)));
+    HWProto::addStringToBuffer(teamscfg, QString("eammreinf %1").arg(cDefaultAmmoStore->mid(3 * cAmmoNumber, cAmmoNumber)));
+    HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
+    HWProto::addStringToBuffer(teamscfg, QString("eammstore"));
     RawSendIPC(teamscfg);
 }
 
--- a/QTfrontend/hwconsts.cpp.in	Fri Apr 16 12:41:06 2010 +0000
+++ b/QTfrontend/hwconsts.cpp.in	Fri Apr 16 14:37:28 2010 +0000
@@ -31,10 +31,10 @@
 QStringList * mapList;
 
 QString * cDefaultAmmoStore = new QString(
-        "93919294221991210322351110012010000002111"
-        "04050405416006555465544647765766666661555"
-        "00000000000002055000000400070040000000002"
-        "13111103121111111231141111111111111112111"
+        "939192942219912103223511100120100000021110"
+        "040504054160065554655446477657666666615550"
+        "000000000000020550000004000700400000000020"
+        "131111031211111112311411111111111111121110"
 		);
 int cAmmoNumber = cDefaultAmmoStore->size() / 4;
 
@@ -42,30 +42,30 @@
 	QList< QPair<QString, QString> >()
 	<< qMakePair(QString("Default"), *cDefaultAmmoStore)
 	<< qMakePair(QString("Crazy"),     QString(
-        "99999999999999999929999999999999992999999"
-        "11111101111111111111111111111111111111111"
-        "00000000000000000000000000000000000000000"
-        "13111103121111111231141111111111111112111"))
+        "999999999999999999299999999999999929999990"
+        "111111011111111111111111111111111111111110"
+        "000000000000000000000000000000000000000000"
+        "131111031211111112311411111111111111121110"))
 	<< qMakePair(QString("Pro mode"),  QString(
-        "90900090000000000000090000000000000000000"
-        "00000000000000000000000000000000000000000"
-        "00000000000002055000000400070040000000002"
-        "11111111111111111111111111111111111111111"))
+        "909000900000000000000900000000000000000000"
+        "000000000000000000000000000000000000000000"
+        "000000000000020550000004000700400000000020"
+        "111111111111111111111111111111111111111110"))
 	<< qMakePair(QString("Shoppa"),    QString(
-        "00000099000000000000000000000000000000000"
-        "44444100442444022101121212224220000000020"
-        "00000000000000000000000000000000000000000"
-        "11111111111111111111111111111111111111111"))
+        "000000990000000000000000000000000000000000"
+        "444441004424440221011212122242200000000200"
+        "000000000000000000000000000000000000000000"
+        "111111111111111111111111111111111111111110"))
 	<< qMakePair(QString("Basketball"),QString(
-		"00000090000009000000000000000000000000000"
-		"00000000000000000000000000000000000000000"
-		"00000000000000055000000400070040000000002"
-		"11111111111111111111111111111111111111111"))
+		"000000900000090000000000000000000000000000"
+		"000000000000000000000000000000000000000000"
+		"000000000000000550000004000700400000000020"
+		"111111111111111111111111111111111111111110"))
 	<< qMakePair(QString("Minefield"), QString(
-		"00000099000900000003000000000000000000000"
-		"00000000000000000000000000000000000000000"
-		"00000000000002055000000400070040000000002"
-		"11111111111111111111111111111111111111111"))
+		"000000990009000000030000000000000000000000"
+		"000000000000000000000000000000000000000000"
+		"000000000000020550000004000700400000000020"
+		"111111111111111111111111111111111111111110"))
 	;
 
 QColor * color1 = new QColor(221,   0,   0);
--- a/hedgewars/CCHandlers.inc	Fri Apr 16 12:41:06 2010 +0000
+++ b/hedgewars/CCHandlers.inc	Fri Apr 16 14:37:28 2010 +0000
@@ -191,9 +191,29 @@
 CurrentHedgehog^.Gear^.Y:= int2hwFloat(t)
 end;
 
+procedure chSetAmmoLoadout(var descr: shortstring);
+begin
+SetAmmoLoadout(descr)
+end;
+
+procedure chSetAmmoDelay(var descr: shortstring);
+begin
+SetAmmoDelay(descr)
+end;
+
+procedure chSetAmmoProbability(var descr: shortstring);
+begin
+SetAmmoProbability(descr)
+end;
+
+procedure chSetAmmoReinforcement(var descr: shortstring);
+begin
+SetAmmoReinforcement(descr)
+end;
+
 procedure chAddAmmoStore(var descr: shortstring);
 begin
-AddAmmoStore(descr)
+AddAmmoStore
 end;
 
 procedure chBind(var id: shortstring);
--- a/hedgewars/uAmmos.pas	Fri Apr 16 12:41:06 2010 +0000
+++ b/hedgewars/uAmmos.pas	Fri Apr 16 14:37:28 2010 +0000
@@ -25,7 +25,11 @@
 procedure initModule;
 procedure freeModule;
 
-procedure AddAmmoStore(s: shortstring);
+procedure AddAmmoStore;
+procedure SetAmmoLoadout(s: shortstring);
+procedure SetAmmoProbability(s: shortstring);
+procedure SetAmmoDelay(s: shortstring);
+procedure SetAmmoReinforcement(s: shortstring);
 procedure AssignStores;
 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
 function  HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean;
@@ -47,6 +51,7 @@
 type TAmmoCounts = array[TAmmoType] of Longword;
 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
     StoreCnt: Longword;
+    ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
 
 procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts);
 var mi: array[0..cMaxSlotIndex] of byte;
@@ -81,17 +86,17 @@
     end
 end;
 
-procedure AddAmmoStore(s: shortstring);
+procedure AddAmmoStore;
 const probability: array [0..8] of LongWord = (0,20,30,60,100,200,400,600,800);
 var cnt: Longword;
     a: TAmmoType;
     ammos: TAmmoCounts;
     substr: shortstring; // TEMPORARY
 begin
-TryDo(byte(s[0]) = byte(ord(High(TAmmoType))) * 4, 'Invalid ammo scheme (incompatible frontend; got: ' + inttostr(byte(s[0]) div 4) + ', expected: ' + inttostr(ord(High(TAmmoType))) + ')', true);
+TryDo((byte(ammoLoadout[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoProbability[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoDelay[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoReinforcement[0]) = byte(ord(High(TAmmoType)))), 'Incomplete or missing ammo scheme set (incompatible frontend or demo/save?)', true);
 
 // FIXME - TEMPORARY hardcoded check on shoppa pending creation of crate *type* probability editor
-substr:= Copy(s,1,15);
+substr:= Copy(ammoLoadout,1,15);
 if (substr = '000000990000009') or 
    (substr = '000000990000000') then
     shoppa:= true;
@@ -105,11 +110,11 @@
     begin
     if a <> amNothing then
         begin
-        Ammoz[a].Probability:= probability[byte(s[ord(a) + ord(High(TAmmoType))]) - byte('0')];
-        Ammoz[a].SkipTurns:= (byte(s[ord(a) + ord(High(TAmmoType)) + ord(High(TAmmoType))]) - byte('0'));
-        Ammoz[a].NumberInCase:= (byte(s[ord(a) + ord(High(TAmmoType)) + ord(High(TAmmoType)) + ord(High(TAmmoType))]) - byte('0'));
+        Ammoz[a].Probability:= probability[byte(ammoProbability[ord(a)]) - byte('0')];
+        Ammoz[a].SkipTurns:= (byte(ammoDelay[ord(a)]) - byte('0'));
+        Ammoz[a].NumberInCase:= (byte(ammoReinforcement[ord(a)]) - byte('0'));
         if (TrainingFlags and tfIgnoreDelays) <> 0 then Ammoz[a].SkipTurns:= 0;
-        cnt:= byte(s[ord(a)]) - byte('0');
+        cnt:= byte(ammoLoadout[ord(a)]) - byte('0');
         // avoid things we already have infinite number
         if cnt = 9 then
             begin
@@ -357,6 +362,26 @@
     if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0
 end;
 
+procedure SetAmmoLoadout(s: shortstring);
+begin
+    ammoLoadout:= s;
+end;
+
+procedure SetAmmoProbability(s: shortstring);
+begin
+    ammoProbability:= s;
+end;
+
+procedure SetAmmoDelay(s: shortstring);
+begin
+    ammoDelay:= s;
+end;
+
+procedure SetAmmoReinforcement(s: shortstring);
+begin
+    ammoReinforcement:= s;
+end;
+
 // Restore indefinitely disabled weapons and initial weapon counts.  Only used for hog placement right now
 procedure ResetWeapons;
 var i, slot, a: Longword;
@@ -378,7 +403,11 @@
 procedure initModule;
 begin
     shoppa:= false;
-    StoreCnt:= 0
+    StoreCnt:= 0;
+    ammoLoadout:= '';
+    ammoProbability:= '';
+    ammoDelay:= '';
+    ammoReinforcement:= ''
 end;
 
 procedure freeModule;
--- a/hedgewars/uConsole.pas	Fri Apr 16 12:41:06 2010 +0000
+++ b/hedgewars/uConsole.pas	Fri Apr 16 14:37:28 2010 +0000
@@ -255,6 +255,10 @@
     RegisterVariable('addhh'   , vtCommand, @chAddHH        , false);
     RegisterVariable('hat'     , vtCommand, @chSetHat       , false);
     RegisterVariable('hhcoords', vtCommand, @chSetHHCoords  , false);
+    RegisterVariable('ammloadt', vtCommand, @chSetAmmoLoadout, false);
+    RegisterVariable('ammdelay', vtCommand, @chSetAmmoDelay, false);
+    RegisterVariable('ammprob',  vtCommand, @chSetAmmoProbability, false);
+    RegisterVariable('ammreinf', vtCommand, @chSetAmmoReinforcement, false);
     RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
     RegisterVariable('quit'    , vtCommand, @chQuit         , true );
     RegisterVariable('confirm' , vtCommand, @chConfirm      , true );
--- a/hedgewars/uScript.pas	Fri Apr 16 12:41:06 2010 +0000
+++ b/hedgewars/uScript.pas	Fri Apr 16 14:37:28 2010 +0000
@@ -53,12 +53,15 @@
     uKeys;
     
 var luaState : Plua_State;
-    ScriptAmmoStore : shortstring;
+    ScriptAmmoLoadout : shortstring;
+    ScriptAmmoProbability : shortstring;
+    ScriptAmmoDelay : shortstring;
+    ScriptAmmoReinforcement : shortstring;
     ScriptLoaded : boolean;
     
 procedure ScriptPrepareAmmoStore; forward;
 procedure ScriptApplyAmmoStore; forward;
-procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte); forward;
+procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay, reinforcement: Byte); forward;
 
 // wrapped calls //
 
@@ -482,11 +485,11 @@
 
 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
 begin
-    if lua_gettop(L) <> 4 then
+    if lua_gettop(L) <> 5 then
         WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!')
     else
         begin
-        ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
+        ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
         end;
     lc_setammo:= 0
 end;
@@ -693,25 +696,38 @@
 // reset ammostore (quite unclean, but works?)
 uAmmos.freeModule;
 uAmmos.initModule;
-ScriptAmmoStore:= '';
+ScriptAmmoLoadout:= '';
+ScriptAmmoDelay:= '';
+ScriptAmmoProbability:= '';
+ScriptAmmoReinforcement:= '';
 for i:=1 to ord(High(TAmmoType)) do
-    ScriptAmmoStore:= ScriptAmmoStore + '0000';
+    begin
+    ScriptAmmoLoadout:= ScriptAmmoLoadout + '0';
+    ScriptAmmoProbability:= ScriptAmmoProbability + '0';
+    ScriptAmmoDelay:= ScriptAmmoDelay + '0';
+    ScriptAmmoReinforcement:= ScriptAmmoReinforcement + '0';
+    end;
 end;
 
-procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte);
+procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay, reinforcement: Byte);
 begin
-if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) or (delay < 0) or (delay > 9)then
+if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) or (delay < 0) or (delay > 9) or (reinforcement < 0) or (reinforcement > 8) then
     exit;
-ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1];
-ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1];
-ScriptAmmoStore[ord(ammo) + 2 * ord(high(TAmmoType))]:= inttostr(delay)[1];
+ScriptAmmoLoadout[ord(ammo)]:= inttostr(count)[1];
+ScriptAmmoProbability[ord(ammo)]:= inttostr(propability)[1];
+ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
+ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
 end;
 
 procedure ScriptApplyAmmoStore;
 var i : LongInt;
 begin
+SetAmmoLoadout(ScriptAmmoLoadout);
+SetAmmoProbability(ScriptAmmoProbability);
+SetAmmoDelay(ScriptAmmoDelay);
+SetAmmoReinforcement(ScriptAmmoReinforcement);
 for i:= 0 to Pred(TeamsCount) do
-    AddAmmoStore(ScriptAmmoStore);
+    AddAmmoStore;
 end;
 
 procedure initModule;
--- a/share/hedgewars/Data/Locale/en.txt	Fri Apr 16 12:41:06 2010 +0000
+++ b/share/hedgewars/Data/Locale/en.txt	Fri Apr 16 14:37:28 2010 +0000
@@ -42,6 +42,7 @@
 00:39=Flying Saucer
 00:40=Molotov Cocktail
 00:41=Birdy
+00:42=UNNAMED WEAPON
 
 01:00=Let's fight!
 01:01=Round draw
--- a/share/hedgewars/Data/Maps/Basketball/map.lua	Fri Apr 16 12:41:06 2010 +0000
+++ b/share/hedgewars/Data/Maps/Basketball/map.lua	Fri Apr 16 14:37:28 2010 +0000
@@ -103,8 +103,8 @@
 end
 
 function onAmmoStoreInit()
-	SetAmmo(amBaseballBat, 9, 0, 0)
-	SetAmmo(amSkip, 9, 0, 0)
+	SetAmmo(amBaseballBat, 9, 0, 0, 0)
+	SetAmmo(amSkip, 9, 0, 0, 0)
 end
 
 function onGearAdd(gear)
--- a/share/hedgewars/Data/Maps/Knockball/map.lua	Fri Apr 16 12:41:06 2010 +0000
+++ b/share/hedgewars/Data/Maps/Knockball/map.lua	Fri Apr 16 14:37:28 2010 +0000
@@ -80,8 +80,8 @@
 end
 
 function onAmmoStoreInit()
-	SetAmmo(amBaseballBat, 9, 0, 0)
-	SetAmmo(amSkip, 9, 0, 0)
+	SetAmmo(amBaseballBat, 9, 0, 0, 0)
+	SetAmmo(amSkip, 9, 0, 0, 0)
 end
 
 function onGearAdd(gear)
--- a/share/hedgewars/Data/Missions/Training/Bazooka.lua	Fri Apr 16 12:41:06 2010 +0000
+++ b/share/hedgewars/Data/Missions/Training/Bazooka.lua	Fri Apr 16 14:37:28 2010 +0000
@@ -209,7 +209,7 @@
 -- to request the available ammo and probabilities
 function onAmmoStoreInit()
 	-- add an unlimited supply of bazooka ammo
-	SetAmmo(amBazooka, 9, 0, 0)
+	SetAmmo(amBazooka, 9, 0, 0, 0)
 end
 
 -- This function is called when a new gear is added.
--- a/share/hedgewars/Data/Missions/Training/Shotgun.lua	Fri Apr 16 12:41:06 2010 +0000
+++ b/share/hedgewars/Data/Missions/Training/Shotgun.lua	Fri Apr 16 14:37:28 2010 +0000
@@ -209,7 +209,7 @@
 -- to request the available ammo and probabilities
 function onAmmoStoreInit()
 	-- add an unlimited supply of shotgun ammo
-	SetAmmo(amShotgun, 9, 0, 0)
+	SetAmmo(amShotgun, 9, 0, 0, 0)
 end
 
 -- This function is called when a new gear is added.
--- a/share/hedgewars/Data/Missions/Training/SniperRifle.lua	Fri Apr 16 12:41:06 2010 +0000
+++ b/share/hedgewars/Data/Missions/Training/SniperRifle.lua	Fri Apr 16 14:37:28 2010 +0000
@@ -220,7 +220,7 @@
 -- to request the available ammo and probabilities
 function onAmmoStoreInit()
 	-- add an unlimited supply of shotgun ammo
-	SetAmmo(amSniperRifle, 9, 0, 0)
+	SetAmmo(amSniperRifle, 9, 0, 0, 0)
 end
 
 -- This function is called when a new gear is added.