Try to beat AI in Mutant!
authorunc0rr
Wed, 07 Nov 2012 13:23:18 +0400
changeset 7996 66e8ac9c2274
parent 7994 706218709157
child 7998 c0c3f117ad1b
Try to beat AI in Mutant!
hedgewars/uAIMisc.pas
hedgewars/uConsts.pas
hedgewars/uScript.pas
hedgewars/uTypes.pas
share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua
--- a/hedgewars/uAIMisc.pas	Wed Nov 07 05:18:06 2012 +0100
+++ b/hedgewars/uAIMisc.pas	Wed Nov 07 13:23:18 2012 +0400
@@ -110,7 +110,7 @@
             begin
             for i:= 0 to cMaxHHIndex do
                 if (Hedgehogs[i].Gear <> nil)
-                and (Hedgehogs[i].Gear <> ThinkingHH) 
+                and (Hedgehogs[i].Gear <> ThinkingHH)
                 and (Hedgehogs[i].Gear^.Health > Hedgehogs[i].Gear^.Damage) 
                     then
                     begin
@@ -119,15 +119,17 @@
                         skip:= false;
                         Point.X:= hwRound(Gear^.X);
                         Point.Y:= hwRound(Gear^.Y);
-                        if Clan <> CurrentTeam^.Clan then
-                            begin
-                            Score:= Gear^.Health - Gear^.Damage;
-                            inc(e)
-                            end else
-                            begin
-                            Score:= Gear^.Damage - Gear^.Health;
-                            inc(f)
-                            end
+                        if (Hedgehogs[i].Gear^.AIHints and aihDoesntMatter) <> 0 then
+                            Score:= 0
+                            else if Clan <> CurrentTeam^.Clan then
+                                begin
+                                Score:= Gear^.Health - Gear^.Damage;
+                                inc(e)
+                                end else
+                                begin
+                                Score:= Gear^.Damage - Gear^.Health;
+                                inc(f)
+                                end
                         end;
                     inc(Targets.Count)
                     end;
--- a/hedgewars/uConsts.pas	Wed Nov 07 05:18:06 2012 +0100
+++ b/hedgewars/uConsts.pas	Wed Nov 07 13:23:18 2012 +0400
@@ -164,6 +164,7 @@
     cSendEmptyPacketTime = 1000;
     trigTurns = $80000001;
 
+    // game flags
     gfAny                = $FFFFFFFF;
     gfOneClanMode        = $00000001;           // used in trainings
     gfMultiWeapon        = $00000002;           // used in trainings
@@ -196,6 +197,7 @@
     // if a "game start notice" would be useful. If so,
     // add one in uWorld.pas - look for "AddGoal".
 
+    // gear states
     gstDrowning       = $00000001;
     gstHHDriven       = $00000002;
     gstMoving         = $00000004;
@@ -217,6 +219,7 @@
     gstHHGone         = $00100000;
     gstInvisible      = $00200000;
 
+    // gear messages
     gmLeft           = $00000001;
     gmRight          = $00000002;
     gmUp             = $00000004;
@@ -239,7 +242,12 @@
 
     cMaxSlotIndex       = 9;
     cMaxSlotAmmoIndex   = 5;
-
+    
+    // ai hints
+    aihUsualProcessing    = $00000000;
+    aihDoesntMatter       = $00000001;
+    
+    // ammo properties
     ammoprop_Timerable    = $00000001;
     ammoprop_Power        = $00000002;
     ammoprop_NeedTarget   = $00000004;
@@ -262,6 +270,7 @@
 
     AMMO_INFINITE = 100;
 
+    // explosion flags
     //EXPLAllDamageInRadius = $00000001;  Completely unused for ages
     EXPLAutoSound         = $00000002;
     EXPLNoDamage          = $00000004;
--- a/hedgewars/uScript.pas	Wed Nov 07 05:18:06 2012 +0100
+++ b/hedgewars/uScript.pas	Wed Nov 07 13:23:18 2012 +0400
@@ -1783,6 +1783,22 @@
         end;
     lc_testrectforobstacle:= 1
 end;
+
+
+function lc_setaihintsongear(L : Plua_State) : LongInt; Cdecl;
+var gear: PGear;
+begin
+    if lua_gettop(L) <> 2 then
+        LuaError('Lua: Wrong number of parameters passed to SetAIHintOnGear!')
+    else
+        begin
+        gear:= GearByUID(lua_tointeger(L, 1));
+        if gear <> nil then
+            gear^.aihints:= lua_tointeger(L, 2);
+        end;
+    lc_setaihintsongear:= 0
+end;
+
 ///////////////////
 
 procedure ScriptPrintStack;
@@ -2287,6 +2303,9 @@
 ScriptSetInteger('gstHHGone'         ,$00100000);
 ScriptSetInteger('gstInvisible'      ,$00200000);
 
+ScriptSetInteger('aihUsualProcessing' ,$00000000);
+ScriptSetInteger('aihDoesntMatter'    ,$00000001);
+
 // register functions
 lua_register(luaState, _P'HideHog', @lc_hidehog);
 lua_register(luaState, _P'RestoreHog', @lc_restorehog);
@@ -2380,6 +2399,8 @@
 lua_register(luaState, _P'GetCurAmmoType', @lc_getcurammotype);
 lua_register(luaState, _P'TestRectForObstacle', @lc_testrectforobstacle);
 
+lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear);
+
 
 ScriptClearStack; // just to be sure stack is empty
 ScriptLoaded:= false;
--- a/hedgewars/uTypes.pas	Wed Nov 07 05:18:06 2012 +0100
+++ b/hedgewars/uTypes.pas	Wed Nov 07 13:23:18 2012 +0400
@@ -258,6 +258,7 @@
             nImpactSounds: Word; // count of ImpactSounds
             SoundChannel: LongInt;
             PortalCounter: LongWord;  // Hopefully temporary, but avoids infinite portal loops in a guaranteed fashion.
+            AIHints: LongWord; // hints for ai. haha ^^^^^^ temporary, sure
             LastDamage: PHedgehog;
             end;
     TPGearArray = array of PGear;
--- a/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Wed Nov 07 05:18:06 2012 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Wed Nov 07 13:23:18 2012 +0400
@@ -209,6 +209,7 @@
     checkScore()
     giveWeapons(CurrentHedgehog)
     drawCircles()
+    setAIHints()
     kill_reward= numhhs*10
 
     if CurrentHedgehog == mutant then
@@ -399,6 +400,16 @@
     mutant=nil
 end
 
+function setAIHints()
+    for i = 0, #hhs do
+        if mutant == nil or hhs[i] == mutant or CurrentHedgehog == mutant then
+            SetGearAIHints(hhs[i], aihUsual)
+        else
+            SetGearAIHints(hhs[i], aihDoesntMatter)
+        end
+    end
+end
+
 function removeFeeder(gear)
 
     if gear~=nil then