Skip to content

Commit cf9081a

Browse files
authored
Merge pull request #742 from LoboEire/master
New Friendly logic
2 parents 0a338f9 + a91f13d commit cf9081a

File tree

7 files changed

+115
-7
lines changed

7 files changed

+115
-7
lines changed

source_files/ddf/ddf_thing.cc

+3
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ const DDFActionCode thing_actions[] = {{"NOTHING", nullptr, nullptr},
311311
{"SET_INVULNERABLE", A_SetInvuln, nullptr},
312312
{"CLEAR_INVULNERABLE", A_ClearInvuln, nullptr},
313313
{"SET_PAINCHANCE", A_PainChanceSet, DDFStateGetPercent},
314+
315+
{"CLEAR_TARGET", A_ClearTarget, nullptr},
316+
{"FRIEND_LOOKOUT", A_FriendLook, nullptr},
314317

315318
{"DROPITEM", A_DropItem, DDFStateGetMobj},
316319
{"SPAWN", A_Spawn, DDFStateGetMobj},

source_files/edge/p_action.cc

+81
Original file line numberDiff line numberDiff line change
@@ -5084,5 +5084,86 @@ void A_PainChanceSet(MapObject *mo)
50845084
mo->pain_chance_ = value;
50855085
}
50865086

5087+
5088+
// Thing will forget both current target and supported player
5089+
void A_ClearTarget(MapObject *object)
5090+
{
5091+
object->SetTarget(nullptr);
5092+
object->SetSupportObject(nullptr);
5093+
}
5094+
5095+
//
5096+
// Similar to SUPPORT_LOOKOUT but will not go to MEANDER states automatically.
5097+
// Look for players AND enemies.
5098+
// - If we have no player to support we try and find one.
5099+
// - If we have no SIDE set then we will get one.
5100+
// - If we see an enemy then we target him.
5101+
void A_FriendLook(MapObject *object)
5102+
{
5103+
object->threshold_ = 0; // any shot will wake up
5104+
5105+
if (!object->support_object_) //no player to support yet
5106+
{
5107+
if (FindPlayerToSupport(object)) //try and find a player. One way or the other we will have a side at least
5108+
{
5109+
if (object->info_->seesound_)
5110+
{
5111+
StartSoundEffect(object->info_->seesound_, GetSoundEffectCategory(object), object, SfxFlags(object->info_));
5112+
}
5113+
}
5114+
}
5115+
5116+
/*
5117+
if (object->flags_ & kMapObjectFlagStealth)
5118+
object->target_visibility_ = 1.0f;
5119+
5120+
if (force_infighting.d_)
5121+
if (CreateAggression(object) || CreateAggression(object))
5122+
return;
5123+
*/
5124+
5125+
if (!A_LookForTargets(object)) //No target found
5126+
return;
5127+
else
5128+
{
5129+
if (object->info_->seesound_)
5130+
{
5131+
StartSoundEffect(object->info_->seesound_, GetSoundEffectCategory(object), object, SfxFlags(object->info_));
5132+
}
5133+
}
5134+
5135+
5136+
}
5137+
5138+
//
5139+
// FindPlayerToSupport
5140+
//
5141+
// Look for a Player to support
5142+
//
5143+
bool FindPlayerToSupport(MapObject *object)
5144+
{
5145+
if (object->flags_ & kMapObjectFlagStealth)
5146+
object->target_visibility_ = 1.0f;
5147+
5148+
if (LookForPlayers(object, object->info_->sight_angle_, true)) //any players around to support?
5149+
{
5150+
// join the player's side
5151+
if (object->side_ == 0)
5152+
{
5153+
if (object->support_object_ && object->support_object_->player_)
5154+
object->side_ = object->support_object_->side_;
5155+
}
5156+
5157+
return true;
5158+
}
5159+
5160+
//default to something at least
5161+
object->side_ = 1;
5162+
5163+
return false;
5164+
5165+
}
5166+
5167+
50875168
//--- editor settings ---
50885169
// vi:ts=4:sw=4:noexpandtab

