mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Added missing #includes Added LUA scripting and console Changed the way tracers are visualized, so they work more like real tracers instead of a light fountain Fixed signedness of many grid variables used in GetMouseMapPos calls Fixed enemy weapon choosing: Sometimes a mortar is chosen but later rejected, but the grenade class was not reset. Caused assertion failure Added checks so enemies don't try to chuck RPG grenades with their hands Now possible to shoot a someone in the head if he's in water Fixed InitSightArrays to also clear soldier interrupt duel points. This was causing an assertion failure elsewhere in the code because the interrupt list still had soldiers on it sometimes when this function was called. Soldiers are much less willing to forfeit their turn over an attempt to use more APs than they have Removed early setting of muzzle flash. This would allow enemies to get an interrupt before you even fired. Fixed item dropping by AI. If AI tried to drop something while standing it would cause deadlock Change to greatly speed up closing the sector inventory window in an unloaded sector Added conditional compile flag to always give robot weapon ready advantage, even for 360 degree sighting Check builddefines.h for the conditional flags. Of greatest interest might be LUA_CONSOLE. This will cause the game to bring up a command console when run. However this console is severely lacking in many areas. If anybody knows of an open-source terminal/console that could be used instead, it would be appreciated. The existing console does bad things when you try to close it, and since it counts as a separate app, it pauses the game while it has focus. LUA scripting is very limited, basically just proof of concept. There is one global variable, the Soldiers array. An array index gives you the soldier in that slot in the currently loaded sector. The soldier has a few things that can be accessed: name (short name); fullname (long name); grid (current grid #, can be changed); walkto(grid) (function to walk to another grid); runto(grid) (function to run to another grid) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@924 3b4a5df2-a311-0410-b5c6-a8a6f20db521
270 lines
7.1 KiB
C++
270 lines
7.1 KiB
C++
#ifdef PRECOMPILEDHEADERS
|
|
#include "AI All.h"
|
|
#else
|
|
#include "ai.h"
|
|
#include "AIInternals.h"
|
|
#include "Isometric utils.h"
|
|
#include "Points.h"
|
|
#include "overhead.h"
|
|
#include "opplist.h"
|
|
#include "rotting corpses.h"
|
|
#include "soldier add.h"
|
|
#include "Soldier Profile Type.h"
|
|
#include "Items.h"
|
|
#include "Weapons.h"
|
|
#include "Soldier Macros.h"
|
|
#include "Soldier Profile.h"
|
|
#include "NPC.h"
|
|
#include "Render Fun.h"
|
|
#include "Quests.h"
|
|
#endif
|
|
|
|
INT8 RTPlayerDecideAction( SOLDIERTYPE * pSoldier )
|
|
{
|
|
INT8 bAction=AI_ACTION_NONE;
|
|
|
|
if (gTacticalStatus.fAutoBandageMode)
|
|
{
|
|
bAction = DecideAutoBandage( pSoldier );
|
|
}
|
|
else
|
|
{
|
|
bAction = DecideAction( pSoldier );
|
|
}
|
|
|
|
#ifdef DEBUGDECISIONS
|
|
STR tempstr;
|
|
sprintf(tempstr,"DecideAction: selected action %d, actionData %d\n\n",bAction,pSoldier->usActionData);
|
|
DebugAI( tempstr );
|
|
#endif
|
|
|
|
return(bAction);
|
|
}
|
|
|
|
INT8 RTDecideAction(SOLDIERTYPE *pSoldier)
|
|
{
|
|
if (CREATURE_OR_BLOODCAT( pSoldier ) )
|
|
{
|
|
return( CreatureDecideAction( pSoldier ) );
|
|
}
|
|
else if (pSoldier->ubBodyType == CROW)
|
|
{
|
|
return( CrowDecideAction( pSoldier ) );
|
|
}
|
|
else if (pSoldier->bTeam == gbPlayerNum)
|
|
{
|
|
return( RTPlayerDecideAction( pSoldier ) );
|
|
}
|
|
else
|
|
{
|
|
// handle traversal
|
|
if ( (pSoldier->ubProfile != NO_PROFILE) && (gMercProfiles[ pSoldier->ubProfile ].ubMiscFlags3 & PROFILE_MISC_FLAG3_HANDLE_DONE_TRAVERSAL ) )
|
|
{
|
|
TriggerNPCWithGivenApproach( pSoldier->ubProfile, APPROACH_DONE_TRAVERSAL, FALSE );
|
|
gMercProfiles[ pSoldier->ubProfile ].ubMiscFlags3 &= (~PROFILE_MISC_FLAG3_HANDLE_DONE_TRAVERSAL);
|
|
pSoldier->ubQuoteActionID = 0;
|
|
// wait a tiny bit
|
|
pSoldier->usActionData = 100;
|
|
return( AI_ACTION_WAIT );
|
|
}
|
|
|
|
return( DecideAction( pSoldier ) );
|
|
}
|
|
}
|
|
|
|
UINT16 RealtimeDelay( SOLDIERTYPE * pSoldier )
|
|
{
|
|
if ( PTR_CIV_OR_MILITIA && !(pSoldier->ubCivilianGroup == KINGPIN_CIV_GROUP ) )
|
|
{
|
|
return( (UINT16) REALTIME_CIV_AI_DELAY );
|
|
}
|
|
else if ( CREATURE_OR_BLOODCAT( pSoldier ) && !( pSoldier->bHunting ) )
|
|
{
|
|
return( (UINT16) REALTIME_CREATURE_AI_DELAY );
|
|
}
|
|
else
|
|
{
|
|
|
|
if ( pSoldier->ubCivilianGroup == KINGPIN_CIV_GROUP )
|
|
{
|
|
UINT8 ubRoom;
|
|
|
|
if ( InARoom( pSoldier->sGridNo, &ubRoom ) && IN_BROTHEL( ubRoom ) )
|
|
{
|
|
return( (UINT16) (REALTIME_AI_DELAY / 3) );
|
|
}
|
|
}
|
|
|
|
return( (UINT16) REALTIME_AI_DELAY );
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void RTHandleAI( SOLDIERTYPE * pSoldier )
|
|
{
|
|
#ifdef AI_PROFILING
|
|
INT32 iLoop;
|
|
#endif
|
|
|
|
if ((pSoldier->bAction != AI_ACTION_NONE) && pSoldier->bActionInProgress)
|
|
{
|
|
// if action should remain in progress
|
|
if (ActionInProgress(pSoldier))
|
|
{
|
|
#ifdef DEBUGBUSY
|
|
AINumMessage("Busy with action, skipping guy#",pSoldier->ubID);
|
|
#endif
|
|
// let it continue
|
|
return;
|
|
}
|
|
}
|
|
|
|
// if man has nothing to do
|
|
if (pSoldier->bAction == AI_ACTION_NONE)
|
|
{
|
|
if (pSoldier->bNextAction == AI_ACTION_NONE)
|
|
{
|
|
// make sure this flag is turned off (it already should be!)
|
|
pSoldier->bActionInProgress = FALSE;
|
|
|
|
// truly nothing to do!
|
|
RefreshAI( pSoldier );
|
|
}
|
|
|
|
// Since we're NEVER going to "continue" along an old path at this point,
|
|
// then it would be nice place to reinitialize "pathStored" flag for
|
|
// insurance purposes.
|
|
//
|
|
// The "pathStored" variable controls whether it's necessary to call
|
|
// findNewPath() after you've called NewDest(). Since the AI calls
|
|
// findNewPath() itself, a speed gain can be obtained by avoiding
|
|
// redundancy.
|
|
//
|
|
// The "normal" way for pathStored to be reset is inside
|
|
// SetNewCourse() [which gets called after NewDest()].
|
|
//
|
|
// The only reason we would NEED to reinitialize it here is if I've
|
|
// incorrectly set pathStored to TRUE in a process that doesn't end up
|
|
// calling NewDest()
|
|
pSoldier->bPathStored = FALSE;
|
|
|
|
// decide on the next action
|
|
#ifdef AI_PROFILING
|
|
for (iLoop = 0; iLoop < 1000; iLoop++)
|
|
#endif
|
|
{
|
|
if (pSoldier->bNextAction != AI_ACTION_NONE)
|
|
{
|
|
if ( pSoldier->bNextAction == AI_ACTION_END_COWER_AND_MOVE )
|
|
{
|
|
if ( pSoldier->uiStatusFlags & SOLDIER_COWERING )
|
|
{
|
|
pSoldier->bAction = AI_ACTION_STOP_COWERING;
|
|
pSoldier->usActionData = ANIM_STAND;
|
|
}
|
|
else if ( gAnimControl[ pSoldier->usAnimState ].ubEndHeight < ANIM_STAND )
|
|
{
|
|
// stand up!
|
|
pSoldier->bAction = AI_ACTION_CHANGE_STANCE;
|
|
pSoldier->usActionData = ANIM_STAND;
|
|
}
|
|
else
|
|
{
|
|
pSoldier->bAction = AI_ACTION_NONE;
|
|
}
|
|
if ( pSoldier->sGridNo == pSoldier->usNextActionData )
|
|
{
|
|
// no need to walk after this
|
|
pSoldier->bNextAction = AI_ACTION_NONE;
|
|
pSoldier->usNextActionData = NOWHERE;
|
|
}
|
|
else
|
|
{
|
|
pSoldier->bNextAction = AI_ACTION_WALK;
|
|
// leave next-action-data as is since that's where we want to go
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// do the next thing we have to do...
|
|
pSoldier->bAction = pSoldier->bNextAction;
|
|
pSoldier->usActionData = pSoldier->usNextActionData;
|
|
pSoldier->bTargetLevel = pSoldier->bNextTargetLevel;
|
|
pSoldier->bNextAction = AI_ACTION_NONE;
|
|
pSoldier->usNextActionData = 0;
|
|
pSoldier->bNextTargetLevel = 0;
|
|
}
|
|
if (pSoldier->bAction == AI_ACTION_PICKUP_ITEM)
|
|
{
|
|
// the item pool index was stored in the special data field
|
|
pSoldier->uiPendingActionData1 = pSoldier->iNextActionSpecialData;
|
|
}
|
|
}
|
|
else if ( pSoldier->sAbsoluteFinalDestination != NOWHERE )
|
|
{
|
|
if ( ACTING_ON_SCHEDULE( pSoldier ) )
|
|
{
|
|
pSoldier->bAction = AI_ACTION_SCHEDULE_MOVE;
|
|
}
|
|
else
|
|
{
|
|
pSoldier->bAction = AI_ACTION_WALK;
|
|
}
|
|
pSoldier->usActionData = pSoldier->sAbsoluteFinalDestination;
|
|
}
|
|
else
|
|
{
|
|
if (!(gTacticalStatus.uiFlags & ENGAGED_IN_CONV))
|
|
{
|
|
pSoldier->bAction = RTDecideAction( pSoldier );
|
|
}
|
|
}
|
|
}
|
|
// if he chose to continue doing nothing
|
|
if (pSoldier->bAction == AI_ACTION_NONE)
|
|
{
|
|
#ifdef RECORDNET
|
|
fprintf(NetDebugFile,"\tMOVED BECOMING TRUE: Chose to do nothing, guynum %d\n",pSoldier->ubID);
|
|
#endif
|
|
|
|
// do a standard wait before doing anything else!
|
|
pSoldier->bAction = AI_ACTION_WAIT;
|
|
//if (PTR_CIVILIAN && pSoldier->bAlertStatus != STATUS_BLACK)
|
|
if ( PTR_CIV_OR_MILITIA && !(pSoldier->ubCivilianGroup == KINGPIN_CIV_GROUP ) )
|
|
{
|
|
pSoldier->usActionData = (UINT16) REALTIME_CIV_AI_DELAY;
|
|
}
|
|
else if ( CREATURE_OR_BLOODCAT( pSoldier ) && !( pSoldier->bHunting ) )
|
|
{
|
|
pSoldier->usActionData = (UINT16) REALTIME_CREATURE_AI_DELAY;
|
|
}
|
|
else
|
|
{
|
|
pSoldier->usActionData = (UINT16) REALTIME_AI_DELAY;
|
|
if ( pSoldier->ubCivilianGroup == KINGPIN_CIV_GROUP )
|
|
{
|
|
UINT8 ubRoom;
|
|
|
|
if ( InARoom( pSoldier->sGridNo, &ubRoom ) && IN_BROTHEL( ubRoom ) )
|
|
{
|
|
pSoldier->usActionData /= 3;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
else if (pSoldier->bAction == AI_ACTION_ABSOLUTELY_NONE)
|
|
{
|
|
pSoldier->bAction = AI_ACTION_NONE;
|
|
}
|
|
|
|
}
|
|
|
|
// to get here, we MUST have an action selected, but not in progress...
|
|
NPCDoesAct(pSoldier);
|
|
|
|
// perform the chosen action
|
|
pSoldier->bActionInProgress = ExecuteAction(pSoldier); // if started, mark us as busy
|
|
}
|