- Code: Select all
const char *GetNPCstateString(int NPCstate)
{
const char *result;
switch(NPCstate)
{
case 0x00:
result = "Seek Food";
break;
case 0x01:
result = "Seek Shelter";
break;
case 0x02:
result = "Purse Shelter";
break;
case 0x03:
result = "Seek Desires";
break;
case 0x04:
result = "Purse Desires";
break;
case 0x05:
result = "Eat Food";
break;
case 0x06:
result = "Loiter";
break;
case 0x07:
result = "Runaway";
break;
case 0x08:
result = "Talking";
break;
case 0x09:
result = "Attack Target";
break;
case 0x0A:
result = "Idle";
break;
case 0x0B:
result = "Wander";
break;
case 0x0C:
result = "Sleep";
break;
case 0x0D:
result = "Following";
break;
default:
result = "Unknown State";
}
return result;
}
In the past I had already found an unused function that would SuperBark the current state of the NPC. However, that function did not match the actual states being used inside the core and scripts. Here's a screenshot of that function: Again, the C version:
- Code: Select all
void FUNC_SuperBarkNPCstate__OLD(NPC *NPCobject)
{
const char *result;
char TempStringBuffer[512];
switch(NPCobject->CurrentState)
{
case 0x00:
result = "Wander";
break;
case 0x01:
result = "Pursue";
break;
case 0x02:
result = "Runaway";
break;
case 0x03:
result = "Combat";
break;
case 0x04:
result = "Following";
break;
case 0x05:
result = "Talking";
break;
case 0x06:
result = "Loiter";
break;
case 0x07:
result = "Sleep";
break;
case 0x0A:
result = "Idle";
break;
default:
result = "Bad State";
}
// Format the state into nice output
sprintf(TempStringBuffer, "myState: %d (%s)", NPCobject->CurrentState, result);
// Bark the nicely formatted state
NPCobject->SuperBark(TempStringBuffer, -1, -1, -1);
}
How did I know which state function is the correct one? Well, the biggest clue is the sleep-state. In the first function I posted that equals state 0x0C, in the other one it is 0x07. There is a script command "goSleep". Let's take a look at that one: For most people, the C version:
- Code: Select all
int COMMAND_goSleep(int NPCserial, int SleepTimeInTicks, int PostSleepState)
{
int result;
// Validate the PostSleepState
if(PostSleepState >= 0 && PostSleepState < 14)
{
// Ensure the given NPC is really a NPC object
NPC NPCobject = ConvertObjectBySerialToNPCobject(NPCserial, "setNPCState");
if(NPCobject != NULL)
{
// Go set the actual sleep state
NPCobject->GoSleep(SleepTimeInTicks, PostSleepState);
result = 1;
}
else
result = 0;
}
else
result = 0;
return result;
}
Thank you OSI for leaving those 2 functions in there, it's gonna be a whole lot easier to understand the NPC AI now and it gives a glimp from your old AI. More to come, but that's going to be for the new year, old year is today. Happy holidays to you all!