Skip to content

Commit

Permalink
Merge pull request #742 from LoboEire/master
Browse files Browse the repository at this point in the history
New Friendly logic
  • Loading branch information
dashodanger authored Oct 27, 2024
2 parents 0a338f9 + a91f13d commit cf9081a
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 7 deletions.
3 changes: 3 additions & 0 deletions source_files/ddf/ddf_thing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ const DDFActionCode thing_actions[] = {{"NOTHING", nullptr, nullptr},
{"SET_INVULNERABLE", A_SetInvuln, nullptr},
{"CLEAR_INVULNERABLE", A_ClearInvuln, nullptr},
{"SET_PAINCHANCE", A_PainChanceSet, DDFStateGetPercent},

{"CLEAR_TARGET", A_ClearTarget, nullptr},
{"FRIEND_LOOKOUT", A_FriendLook, nullptr},

{"DROPITEM", A_DropItem, DDFStateGetMobj},
{"SPAWN", A_Spawn, DDFStateGetMobj},
Expand Down
81 changes: 81 additions & 0 deletions source_files/edge/p_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5084,5 +5084,86 @@ void A_PainChanceSet(MapObject *mo)
mo->pain_chance_ = value;
}


// Thing will forget both current target and supported player
void A_ClearTarget(MapObject *object)
{
object->SetTarget(nullptr);
object->SetSupportObject(nullptr);
}

//
// Similar to SUPPORT_LOOKOUT but will not go to MEANDER states automatically.
// Look for players AND enemies.
// - If we have no player to support we try and find one.
// - If we have no SIDE set then we will get one.
// - If we see an enemy then we target him.
void A_FriendLook(MapObject *object)
{
object->threshold_ = 0; // any shot will wake up

if (!object->support_object_) //no player to support yet
{
if (FindPlayerToSupport(object)) //try and find a player. One way or the other we will have a side at least
{
if (object->info_->seesound_)
{
StartSoundEffect(object->info_->seesound_, GetSoundEffectCategory(object), object, SfxFlags(object->info_));
}
}
}

/*
if (object->flags_ & kMapObjectFlagStealth)
object->target_visibility_ = 1.0f;
if (force_infighting.d_)
if (CreateAggression(object) || CreateAggression(object))
return;
*/

if (!A_LookForTargets(object)) //No target found
return;
else
{
if (object->info_->seesound_)
{
StartSoundEffect(object->info_->seesound_, GetSoundEffectCategory(object), object, SfxFlags(object->info_));
}
}


}

//
// FindPlayerToSupport
//
// Look for a Player to support
//
bool FindPlayerToSupport(MapObject *object)
{
if (object->flags_ & kMapObjectFlagStealth)
object->target_visibility_ = 1.0f;

if (LookForPlayers(object, object->info_->sight_angle_, true)) //any players around to support?
{
// join the player's side
if (object->side_ == 0)
{
if (object->support_object_ && object->support_object_->player_)
object->side_ = object->support_object_->side_;
}

return true;
}

//default to something at least
object->side_ = 1;

return false;

}


//--- editor settings ---
// vi:ts=4:sw=4:noexpandtab
4 changes: 4 additions & 0 deletions source_files/edge/p_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ void A_ClearInvuln(MapObject *mo);

void A_PainChanceSet(MapObject *mo);

void A_ClearTarget(MapObject *mo);
void A_FriendLook(MapObject *mo);
bool FindPlayerToSupport(MapObject *mo);

// Movement actions
void A_FaceDir(MapObject *mo);
void A_TurnDir(MapObject *mo);
Expand Down
22 changes: 16 additions & 6 deletions source_files/edge/p_enemy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,14 @@ void NewChaseDir(MapObject *object)
object->move_direction_ = kDirectionNone;
}


//
// Used to find a player, either to set as support object or to set as a target.
// Range is angle range on either side of eyes, 90 degrees for normal
// view, 180 degrees for total sight in all dirs.
// Returns true if a player is found.
//
// Returns true if a player is targeted.
//
bool LookForPlayers(MapObject *actor, BAMAngle range)
bool LookForPlayers(MapObject *actor, BAMAngle range, bool ToSupport)
{
int c;
int stop;
Expand Down Expand Up @@ -488,7 +489,10 @@ bool LookForPlayers(MapObject *actor, BAMAngle range)

// on the same team ?
if ((actor->side_ & player->map_object_->side_) != 0)
continue;
{
if (!ToSupport) //not looking to support a player
continue;
}

if (range < kBAMAngle180)
{
Expand All @@ -509,13 +513,19 @@ bool LookForPlayers(MapObject *actor, BAMAngle range)
if (!CheckSight(actor, player->map_object_))
continue;

actor->SetTarget(player->map_object_);
return true;
if (ToSupport) //support the player
actor->SetSupportObject(player->map_object_);
else // target the player
actor->SetTarget(player->map_object_);

return true;

}

return false;
}


//
// BOSS-BRAIN HANDLING
//
Expand Down
3 changes: 2 additions & 1 deletion source_files/edge/p_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ extern float yspeed[8];
void NoiseAlert(Player *p);
void NewChaseDir(MapObject *actor);
bool DoMove(MapObject *actor, bool path);
bool LookForPlayers(MapObject *actor, BAMAngle range);
bool LookForPlayers(MapObject *actor, BAMAngle range, bool ToSupport = false);

MapObject *LookForShootSpot(const MapObjectDefinition *spot_type);

//
Expand Down
2 changes: 2 additions & 0 deletions source_files/edge/p_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ static MapObject *SpawnMapThing(const MapObjectDefinition *info, float x, float
{
mo->side_ = 1; //~0;
mo->hyper_flags_ |= kHyperFlagUltraLoyal;
//mo->extended_flags_ &= ~kExtendedFlagDisloyalToOwnType; //remove this flag just in case

/*
player_t *player;
player = players[0];
Expand Down
7 changes: 7 additions & 0 deletions source_files/edge/p_sight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ static bool CheckSightSameSubsector(MapObject *src, MapObject *dest)

bool CheckSight(MapObject *src, MapObject *dest)
{
if (!dest)
return false;

// -ACB- 1998/07/20 t2 is Invisible, t1 cannot possibly see it.
if (AlmostEquals(dest->visibility_, 0.0f))
return false;
Expand Down Expand Up @@ -462,7 +465,11 @@ bool CheckSight(MapObject *src, MapObject *dest)
if (src->info_->sight_distance_ > -1) // if we have sight_distance set
{
if (src->info_->sight_distance_ < dist_a)
{
//src->SetTarget(nullptr); //forget we even saw the guy?
return false; // too far away for this thing to see
}

}

#if (EDGE_DEBUG_SIGHT >= 1)
Expand Down

0 comments on commit cf9081a

Please sign in to comment.