source_files/edge/p_action.h

+4
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ void A_ClearInvuln(MapObject *mo);
200200

201201
void A_PainChanceSet(MapObject *mo);
202202

203+
void A_ClearTarget(MapObject *mo);
204+
void A_FriendLook(MapObject *mo);
205+
bool FindPlayerToSupport(MapObject *mo);
206+
203207
// Movement actions
204208
void A_FaceDir(MapObject *mo);
205209
void A_TurnDir(MapObject *mo);

source_files/edge/p_enemy.cc

+16-6
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,14 @@ void NewChaseDir(MapObject *object)
452452
object->move_direction_ = kDirectionNone;
453453
}
454454

455+
455456
//
457+
// Used to find a player, either to set as support object or to set as a target.
456458
// Range is angle range on either side of eyes, 90 degrees for normal
457459
// view, 180 degrees for total sight in all dirs.
460+
// Returns true if a player is found.
458461
//
459-
// Returns true if a player is targeted.
460-
//
461-
bool LookForPlayers(MapObject *actor, BAMAngle range)
462+
bool LookForPlayers(MapObject *actor, BAMAngle range, bool ToSupport)
462463
{
463464
int c;
464465
int stop;
@@ -488,7 +489,10 @@ bool LookForPlayers(MapObject *actor, BAMAngle range)
488489

489490
// on the same team ?
490491
if ((actor->side_ & player->map_object_->side_) != 0)
491-
continue;
492+
{
493+
if (!ToSupport) //not looking to support a player
494+
continue;
495+
}
492496

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

512-
actor->SetTarget(player->map_object_);
513-
return true;
516+
if (ToSupport) //support the player
517+
actor->SetSupportObject(player->map_object_);
518+
else // target the player
519+
actor->SetTarget(player->map_object_);
520+
521+
return true;
522+
514523
}
515524

516525
return false;
517526
}
518527

528+
519529
//
520530
// BOSS-BRAIN HANDLING
521531
//

source_files/edge/p_local.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ extern float yspeed[8];
149149
void NoiseAlert(Player *p);
150150
void NewChaseDir(MapObject *actor);
151151
bool DoMove(MapObject *actor, bool path);
152-
bool LookForPlayers(MapObject *actor, BAMAngle range);
152+
bool LookForPlayers(MapObject *actor, BAMAngle range, bool ToSupport = false);
153+
153154
MapObject *LookForShootSpot(const MapObjectDefinition *spot_type);
154155

155156
//

source_files/edge/p_setup.cc

+2
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ static MapObject *SpawnMapThing(const MapObjectDefinition *info, float x, float
670670
{
671671
mo->side_ = 1; //~0;
672672
mo->hyper_flags_ |= kHyperFlagUltraLoyal;
673+
//mo->extended_flags_ &= ~kExtendedFlagDisloyalToOwnType; //remove this flag just in case
674+
673675
/*
674676
player_t *player;
675677
player = players[0];

source_files/edge/p_sight.cc

+7
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ static bool CheckSightSameSubsector(MapObject *src, MapObject *dest)
420420

421421
bool CheckSight(MapObject *src, MapObject *dest)
422422
{
423+
if (!dest)
424+
return false;
425+
423426
// -ACB- 1998/07/20 t2 is Invisible, t1 cannot possibly see it.
424427
if (AlmostEquals(dest->visibility_, 0.0f))
425428
return false;
@@ -462,7 +465,11 @@ bool CheckSight(MapObject *src, MapObject *dest)
462465
if (src->info_->sight_distance_ > -1) // if we have sight_distance set
463466
{
464467
if (src->info_->sight_distance_ < dist_a)
468+
{
469+
//src->SetTarget(nullptr); //forget we even saw the guy?
465470
return false; // too far away for this thing to see
471+
}
472+
466473
}
467474

468475
#if (EDGE_DEBUG_SIGHT >= 1)

0 commit comments

Comments
 (0)