Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeLepageUQAC committed Dec 13, 2022
2 parents 3fb8f07 + f2e1e3c commit 8d61008
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Buckland_Chapter7 to 10_Raven_apprentissage/Raven_Bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ bool Raven_Bot::HandleMessage(const Telegram& msg)
return true;
}

case Msg_ProtectLeader:
{
Raven_Bot* leader = current_team->GetTeamLeader();
isProtectingLeader != isProtectingLeader;
if (isProtectingLeader)
{
m_pSteering->OffSetPursuitOn(leader);
}
else
{
m_pSteering->OffSetPursuitOff();
}
}

case Msg_TargetKilled: {
m_pTargSys->ClearTarget(); //clear target
isTargeted = false;
Expand Down Expand Up @@ -393,6 +407,8 @@ void Raven_Bot::TakePossession()
if ( !(isSpawning() || isDead()))
{
m_bPossessed = true;
Team* team;
team->SetTeamLeader(this);

debug_con << "Player Possesses bot " << this->ID() << "";
}
Expand Down
2 changes: 2 additions & 0 deletions Buckland_Chapter7 to 10_Raven_apprentissage/Raven_Bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class Raven_Bot : public MovingEntity

bool isTargeted = false;

bool isProtectingLeader = true;

//the usual suspects
void Render();
virtual void Update();
Expand Down
4 changes: 4 additions & 0 deletions Buckland_Chapter7 to 10_Raven_apprentissage/Raven_Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum message_type
Msg_GunshotSound,
Msg_UserHasRemovedBot,
Msg_UpdatingTarget,
Msg_ProtectLeader,
Msg_TargetKilled
};

Expand Down Expand Up @@ -65,6 +66,9 @@ inline std::string MessageToString(int msg)
case Msg_UpdatingTarget:
return "Msg_UpdatingTarget";

case Msg_ProtectLeader:
return "Msg_ProtectLeader";

case Msg_TargetKilled:
return "Msg_TargetKilled";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ Vector2D Raven_Steering::CalculatePrioritized()
if (!AccumulateForce(m_vSteeringForce, force)) return m_vSteeringForce;
}

if (On(offset_pursuit))
{

force = OffSetPursuit(Vector2D(0.1f, 0.1f));

if (!AccumulateForce(m_vSteeringForce, force)) return m_vSteeringForce;
}


return m_vSteeringForce;
}
Expand Down Expand Up @@ -403,6 +411,27 @@ Vector2D Raven_Steering::Separation(const std::list<Raven_Bot*>& neighbors)
return SteeringForce;
}

Vector2D Raven_Steering::OffSetPursuit(const Vector2D offset)
{
Raven_Bot* leader = m_leader;
//calculate the offset's position in world space
Vector2D WorldOffsetPos = PointToWorldSpace(offset,
leader->Heading(),
leader->Side(),
leader->Pos());

Vector2D ToOffset = WorldOffsetPos - leader->Pos();

//the lookahead time is propotional to the distance between the leader
//and the pursuer; and is inversely proportional to the sum of both
//agent's velocities
double LookAheadTime = ToOffset.Length() /
(leader->MaxSpeed() + leader->Speed());

//now Arrive at the predicted future position of the offset
return Arrive(WorldOffsetPos + leader->Velocity() * LookAheadTime, fast);
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ class Raven_Steering
wander = 0x00010,
separation = 0x00040,
wall_avoidance = 0x00200,
offset_pursuit = 0x00400,
};

private:


//a pointer to the owner of this instance
Raven_Bot* m_pRaven_Bot;

Raven_Bot* m_leader;

//pointer to the world data
Raven_Game* m_pWorld;
Expand Down Expand Up @@ -162,6 +165,8 @@ class Raven_Steering

Vector2D Separation(const std::list<Raven_Bot*> &agents);

Vector2D OffSetPursuit(const Vector2D offset);


