# HG changeset patch # User Henek # Date 1292248924 -3600 # Node ID 0618b31023dc35c0dd9424a573adad74471c89fe # Parent ecf012a762d8e73b4993ae1b0c4116db237c1b23 added team flag to AddTeam and made AI team allowed to have custom flags. added GetGearVelocity and SetGearVelocity and removed CopyPV2. changed knockball to use use these functions instead. diff -r ecf012a762d8 -r 0618b31023dc hedgewars/uScript.pas --- a/hedgewars/uScript.pas Sun Dec 12 23:52:53 2010 -0500 +++ b/hedgewars/uScript.pas Mon Dec 13 15:02:04 2010 +0100 @@ -642,28 +642,6 @@ lc_copypv:= 1 end; -function lc_copypv2(L : Plua_State) : LongInt; Cdecl; -var gears, geard : PGear; -begin - if lua_gettop(L) <> 2 then - begin - LuaError('Lua: Wrong number of parameters passed to CopyPV2!'); - end - else - begin - gears:= GearByUID(lua_tointeger(L, 1)); - geard:= GearByUID(lua_tointeger(L, 2)); - if (gears <> nil) and (geard <> nil) then - begin - geard^.X:= gears^.X; - geard^.Y:= gears^.Y; - geard^.dX:= gears^.dX * 2; - geard^.dY:= gears^.dY * 2; - end - end; - lc_copypv2:= 1 -end; - function lc_followgear(L : Plua_State) : LongInt; Cdecl; var gear : PGear; begin @@ -864,8 +842,10 @@ end; function lc_addteam(L : Plua_State) : LongInt; Cdecl; +var np: LongInt; begin - if lua_gettop(L) <> 5 then + np:= lua_gettop(L); + if (np < 5) or (np > 6) then begin LuaError('Lua: Wrong number of parameters passed to AddTeam!'); //lua_pushnil(L) @@ -876,6 +856,7 @@ ParseCommand('grave ' + lua_tostring(L, 3), true); ParseCommand('fort ' + lua_tostring(L, 4), true); ParseCommand('voicepack ' + lua_tostring(L, 5), true); + if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true); CurrentTeam^.Binds:= DefaultBinds // fails on x64 //lua_pushinteger(L, LongInt(CurrentTeam)); @@ -959,6 +940,45 @@ lc_setgearposition:= 0 end; +function lc_getgearvelocity(L : Plua_State) : LongInt; Cdecl; +var gear: PGear; +begin + if lua_gettop(L) <> 1 then + begin + LuaError('Lua: Wrong number of parameters passed to GetGearVelocity!'); + lua_pushnil(L); + lua_pushnil(L) + end + else + begin + gear:= GearByUID(lua_tointeger(L, 1)); + if gear <> nil then + begin + lua_pushnumber(L, hwRound(gear^.dX * 1000) / 1000); + lua_pushnumber(L, hwRound(gear^.dY * 1000) / 1000) + end + end; + lc_getgearvelocity:= 2; +end; + +function lc_setgearvelocity(L : Plua_State) : LongInt; Cdecl; +var gear: PGear; +begin + if lua_gettop(L) <> 3 then + LuaError('Lua: Wrong number of parameters passed to SetGearVelocity!') + else + begin + gear:= GearByUID(lua_tointeger(L, 1)); + if gear <> nil then + begin + gear^.dX:= int2hwFloat(round(lua_tonumber(L, 2) * 1000)) / 1000; + gear^.dY:= int2hwFloat(round(lua_tonumber(L, 3) * 1000)) / 1000; + SetAllToActive; + end + end; + lc_setgearvelocity:= 0 +end; + function lc_setzoom(L : Plua_State) : LongInt; Cdecl; begin if lua_gettop(L) <> 1 then @@ -1412,6 +1432,8 @@ lua_register(luaState, 'FindPlace', @lc_findplace); lua_register(luaState, 'SetGearPosition', @lc_setgearposition); lua_register(luaState, 'GetGearPosition', @lc_getgearposition); +lua_register(luaState, 'SetGearVelocity', @lc_setgearvelocity); +lua_register(luaState, 'GetGearVelocity', @lc_getgearvelocity); lua_register(luaState, 'ParseCommand', @lc_parsecommand); lua_register(luaState, 'ShowMission', @lc_showmission); lua_register(luaState, 'HideMission', @lc_hidemission); @@ -1433,7 +1455,6 @@ lua_register(luaState, 'GetX', @lc_getx); lua_register(luaState, 'GetY', @lc_gety); lua_register(luaState, 'CopyPV', @lc_copypv); -lua_register(luaState, 'CopyPV2', @lc_copypv2); lua_register(luaState, 'FollowGear', @lc_followgear); lua_register(luaState, 'GetFollowGear', @lc_getfollowgear); lua_register(luaState, 'SetState', @lc_setstate); diff -r ecf012a762d8 -r 0618b31023dc hedgewars/uStore.pas --- a/hedgewars/uStore.pas Sun Dec 12 23:52:53 2010 -0500 +++ b/hedgewars/uStore.pas Mon Dec 13 15:02:04 2010 +0100 @@ -120,7 +120,7 @@ // overwrite flag for cpu teams and keep players from using it if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then - Flag:= 'cpu' + if Flag = 'hedgewars' then Flag:= 'cpu' else if Flag = 'cpu' then Flag:= 'hedgewars'; diff -r ecf012a762d8 -r 0618b31023dc share/hedgewars/Data/Maps/Knockball/map.lua --- a/share/hedgewars/Data/Maps/Knockball/map.lua Sun Dec 12 23:52:53 2010 -0500 +++ b/share/hedgewars/Data/Maps/Knockball/map.lua Mon Dec 13 15:02:04 2010 +0100 @@ -36,7 +36,8 @@ if GetGearType(gear) == gtShover then ball = AddGear(GetX(gear), GetY(gear), gtBall, 0, 0, 0, 0) if ball ~= nil then - CopyPV2(gear, ball) + local dx, dy = GetGearVelocity(gear) + SetGearVelocity(ball, dx * 2, dy * 2) SetState(ball, 0x200) -- temporary - might change! SetTag(ball, 8) -- baseball skin FollowGear(ball)