mirror of
https://gitlab.com/drummyfish/anarch.git
synced 2024-11-22 00:42:16 -05:00
Fix and improve monster dist check
This commit is contained in:
parent
4f50aef17a
commit
b535d923f7
35
main.c
35
main.c
@ -1214,6 +1214,7 @@ uint8_t SFG_launchProjectile(
|
|||||||
void SFG_monsterPerformAI(SFG_MonsterRecord *monster)
|
void SFG_monsterPerformAI(SFG_MonsterRecord *monster)
|
||||||
{
|
{
|
||||||
uint8_t state = monster->stateType & SFG_MONSTER_MASK_STATE;
|
uint8_t state = monster->stateType & SFG_MONSTER_MASK_STATE;
|
||||||
|
|
||||||
uint8_t type = monster->stateType & SFG_MONSTER_MASK_TYPE;
|
uint8_t type = monster->stateType & SFG_MONSTER_MASK_TYPE;
|
||||||
|
|
||||||
int8_t coordAdd[2];
|
int8_t coordAdd[2];
|
||||||
@ -2013,8 +2014,14 @@ void SFG_gameStep()
|
|||||||
if (SFG_currentLevel.doorRecordCount > 0) // has to be here
|
if (SFG_currentLevel.doorRecordCount > 0) // has to be here
|
||||||
{
|
{
|
||||||
/* Check one door on whether a player is standing nearby. For performance
|
/* Check one door on whether a player is standing nearby. For performance
|
||||||
reasons we only check one door and move to another in the next frame. */
|
reasons we only check a few doors and move to others in the next
|
||||||
|
frame. */
|
||||||
|
|
||||||
|
for (uint16_t i = 0;
|
||||||
|
i < RCL_min(SFG_ELEMENT_DISTANCES_CHECKED_PER_FRAME,
|
||||||
|
SFG_currentLevel.doorRecordCount);
|
||||||
|
++i)
|
||||||
|
{
|
||||||
SFG_DoorRecord *door =
|
SFG_DoorRecord *door =
|
||||||
&(SFG_currentLevel.doorRecords[SFG_currentLevel.checkedDoorIndex]);
|
&(SFG_currentLevel.doorRecords[SFG_currentLevel.checkedDoorIndex]);
|
||||||
|
|
||||||
@ -2031,6 +2038,7 @@ void SFG_gameStep()
|
|||||||
|
|
||||||
if (SFG_currentLevel.checkedDoorIndex >= SFG_currentLevel.doorRecordCount)
|
if (SFG_currentLevel.checkedDoorIndex >= SFG_currentLevel.doorRecordCount)
|
||||||
SFG_currentLevel.checkedDoorIndex = 0;
|
SFG_currentLevel.checkedDoorIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < SFG_currentLevel.doorRecordCount; ++i)
|
for (uint32_t i = 0; i < SFG_currentLevel.doorRecordCount; ++i)
|
||||||
{
|
{
|
||||||
@ -2049,6 +2057,13 @@ void SFG_gameStep()
|
|||||||
// handle items, in a similar manner to door:
|
// handle items, in a similar manner to door:
|
||||||
|
|
||||||
if (SFG_currentLevel.itemRecordCount > 0) // has to be here
|
if (SFG_currentLevel.itemRecordCount > 0) // has to be here
|
||||||
|
{
|
||||||
|
// check item distances:
|
||||||
|
|
||||||
|
for (uint16_t i = 0;
|
||||||
|
i < RCL_min(SFG_ELEMENT_DISTANCES_CHECKED_PER_FRAME,
|
||||||
|
SFG_currentLevel.itemRecordCount);
|
||||||
|
++i)
|
||||||
{
|
{
|
||||||
SFG_ItemRecord item =
|
SFG_ItemRecord item =
|
||||||
SFG_currentLevel.itemRecords[SFG_currentLevel.checkedItemIndex];
|
SFG_currentLevel.itemRecords[SFG_currentLevel.checkedItemIndex];
|
||||||
@ -2074,15 +2089,23 @@ void SFG_gameStep()
|
|||||||
if (SFG_currentLevel.checkedItemIndex >= SFG_currentLevel.itemRecordCount)
|
if (SFG_currentLevel.checkedItemIndex >= SFG_currentLevel.itemRecordCount)
|
||||||
SFG_currentLevel.checkedItemIndex = 0;
|
SFG_currentLevel.checkedItemIndex = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// similarly handle monsters:
|
// similarly handle monsters:
|
||||||
|
|
||||||
if (SFG_currentLevel.monsterRecordCount > 0) // has to be here
|
if (SFG_currentLevel.monsterRecordCount > 0) // has to be here
|
||||||
|
{
|
||||||
|
// check monster distances:
|
||||||
|
|
||||||
|
for (uint16_t i = 0;
|
||||||
|
i < RCL_min(SFG_ELEMENT_DISTANCES_CHECKED_PER_FRAME,
|
||||||
|
SFG_currentLevel.monsterRecordCount);
|
||||||
|
++i)
|
||||||
{
|
{
|
||||||
SFG_MonsterRecord *monster =
|
SFG_MonsterRecord *monster =
|
||||||
&(SFG_currentLevel.monsterRecords[SFG_currentLevel.checkedMonsterIndex]);
|
&(SFG_currentLevel.monsterRecords[SFG_currentLevel.checkedMonsterIndex]);
|
||||||
|
|
||||||
if (
|
if ( // far away from the player?
|
||||||
RCL_absVal(SFG_player.squarePosition[0] - monster->coords[0] / 4)
|
RCL_absVal(SFG_player.squarePosition[0] - monster->coords[0] / 4)
|
||||||
> SFG_LEVEL_ELEMENT_ACTIVE_DISTANCE
|
> SFG_LEVEL_ELEMENT_ACTIVE_DISTANCE
|
||||||
||
|
||
|
||||||
@ -2094,7 +2117,8 @@ void SFG_gameStep()
|
|||||||
(monster->stateType & SFG_MONSTER_MASK_TYPE) |
|
(monster->stateType & SFG_MONSTER_MASK_TYPE) |
|
||||||
SFG_MONSTER_STATE_INACTIVE;
|
SFG_MONSTER_STATE_INACTIVE;
|
||||||
}
|
}
|
||||||
else if (monster->stateType == SFG_MONSTER_STATE_INACTIVE)
|
else if ((monster->stateType & SFG_MONSTER_MASK_STATE) ==
|
||||||
|
SFG_MONSTER_STATE_INACTIVE)
|
||||||
{
|
{
|
||||||
monster->stateType =
|
monster->stateType =
|
||||||
(monster->stateType & SFG_MONSTER_MASK_TYPE) |
|
(monster->stateType & SFG_MONSTER_MASK_TYPE) |
|
||||||
@ -2107,14 +2131,15 @@ void SFG_gameStep()
|
|||||||
SFG_currentLevel.monsterRecordCount)
|
SFG_currentLevel.monsterRecordCount)
|
||||||
SFG_currentLevel.checkedMonsterIndex = 0;
|
SFG_currentLevel.checkedMonsterIndex = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update AI
|
// update AI
|
||||||
|
|
||||||
if ((SFG_gameFrame - SFG_currentLevel.frameStart) %
|
if ((SFG_gameFrame - SFG_currentLevel.frameStart) %
|
||||||
SFG_AI_UPDATE_FRAME_INTERVAL == 0)
|
SFG_AI_UPDATE_FRAME_INTERVAL == 0)
|
||||||
for (uint8_t i = 0; i < SFG_currentLevel.monsterRecordCount; ++i)
|
for (uint8_t i = 0; i < SFG_currentLevel.monsterRecordCount; ++i)
|
||||||
if (SFG_currentLevel.monsterRecords[i].stateType !=
|
if ((SFG_currentLevel.monsterRecords[i].stateType &
|
||||||
SFG_MONSTER_STATE_INACTIVE)
|
SFG_MONSTER_MASK_STATE) != SFG_MONSTER_STATE_INACTIVE)
|
||||||
SFG_monsterPerformAI(
|
SFG_monsterPerformAI(
|
||||||
&(SFG_currentLevel.monsterRecords[i]));
|
&(SFG_currentLevel.monsterRecords[i]));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user