/* .......................................................
Expand Down Expand Up @@ -208,12 +213,14 @@ class Raven_Steering
void WanderOn(){m_iFlags |= wander;}
void SeparationOn(){m_iFlags |= separation;}
void WallAvoidanceOn(){m_iFlags |= wall_avoidance;}
void OffSetPursuitOn(Raven_Bot* leader) { m_iFlags |= offset_pursuit; m_leader = leader; }

void SeekOff() {if(On(seek)) m_iFlags ^=seek;}
void ArriveOff(){if(On(arrive)) m_iFlags ^=arrive;}
void WanderOff(){if(On(wander)) m_iFlags ^=wander;}
void SeparationOff(){if(On(separation)) m_iFlags ^=separation;}
void WallAvoidanceOff(){if(On(wall_avoidance)) m_iFlags ^=wall_avoidance;}
void OffSetPursuitOff(){ if (On(offset_pursuit)) m_iFlags ^= offset_pursuit; }

bool SeekIsOn(){return On(seek);}
bool ArriveIsOn(){return On(arrive);}
Expand Down
17 changes: 17 additions & 0 deletions Buckland_Chapter7 to 10_Raven_apprentissage/Team.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ void Team::UpdateNewTarget(Raven_Bot* new_target, int id_sender) {
}
}

void Team::ProtectLeader(int id_sender)
{
std::list<Raven_Bot*>::iterator curBot = members.begin();
Raven_Bot* leader = *curBot;
for (curBot; curBot != members.end(); ++curBot) { //dispatch message to all members
Raven_Bot* bot_courant = *curBot;
if (!bot_courant->isPossessed())
{
Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY,
id_sender,
bot_courant->ID(),
Msg_ProtectLeader,
NO_ADDITIONAL_INFO);
}
}
}

void Team::ClearTarget(int id_sender) {
target = 0;
std::list<Raven_Bot*>::iterator curBot = members.begin();
Expand Down
2 changes: 2 additions & 0 deletions Buckland_Chapter7 to 10_Raven_apprentissage/Team.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ class Team

void Addmember(Raven_Bot* new_memeber);
Raven_Bot* GetTeamLeader() { return team_leader; }
void SetTeamLeader(Raven_Bot* teamLeader) { team_leader = teamLeader; }

void AddSpawnPoint(Vector2D spawnPoint);
const std::vector<Vector2D>& GetSpawnPoints()const { return m_SpawnPoints; }
Vector2D GetRandomSpawnPoint() { return m_SpawnPoints[RandInt(0, m_SpawnPoints.size() - 1)]; }
Vector2D GetLootingLocation() { return lootingLocation; }

void UpdateNewTarget(Raven_Bot* bot, int id_sender);
void ProtectLeader(int id_sender);
Raven_Bot* GetTarget() { return target; }
void ClearTarget(int id_sender);

Expand Down
4 changes: 4 additions & 0 deletions Buckland_Chapter7 to 10_Raven_apprentissage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ LRESULT CALLBACK WindowProc (HWND hwnd,
}

break;
case 'Y':
g_pRaven->GetPlayer()->GetTeam()->SetTeamLeader(g_pRaven->GetSelectedBot());
g_pRaven->GetPlayer()->GetTeam()->ProtectLeader(g_pRaven->GetPlayer()->ID());
break;


case VK_UP:
Expand Down
18 changes: 16 additions & 2 deletions Modifications.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,19 @@ Goal_Think.cpp
FleeGoal_Evaluator.cpp
FleeGoal_Evaluator.h

Rocket Launcher Fuzzy Rules: +5 pts
in Weapon/Weapon_RocketLauncher.cpp
Rocket Launcher Fuzzy Rules: +5 PTS
Weapon_RocketLauncher.cpp

Stratégie de comportement au sein d’une équipe +10 PTS
(Main.cpp, on appuie sur Y, ça set le team leader du joueur actuel au joueur actuel de Team.cpp, ensuite on appel ProtectLeader de Team.cpp, cette fonction loop sur tous les
bots de l'équipe (Excepté le leader) et leur envoie un message "Msg_ProtectLeader". Dans Raven_Bot.cpp on réagis à ce message en appelant OffSetPursuitOn de
SteeringBehaviour.cpp en lui envoyant le leader)
Raven_Messages.h
Team.h
Team.cpp
main.cpp
Raven_SteeringBehaviors.cpp
Raven_SteeringBehaviors.h
Raven_bot.h
Raven_bot.cpp
main.cpp

0 comments on commit 8d61008

Please sign in to comment.