# HG changeset patch # User unc0rr # Date 1398752445 -14400 # Node ID aef994a2ec1a4bf86ccd8b28dc5f0c50d6a8ec45 # Parent 93afc42147c8897d15bc1a126f3f7347814b959c# Parent 8e62b5cb790c5f0cd34ed3858a3383f97512c2a4 Merge diff -r 8e62b5cb790c -r aef994a2ec1a INSTALL --- a/INSTALL Mon Apr 28 16:49:29 2014 -0400 +++ b/INSTALL Tue Apr 29 10:20:45 2014 +0400 @@ -7,7 +7,7 @@ - SDL_mixer >= 1.2 - SDL_image >= 1.2 - SDL_ttf >= 2.0 - - Lua >= 5.1.0 + - Lua >= 5.2.0 - Physfs >= 2.0.0 For server: - Glasgow Haskell Compiler >= 6.10 diff -r 8e62b5cb790c -r aef994a2ec1a cmake_modules/FindLua.cmake --- a/cmake_modules/FindLua.cmake Mon Apr 28 16:49:29 2014 -0400 +++ b/cmake_modules/FindLua.cmake Tue Apr 29 10:20:45 2014 +0400 @@ -17,10 +17,9 @@ find_path(LUA_INCLUDE_DIR lua.h PATHS /usr/include /usr/local/include /usr/pkg/include - PATH_SUFFIXES lua5.1 lua51) -find_library(LUA_LIBRARY NAMES lua51 lua5.1 lua-5.1 lua + PATH_SUFFIXES lua5.2 lua52) +find_library(LUA_LIBRARY NAMES lua52 lua5.2 lua-5.2 lua PATHS /lib /usr/lib /usr/local/lib /usr/pkg/lib) find_package_handle_standard_args(Lua DEFAULT_MSG LUA_LIBRARY LUA_INCLUDE_DIR) mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY) - diff -r 8e62b5cb790c -r aef994a2ec1a hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Mon Apr 28 16:49:29 2014 -0400 +++ b/hedgewars/CMakeLists.txt Tue Apr 29 10:20:45 2014 +0400 @@ -148,6 +148,7 @@ add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LUA_LIBRARY_DIR} -XLAlua=${LUA_LIBRARY_NAME}") else() add_definitions(-dLUA_INTERNAL) + add_definitions(-dLUA51) list(APPEND HW_LINK_LIBS lua) add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}") endif() diff -r 8e62b5cb790c -r aef994a2ec1a hedgewars/LuaPas.pas --- a/hedgewars/LuaPas.pas Mon Apr 28 16:49:29 2014 -0400 +++ b/hedgewars/LuaPas.pas Tue Apr 29 10:20:45 2014 +0400 @@ -8,6 +8,10 @@ * * Created by Geo Massar, 2006 * Distributed as free/open source. + * + * Note: This file contains custom modification for Hedgewars + * These changes should accomplish compatibility for both lua 5.1 and 5.2 + * Differences: In 5.1 set/getglobal ARE macros and tonumber/tointeger are NOT *) interface @@ -238,6 +242,27 @@ (* ** access functions (stack -> C) *) + +{$IFNDEF LUA51} + +function lua_tointegerx(L : Plua_State; idx : LongInt; success : PInteger) : lua_Integer; + cdecl; external LuaLibName; +function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer; + +function lua_tonumberx(L : Plua_State; idx : LongInt; success : PInteger) : lua_Number; + cdecl; external LuaLibName; +function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number; + +{$ELSE} + +function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer; + cdecl; external LuaLibName; + +function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number; + cdecl; external LuaLibName; + +{$ENDIF} + function lua_isnumber(L : Plua_State; idx : LongInt) : LongBool; cdecl; external LuaLibName; @@ -265,12 +290,6 @@ function lua_lessthan(L : Plua_State; idx1, idx2 : LongInt) : LongBool; cdecl; external LuaLibName; -function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number; - cdecl; external LuaLibName; - -function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer; - cdecl; external LuaLibName; - function lua_toboolean(L : Plua_State; idx : LongInt) : LongBool; cdecl; external LuaLibName; @@ -386,8 +405,15 @@ procedure lua_call(L : Plua_State; nargs, nresults : LongInt); cdecl; external LuaLibName; + +{$IFNDEF LUA51} +function lua_pcallk(L: Plua_State; nargs, nresults, errfunc, ctx: Integer; k: lua_CFunction): Integer; + cdecl; external LuaLibName; +function lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt; +{$ELSE} function lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt; cdecl; external LuaLibName; +{$ENDIF} function lua_cpcall(L : Plua_State; func : lua_CFunction; ud : Pointer) : LongInt; cdecl; external LuaLibName; @@ -460,8 +486,6 @@ procedure lua_pushcfunction(L : Plua_State; f : lua_CFunction); -function lua_strlen(L : Plua_State; idx : LongInt) : LongInt; - function lua_isfunction(L : Plua_State; n : LongInt) : Boolean; function lua_istable(L : Plua_State; n : LongInt) : Boolean; function lua_islightuserdata(L : Plua_State; n : LongInt) : Boolean; @@ -474,7 +498,13 @@ procedure lua_pushliteral(L : Plua_State; s : PChar); procedure lua_setglobal(L : Plua_State; s : PChar); +{$IFNDEF LUA51} + cdecl; external LuaLibName; +{$ENDIF} procedure lua_getglobal(L : Plua_State; s : PChar); +{$IFNDEF LUA51} + cdecl; external LuaLibName; +{$ENDIF} function lua_tostring(L : Plua_State; idx : LongInt) : shortstring; function lua_tostringA(L : Plua_State; idx : LongInt) : ansistring; @@ -483,6 +513,7 @@ (* ** compatibility macros and functions *) +(* function lua_open : Plua_State; procedure lua_getregistry(L : Plua_State); @@ -492,6 +523,7 @@ type lua_Chuckreader = lua_Reader; lua_Chuckwriter = lua_Writer; +*) (* ====================================================================== *) @@ -636,10 +668,6 @@ ** See Copyright Notice at the end of this file. *) -// not compatibility with the behavior of setn/getn in Lua 5.0 -function luaL_getn(L : Plua_State; idx : LongInt) : LongInt; -procedure luaL_setn(L : Plua_State; i, j : LongInt); - const LUA_ERRFILE = LUA_ERRERR + 1; @@ -651,8 +679,8 @@ PluaL_Reg = ^luaL_Reg; -procedure luaL_openlib(L : Plua_State; const libname : PChar; const lr : PluaL_Reg; nup : LongInt); - cdecl; external LuaLibName; +(*procedure luaL_openlib(L : Plua_State; const libname : PChar; const lr : PluaL_Reg; nup : LongInt); + cdecl; external LuaLibName;*) procedure luaL_register(L : Plua_State; const libname : PChar; const lr : PluaL_Reg); cdecl; external LuaLibName; function luaL_getmetafield(L : Plua_State; obj : LongInt; const e : PChar) : LongInt; @@ -736,10 +764,6 @@ function luaL_typename(L : Plua_State; idx : LongInt) : PChar; -function luaL_dofile(L : Plua_State; fn : PChar) : LongInt; - -function luaL_dostring(L : Plua_State; s : PChar) : LongInt; - procedure luaL_getmetatable(L : Plua_State; n : PChar); (* not implemented yet @@ -761,11 +785,7 @@ end; PluaL_Buffer = ^luaL_Buffer; -procedure luaL_addchar(B : PluaL_Buffer; c : Char); - (* compatibility only *) -procedure luaL_putchar(B : PluaL_Buffer; c : Char); - procedure luaL_addsize(B : PluaL_Buffer; n : LongInt); procedure luaL_buffinit(L : Plua_State; B : PluaL_Buffer); @@ -823,6 +843,28 @@ lua_readline := (b[0] <> #4); // test for ctrl-D end; } + +{$IFNDEF LUA51} + +(* compatibility with 5.2 *) + +function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer; +begin + lua_tointeger := lua_tointegerx(L, idx, nil); +end; + +function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number; +begin + lua_tonumber := lua_tonumberx(L, idx, nil); +end; + +function lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt; +begin + lua_pcall := lua_pcallk(L, nargs, nresults, errfunc, 0, nil); +end; + +{$ENDIF} + procedure lua_saveline(L : Plua_State; idx : LongInt); begin end; @@ -862,11 +904,6 @@ lua_pushcclosure(L, f, 0); end; -function lua_strlen(L : Plua_State; idx : LongInt) : LongInt; -begin - lua_strlen := lua_objlen(L, idx); -end; - function lua_isfunction(L : Plua_State; n : LongInt) : Boolean; begin lua_isfunction := lua_type(L, n) = LUA_TFUNCTION; @@ -912,6 +949,8 @@ lua_pushlstring(L, s, StrLen(s)); end; + +{$IFDEF LUA51} procedure lua_setglobal(L : Plua_State; s : PChar); begin lua_setfield(L, LUA_GLOBALSINDEX, s); @@ -921,6 +960,7 @@ begin lua_getfield(L, LUA_GLOBALSINDEX, s); end; +{$ENDIF} function lua_tostring(L : Plua_State; idx : LongInt) : shortstring; begin @@ -933,7 +973,7 @@ p:= lua_tolstring(L, idx, nil); lua_tostringA := ansistring(p); end; - +(* function lua_open : Plua_State; begin lua_open := luaL_newstate; @@ -948,7 +988,7 @@ begin lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0); end; - +*) (*****************************************************************************) (* lualib.h *) @@ -963,11 +1003,6 @@ (* lauxlib.h n *) (*****************************************************************************) -function luaL_getn(L : Plua_State; idx : LongInt) : LongInt; -begin - luaL_getn := lua_objlen(L, idx); -end; - procedure luaL_setn(L : plua_State; i, j : LongInt); begin (* no op *) @@ -1016,38 +1051,11 @@ luaL_typename := lua_typename( L, lua_type(L, idx) ); end; -function luaL_dofile(L : Plua_State; fn : PChar) : LongInt; -begin - luaL_dofile := luaL_loadfile(L, fn); - if luaL_dofile = 0 then - luaL_dofile := lua_pcall(L, 0, 0, 0); -end; - -function luaL_dostring(L : Plua_State; s : PChar) : LongInt; -begin - luaL_dostring := luaL_loadstring(L, s); - if luaL_dostring = 0 then - luaL_dostring := lua_pcall(L, 0, 0, 0); -end; - procedure luaL_getmetatable(L : Plua_State; n : PChar); begin lua_getfield(L, LUA_REGISTRYINDEX, n); end; -procedure luaL_addchar(B : PluaL_Buffer; c : Char); -begin - if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then - luaL_prepbuffer(B); - (B^.p^) := c; - Inc(B^.p); -end; - -procedure luaL_putchar(B : PluaL_Buffer; c : Char); -begin - luaL_addchar(B, c); -end; - procedure luaL_addsize(B : PluaL_Buffer; n : LongInt); begin Inc(B^.p, n); diff -r 8e62b5cb790c -r aef994a2ec1a hedgewars/uAI.pas --- a/hedgewars/uAI.pas Mon Apr 28 16:49:29 2014 -0400 +++ b/hedgewars/uAI.pas Tue Apr 29 10:20:45 2014 +0400 @@ -146,19 +146,23 @@ BestActions.Score:= Actions.Score + Score; - if HHHasAmmo(Me^.Hedgehog^, amInvulnerable) > 0 then + // if not between shots, activate invulnerability/vampirism if available + if CurrentHedgehog^.MultiShootAttacks = 0 then begin - AddAction(BestActions, aia_Weapon, Longword(amInvulnerable), 80, 0, 0); - AddAction(BestActions, aia_attack, aim_push, 10, 0, 0); - AddAction(BestActions, aia_attack, aim_release, 10, 0, 0); + if HHHasAmmo(Me^.Hedgehog^, amInvulnerable) > 0 then + begin + AddAction(BestActions, aia_Weapon, Longword(amInvulnerable), 80, 0, 0); + AddAction(BestActions, aia_attack, aim_push, 10, 0, 0); + AddAction(BestActions, aia_attack, aim_release, 10, 0, 0); + end; + + if HHHasAmmo(Me^.Hedgehog^, amExtraDamage) > 0 then + begin + AddAction(BestActions, aia_Weapon, Longword(amExtraDamage), 80, 0, 0); + AddAction(BestActions, aia_attack, aim_push, 10, 0, 0); + AddAction(BestActions, aia_attack, aim_release, 10, 0, 0); + end; end; - - if HHHasAmmo(Me^.Hedgehog^, amExtraDamage) > 0 then - begin - AddAction(BestActions, aia_Weapon, Longword(amExtraDamage), 80, 0, 0); - AddAction(BestActions, aia_attack, aim_push, 10, 0, 0); - AddAction(BestActions, aia_attack, aim_release, 10, 0, 0); - end; AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0); diff -r 8e62b5cb790c -r aef994a2ec1a hedgewars/uCommandHandlers.pas --- a/hedgewars/uCommandHandlers.pas Mon Apr 28 16:49:29 2014 -0400 +++ b/hedgewars/uCommandHandlers.pas Tue Apr 29 10:20:45 2014 +0400 @@ -339,7 +339,7 @@ if not isExternalSource then SendIPC(_S'A'); Message:= Message or (gmAttack and InputMask); - ScriptCall('onAttack'); + ScriptCall('onAttack'); // so if I fire airstrike, it doesn't count as attack? fine, fine end end end; diff -r 8e62b5cb790c -r aef994a2ec1a hedgewars/uLandGenTemplateBased.pas --- a/hedgewars/uLandGenTemplateBased.pas Mon Apr 28 16:49:29 2014 -0400 +++ b/hedgewars/uLandGenTemplateBased.pas Tue Apr 29 10:20:45 2014 +0400 @@ -98,7 +98,8 @@ const mapBorderMargin = 40; minDistance = 32; // adjust/parametrize this for different details size var p1, p2, p4, fp, mp: TPoint; - i, t1, t2, a, b, p, q, iy, ix, aqpb: LongInt; + i, t1, t2, iy, ix, aqpb: LongInt; + a, b, p, q: LongInt; dab, d, distL, distR: LongInt; begin // [p1, p2] is the segment we're trying to divide @@ -189,7 +190,7 @@ if (aqpb <> 0) then begin // (ix; iy) is intersection point - iy:= (((pa.ar[i].x - mp.x) * b + mp.y * a) * q - pa.ar[i].y * p * b) div aqpb; + iy:= ((Int64(pa.ar[i].x - mp.x) * b + Int64(mp.y) * a) * q - Int64(pa.ar[i].y) * p * b) div aqpb; if abs(b) > abs(q) then ix:= (iy - mp.y) * a div b + mp.x else @@ -220,7 +221,7 @@ if (aqpb <> 0) then begin // (ix; iy) is intersection point - iy:= (((p1.x - mp.x) * b + mp.y * a) * q - p1.y * p * b) div aqpb; + iy:= ((Int64(p1.x - mp.x) * b + Int64(mp.y) * a) * q - Int64(p1.y) * p * b) div aqpb; if abs(b) > abs(q) then ix:= (iy - mp.y) * a div b + mp.x else @@ -239,7 +240,7 @@ if (aqpb <> 0) then begin // (ix; iy) is intersection point - iy:= (((p2.x - mp.x) * b + mp.y * a) * q - p2.y * p * b) div aqpb; + iy:= ((Int64(p2.x - mp.x) * b + Int64(mp.y) * a) * q - Int64(p2.y) * p * b) div aqpb; if abs(b) > abs(q) then ix:= (iy - mp.y) * a div b + mp.x else @@ -260,8 +261,9 @@ if distR + distL < minDistance * 2 + 10 then begin - // limits are too narrow, leave point alone - newPoint:= p1 + // limits are too narrow, just divide + newPoint.x:= mp.x; + newPoint.y:= mp.y; end else begin diff -r 8e62b5cb790c -r aef994a2ec1a hedgewars/uScript.pas --- a/hedgewars/uScript.pas Mon Apr 28 16:49:29 2014 -0400 +++ b/hedgewars/uScript.pas Tue Apr 29 10:20:45 2014 +0400 @@ -2498,14 +2498,11 @@ cg : TCapGroup; begin // initialize lua -luaState:= lua_open; -TryDo(luaState <> nil, 'lua_open failed', true); +luaState:= luaL_newstate(); +TryDo(luaState <> nil, 'luaL_newstate() failed', true); // open internal libraries -luaopen_base(luaState); -luaopen_string(luaState); -luaopen_math(luaState); -luaopen_table(luaState); +luaL_openlibs(luaState); // import some variables ScriptSetString(_S'L', cLocale); diff -r 8e62b5cb790c -r aef994a2ec1a hedgewars/uStore.pas --- a/hedgewars/uStore.pas Mon Apr 28 16:49:29 2014 -0400 +++ b/hedgewars/uStore.pas Tue Apr 29 10:20:45 2014 +0400 @@ -115,6 +115,7 @@ clr.g:= (Color shr 8) and $FF; clr.b:= Color and $FF; tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, s, clr); +SDLTry(tmpsurf <> nil, true); tmpsurf:= doSurfaceConversion(tmpsurf); SDLTry(tmpsurf <> nil, true); SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect); @@ -1249,7 +1250,7 @@ // make sure there is a caption as well as a sub caption - description is optional if length(caption) = 0 then caption:= ansistring('???'); -if length(caption) = 0 then +if length(subcaption) = 0 then subcaption:= ansistring(_S' '); font:= CheckCJKFont(caption,fnt16); diff -r 8e62b5cb790c -r aef994a2ec1a share/hedgewars/Data/Scripts/Multiplayer/Racer.lua --- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua Mon Apr 28 16:49:29 2014 -0400 +++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua Tue Apr 29 10:20:45 2014 +0400 @@ -136,6 +136,8 @@ local wpCount = 0 local wpLimit = 8 +local usedWeapons = {} + local roundN local lastRound local RoundHasChanged @@ -359,7 +361,7 @@ loc("Best Team Times: ") .. "|" .. totalComment, 0, 4000) -- end game if its at round limit - if roundNumber == roundLimit then + if roundNumber >= roundLimit then for i = 0, (numhhs-1) do if GetHogClan(hhs[i]) ~= bestClan then SetEffect(hhs[i], heResurrectable, 0) @@ -515,22 +517,21 @@ end function PlaceWayPoint(x,y) - - if (wpCount < wpLimit) then -- seems to not work with a hedgehog nil chek + if not racerActive then + if wpCount == 0 or wpX[wpCount - 1] ~= x or wpY[wpCount - 1] ~= y then - wpX[wpCount] = x - wpY[wpCount] = y - wpCol[wpCount] = 0xffffffff - wpCirc[wpCount] = AddVisualGear(wpX[wpCount],wpY[wpCount],vgtCircle,0,true) - --100 - SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], 20, 100, 1, 10, 0, wpRad, 5, wpCol[wpCount]) + wpX[wpCount] = x + wpY[wpCount] = y + wpCol[wpCount] = 0xffffffff + wpCirc[wpCount] = AddVisualGear(wpX[wpCount],wpY[wpCount],vgtCircle,0,true) + + SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], 20, 100, 1, 10, 0, wpRad, 5, wpCol[wpCount]) - wpCount = wpCount + 1 + wpCount = wpCount + 1 - AddCaption(loc("Waypoint placed.") .. " " .. loc("Available points remaining: ") .. (wpLimit-wpCount)) - + AddCaption(loc("Waypoint placed.") .. " " .. loc("Available points remaining: ") .. (wpLimit-wpCount)) end - + end end function onSpecialPoint(x,y,flag) @@ -671,7 +672,6 @@ if (CheckWaypoints() == true) then AdjustScores() - racerActive = false DisableTumbler() end @@ -720,13 +720,44 @@ end +function onAttack() + at = GetCurAmmoType() + + usedWeapons[at] = 0 +end function onAchievementsDeclaration() + usedWeapons[amSkip] = nil + + usedRope = usedWeapons[amRope] ~= nil + usedPortal = usedWeapons[amPortalGun] ~= nil + usedSaucer = usedWeapons[amJetpack] ~= nil + + usedWeapons[amRope] = nil + usedWeapons[amPortalGun] = nil + usedWeapons[amJetpack] = nil + + usedOther = next(usedWeapons) ~= nil + + if usedOther then -- smth besides skip, rope, portal or saucer used + raceType = "unknown race" + elseif usedRope and not usedPortal and not usedSaucer then + raceType = "rope race" + elseif not usedRope and usedPortal and not usedSaucer then + raceType = "portal race" + elseif not usedRope and not usedPortal and usedSaucer then + raceType = "saucer race" + elseif (usedRope or usedPortal or usedSaucer or usedOther) == false then -- no weapons used at all? + raceType = "no tools race" + else -- at least two of rope, portal and saucer used + raceType = "mixed race" + end + map = detectMap() for i = 0, (numTeams-1) do if teamScore[i] < 100000 then - DeclareAchievement("rope race", teamNameArr[i], map, teamScore[i]) + DeclareAchievement(raceType, teamNameArr[i], map, teamScore[i]) end end end