From c7cac0dff29a0692ce1580bd0409c93f453a49ac Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Tue, 13 Aug 2019 09:39:47 +0000 Subject: [PATCH] FindClosestBoxingRingSpot: player boxer should try to move out of ring as close to Darren as possible. LUA: added new functions SetgfBoxersResting(), SetgubBoxersRests() to change boxers status. ResetBoxers(): keep gfBoxerFought[] unchanged as it will be reset every day at 15:00 by HourlyQuestUpdate() in HourlyUpdate.lua git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8687 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/LuaInitNPCs.cpp | 38 ++++++++++++++++++++++++++++-------- TacticalAI/FindLocations.cpp | 25 +++++++++++++++--------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index 477bd66d..ab98eaf4 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -372,6 +372,9 @@ static int l_TileIsOutOfBoundsClosestPC (lua_State *L); static int l_SetgfBoxerFought (lua_State *L); static int l_EVENT_StopMerc (lua_State *L); +static int l_SetgfBoxersResting(lua_State *L); +static int l_SetgubBoxersRests(lua_State *L); + static int l_SetEnterCombatMode (lua_State *L); static int l_PlayerInARoom (lua_State *L); @@ -3061,6 +3064,8 @@ BOOLEAN LetLuaHourlyQuestUpdate(UINT8 Init) //-----boxer------ only hourly quest update lua_register(_LS.L(), "gfBoxerFought", l_SetgfBoxerFought); + lua_register(_LS.L(), "SetgfBoxersResting", l_SetgfBoxersResting); + lua_register(_LS.L(), "SetgubBoxersRests", l_SetgubBoxersRests); lua_register(_LS.L(), "GetWorldHour", l_GetWorldHour); SGP_THROW_IFFALSE( _LS.L.EvalFile(filename), _BS("Cannot open file: ") << filename << _BS::cget ); @@ -8220,6 +8225,22 @@ static int l_SetgfBoxerFought (lua_State *L) return 0; } +static int l_SetgfBoxersResting(lua_State *L) +{ + if (lua_gettop(L)) + gfBoxersResting = lua_toboolean(L, 1); + + return 0; +} + +static int l_SetgubBoxersRests(lua_State *L) +{ + if (lua_gettop(L)) + gubBoxersRests = lua_tointeger(L, 1); + + return 0; +} + static int l_GetWorldHour (lua_State *L) { UINT32 h2 = GetWorldHour(); @@ -10464,7 +10485,7 @@ static int l_SetPendingNewScreen (lua_State *L) } //-------------- -//Set charcter to sector Z +//Set character to sector Z static int l_GetCharacterSectorZ (lua_State *L) { UINT8 n = lua_gettop(L); @@ -10484,7 +10505,7 @@ static int l_GetCharacterSectorZ (lua_State *L) return 1; } -//Set charcter to sector Y +//Set character to sector Y static int l_GetCharacterSectorY (lua_State *L) { UINT8 n = lua_gettop(L); @@ -10504,7 +10525,7 @@ static int l_GetCharacterSectorY (lua_State *L) return 1; } -//Set charcter to sector X +//Set character to sector X static int l_GetCharacterSectorX (lua_State *L) { UINT8 n = lua_gettop(L); @@ -10525,7 +10546,7 @@ static int l_GetCharacterSectorX (lua_State *L) } //----------- -//Set charcter to sector Z +//Set character to sector Z static int l_SetCharacterSectorZ (lua_State *L) { if ( lua_gettop( L ) >= 2 ) @@ -10545,13 +10566,14 @@ static int l_ResetBoxers( lua_State *L ) for ( UINT8 i = 0; i < NUM_BOXERS; ++i ) { gubBoxerID[i] = NOBODY; - gfBoxerFought[i] = FALSE; + // sevenfm: keep gfBoxerFought[] unchanged as it will be reset every day at 16:00 by HourlyQuestUpdate(), HourlyUpdate.lua + //gfBoxerFought[i] = FALSE; } return 0; } -//Set charcter to sector Y +//Set character to sector Y static int l_SetCharacterSectorY (lua_State *L) { UINT8 n = lua_gettop(L); @@ -10570,7 +10592,7 @@ static int l_SetCharacterSectorY (lua_State *L) return 0; } -//Set charcter to sector X +//Set character to sector X static int l_SetCharacterSectorX (lua_State *L) { UINT8 n = lua_gettop(L); @@ -10625,7 +10647,7 @@ static int l_TriggerNPCRecordImmediately(lua_State *L) return 0; } -//Add undern Ground Sector +//Add underground Sector static int l_AddAltUnderGroundSectorNew(lua_State *L) { UINT8 x = 0,y = 0,z = 0; diff --git a/TacticalAI/FindLocations.cpp b/TacticalAI/FindLocations.cpp index 5cde47e4..98140b52 100644 --- a/TacticalAI/FindLocations.cpp +++ b/TacticalAI/FindLocations.cpp @@ -2414,9 +2414,10 @@ INT32 FindClosestBoxingRingSpot( SOLDIERTYPE * pSoldier, BOOLEAN fInRing ) INT32 sGridNo, sClosestSpot = NOWHERE; INT32 iDistance, iClosestDistance = 9999; - //DBrot: More Rooms - //UINT8 ubRoom; UINT16 usRoom; + SOLDIERTYPE *pDarren; + UINT8 ubLoop; + pDarren = FindSoldierByProfileID(DARREN, FALSE); // set the distance limit of the square region iSearchRange = 7; @@ -2427,11 +2428,11 @@ INT32 FindClosestBoxingRingSpot( SOLDIERTYPE * pSoldier, BOOLEAN fInRing ) sMaxRight = min( iSearchRange, MAXCOL - ((pSoldier->sGridNo % MAXCOL) + 1)); //NumMessage("sMaxRight = ",sMaxRight); - if ( (pSoldier->bTeam == gbPlayerNum) && (fInRing == FALSE) ) + /*if ( (pSoldier->bTeam == gbPlayerNum) && (fInRing == FALSE) ) { // have player not go to the left of the ring sMaxLeft = 0; - } + }*/ // determine maximum vertical limits sMaxUp = min( iSearchRange, (pSoldier->sGridNo / MAXROW)); @@ -2444,19 +2445,25 @@ INT32 FindClosestBoxingRingSpot( SOLDIERTYPE * pSoldier, BOOLEAN fInRing ) { // calculate the next potential gridno sGridNo = pSoldier->sGridNo + sXOffset + (MAXCOL * sYOffset); - if ( InARoom( sGridNo, &usRoom )) + if (!TileIsOutOfBounds(sGridNo) && + InARoom(sGridNo, &usRoom)) { - if ( (fInRing && usRoom == BOXING_RING) || (!fInRing && usRoom != BOXING_RING ) && LegalNPCDestination(pSoldier,sGridNo,IGNORE_PATH,NOWATER,0) ) + if ((fInRing && usRoom == BOXING_RING) || (!fInRing && usRoom != BOXING_RING) && + LegalNPCDestination(pSoldier, sGridNo, IGNORE_PATH, NOWATER, 0)) { - iDistance = abs( sXOffset ) + abs( sYOffset ); - if ( iDistance < iClosestDistance && WhoIsThere2( sGridNo, 0 ) == NOBODY ) + // sevenfm: for player merc, find spot closest to Darren + if (pDarren && pSoldier->bTeam == gbPlayerNum) + iDistance = PythSpacesAway(pDarren->sGridNo, sGridNo) + PythSpacesAway(pSoldier->sGridNo, sGridNo); + else + iDistance = abs(sXOffset) + abs(sYOffset); + + if (iDistance < iClosestDistance && WhoIsThere2(sGridNo, 0) == NOBODY) { sClosestSpot = sGridNo; iClosestDistance = iDistance; } } } - } }