# HG changeset patch # User nemo # Date 1349625582 14400 # Node ID 1137406bce125bf9f8470333ddbc93a6bcc45aa2 # Parent 4ad05a478c6c17f88e455745d9f79ecb2595d83f Set default collision mask for gears at currenthedgehog X/Y to FF7F, expose mask to scripting as well. This should resolve the collision part of bug #420 diff -r 4ad05a478c6c -r 1137406bce12 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Sun Oct 07 00:12:46 2012 +0400 +++ b/hedgewars/GSHandlers.inc Sun Oct 07 11:59:42 2012 -0400 @@ -315,14 +315,14 @@ CheckCollision(Gear); if (Gear^.State and gstCollision) <> 0 then doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 20, Gear^.Hedgehog, EXPLDontDraw or EXPLNoGfx); - end; + end; if (Gear^.Kind = gtGasBomb) and ((GameTicks mod 200) = 0) then begin vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeWhite); if vg <> nil then vg^.Tint:= $FFC0C000; - end; + end; if Gear^.Timer = 0 then begin @@ -386,10 +386,10 @@ FollowGear:= AddGear(hwRound(Gear^.X) - 30 + x, hwRound(Gear^.Y) - 20 + y, gtPoisonCloud, 0, _0, _0, 0); end end; + end; + DeleteGear(Gear); + exit end; - DeleteGear(Gear); - exit - end; CalcRotationDirAngle(Gear); diff -r 4ad05a478c6c -r 1137406bce12 hedgewars/uGearsList.pas --- a/hedgewars/uGearsList.pas Sun Oct 07 00:12:46 2012 +0400 +++ b/hedgewars/uGearsList.pas Sun Oct 07 11:59:42 2012 -0400 @@ -104,9 +104,14 @@ gear^.Density:= _1; // Define ammo association, if any. gear^.AmmoType:= GearKindAmmoTypeMap[Kind]; -gear^.CollisionMask:= $FFFF; -if CurrentHedgehog <> nil then gear^.Hedgehog:= CurrentHedgehog; +if CurrentHedgehog <> nil then + begin + gear^.Hedgehog:= CurrentHedgehog; + if (CurrentHedgehog^.Gear <> nil) and (hwRound(CurrentHedgehog^.Gear^.X) = X) and (hwRound(CurrentHedgehog^.Gear^.Y) = Y) then + gear^.CollisionMask:= $FF7F; + end +else gear^.CollisionMask:= $FFFF; if (Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then gear^.Z:= cHHZ+1 diff -r 4ad05a478c6c -r 1137406bce12 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Sun Oct 07 00:12:46 2012 +0400 +++ b/hedgewars/uScript.pas Sun Oct 07 11:59:42 2012 -0400 @@ -647,6 +647,39 @@ lc_setgearpos:= 0 end; +function lc_getgearcollisionmask(L : Plua_State) : LongInt; Cdecl; +var gear : PGear; +begin + if lua_gettop(L) <> 1 then + begin + LuaError('Lua: Wrong number of parameters passed to GetGearCollisionMask!'); + lua_pushnil(L); // return value on stack (nil) + end + else + begin + gear:= GearByUID(lua_tointeger(L, 1)); + if gear <> nil then + lua_pushinteger(L, gear^.CollisionMask) + else + lua_pushnil(L); + end; + lc_getgearcollisionmask:= 1 +end; + +function lc_setgearcollisionmask(L : Plua_State) : LongInt; Cdecl; +var gear : PGear; +begin + if lua_gettop(L) <> 2 then + LuaError('Lua: Wrong number of parameters passed to SetGearCollisionMask!') + else + begin + gear:= GearByUID(lua_tointeger(L, 1)); + if gear <> nil then + gear^.CollisionMask:= lua_tointeger(L, 2); + end; + lc_setgearcollisionmask:= 0 +end; + function lc_gethoglevel(L : Plua_State): LongInt; Cdecl; var gear : PGear; begin @@ -2327,6 +2360,8 @@ lua_register(luaState, _P'SetGearMessage', @lc_setgearmessage); lua_register(luaState, _P'GetGearPos', @lc_getgearpos); lua_register(luaState, _P'SetGearPos', @lc_setgearpos); +lua_register(luaState, _P'GetGearCollisionMask', @lc_getgearcollisionmask); +lua_register(luaState, _P'SetGearCollisionMask', @lc_setgearcollisionmask); lua_register(luaState, _P'GetRandom', @lc_getrandom); lua_register(luaState, _P'SetWind', @lc_setwind); lua_register(luaState, _P'GetDataPath', @lc_getdatapath);