fp: Add an aggro flag on terry
This commit is contained in:
+33
-4
@@ -667,8 +667,37 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Determine acceleration to move towards next waypoint if we have one
|
||||
// NOTE: Determine AI movement =============================================================
|
||||
if (acceleration.x == 0 && acceleration.y == 0) {
|
||||
Dqn_V2 entity_pos = FP_Game_CalcEntityWorldPos(game, entity->handle);
|
||||
|
||||
if (entity->flags & FP_GameEntityFlag_AggrosWhenNearTerry) {
|
||||
Dqn_f32 closest_terry_dist = DQN_F32_MAX;
|
||||
Dqn_V2 closest_terry_pos = Dqn_V2_InitNx1(DQN_F32_MAX);
|
||||
FP_GameEntity *closest_terry = nullptr;
|
||||
for (FP_GameEntityIterator terry_it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &terry_it, game->root_entity); ) {
|
||||
FP_GameEntity *terry = terry_it.entity;
|
||||
if (terry->type != FP_EntityType_Terry)
|
||||
continue;
|
||||
|
||||
Dqn_V2 terry_pos = FP_Game_CalcEntityWorldPos(game, terry->handle);
|
||||
Dqn_f32 dist_to_terry = Dqn_V2_LengthSq_V2x2(terry_pos, entity_pos);
|
||||
if (dist_to_terry < closest_terry_dist) {
|
||||
closest_terry_pos = terry_pos;
|
||||
closest_terry_dist = dist_to_terry;
|
||||
closest_terry = terry;
|
||||
}
|
||||
}
|
||||
|
||||
if (closest_terry_dist < DQN_SQUARED(200.f)) {
|
||||
FP_SentinelListLink<FP_GameEntityHandle> *first_waypoint = FP_SentinelList_Front(&entity->waypoints);
|
||||
if (first_waypoint->data != closest_terry->handle) {
|
||||
FP_SentinelListLink<FP_GameEntityHandle> *link = FP_SentinelList_MakeBefore(&entity->waypoints, first_waypoint, game->chunk_pool);
|
||||
link->data = closest_terry->handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (entity->waypoints.size) {
|
||||
FP_SentinelListLink<FP_GameEntityHandle> *waypoint_link = entity->waypoints.sentinel->next;
|
||||
FP_GameEntity *waypoint = FP_Game_GetEntity(game, waypoint_link->data);
|
||||
@@ -679,7 +708,6 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
|
||||
|
||||
// NOTE: We found a waypoint that is valid to move towards
|
||||
Dqn_V2 waypoint_pos = FP_Game_CalcEntityWorldPos(game, waypoint->handle);
|
||||
Dqn_V2 entity_pos = FP_Game_CalcEntityWorldPos(game, entity->handle);
|
||||
Dqn_V2 entity_to_waypoint = waypoint_pos - entity_pos;
|
||||
|
||||
// NOTE: Check if we've arrived at the waypoint
|
||||
@@ -842,8 +870,9 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
|
||||
link->data = FP_Entity_CreateSmoochie(game, entity_world_pos, "Smoochie");
|
||||
|
||||
// NOTE: Setup the mob with waypoints
|
||||
FP_GameEntity *mob = FP_Game_GetEntity(game, link->data);
|
||||
mob->waypoints = FP_SentinelList_Init<FP_GameEntityHandle>(game->chunk_pool);
|
||||
FP_GameEntity *mob = FP_Game_GetEntity(game, link->data);
|
||||
mob->waypoints = FP_SentinelList_Init<FP_GameEntityHandle>(game->chunk_pool);
|
||||
mob->flags |= FP_GameEntityFlag_AggrosWhenNearTerry;
|
||||
|
||||
for (FP_GameEntity *waypoint_entity = entity->first_child; waypoint_entity; waypoint_entity = waypoint_entity->next) {
|
||||
if ((waypoint_entity->flags & FP_GameEntityFlag_MobSpawnerWaypoint) == 0)
|
||||
|
||||
Reference in New Issue
Block a user