-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic factions #609
base: master
Are you sure you want to change the base?
Dynamic factions #609
Changes from all commits
7261c62
7263a18
c3b654e
4d0389b
eb0f7f1
32b1d0a
02b7a1d
9ef153f
4aa682b
8a5643f
e439d6d
43160c0
18da046
f087c27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
|
||
#include "factions/factionrelation.h" | ||
#include "utils/handle/handle.h" | ||
#include "utils/handle/handlehash.h" | ||
|
||
|
||
class AiTask; | ||
class Faction; | ||
class Ship; | ||
class WorldObject; | ||
class World; | ||
|
||
/** | ||
* The Character is the Ship's pilot and executes his AiTask. He has a Faction which decides | ||
|
@@ -23,9 +30,25 @@ class Character { | |
|
||
virtual void update(float deltaSec); | ||
|
||
void onCollisionWith(WorldObject* worldObject); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the methods you added here should probably be protected |
||
|
||
void onKilledBy(WorldObject* worldObject); | ||
|
||
void onAggressionBy(WorldObject* aggressor, float friendlinessModifier); | ||
|
||
FactionRelationType relationTypeTo(WorldObject* worldObject); | ||
|
||
void setFriendlinessToWorldObject(WorldObject* worldObject, float friendliness); | ||
|
||
protected: | ||
World* m_world; | ||
Ship& m_ship; | ||
Faction* m_faction; | ||
std::shared_ptr<AiTask> m_task; | ||
std::unordered_map<Handle<WorldObject>, float> m_friendlinessToWorldObject; | ||
std::unordered_map<Handle<WorldObject>, float> m_friendlinessResetDelay; | ||
|
||
void resetFriendliness(float deltaSec); | ||
void changeFriendlinessToAggressor(WorldObject* aggressor, float difference); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include "utils/safenormalize.h" | ||
#include "physics/physics.h" | ||
#include "voxel/voxelclusterbounds.h" | ||
#include "ai/character.h" | ||
|
||
Squad::Squad(Ship* leader) : | ||
m_leader(leader), | ||
|
@@ -125,3 +126,9 @@ glm::vec3 Squad::calculateFormationPosition(Ship* member, int position) { | |
return m_leader->transform().position() + m_leader->physics().speed().directional() + m_leader->transform().orientation() * (distance * glm::normalize(direction)); | ||
} | ||
|
||
void Squad::propagadeFriendlinessToWorldObject(WorldObject* worldObject, float friendliness) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please name it something like propagateToMembers or something. The current name is wrong |
||
m_leader->character()->setFriendlinessToWorldObject(worldObject, friendliness); | ||
for (Ship* ship : m_members) { | ||
ship->character()->setFriendlinessToWorldObject(worldObject, friendliness); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
class Ship; | ||
class AiGroupTask; | ||
class WorldObject; | ||
|
||
/** | ||
* Ships can be joined to Squads to give them AiGroupTasks. The Squad's leader is the one to execute the Squad's task. | ||
|
@@ -25,6 +26,8 @@ class Squad : public Scriptable { | |
|
||
const std::vector<Ship*>& members(); | ||
|
||
//void propagadeFriendlinessToPlayer(float friendliness); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not used? remove! |
||
void propagadeFriendlinessToWorldObject(WorldObject* worldObject, float friendliness); | ||
|
||
protected: | ||
friend class SquadLogic; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,20 @@ FactionRelation& FactionMatrix::getRelationToPlayer(Faction& faction) { | |
return getRelation(faction, playerFaction()); | ||
} | ||
|
||
void FactionMatrix::changeFriendlinessToPlayer(Faction& faction, float difference) { | ||
changeFriendlinessToFaction(faction, playerFaction(), difference); | ||
} | ||
|
||
void FactionMatrix::changeFriendlinessToFaction(Faction& faction, Faction& otherFaction, float difference) { | ||
getRelation(faction, otherFaction).changeFriendliness(difference); //change friendliness to other faction | ||
for (auto it = m_factions.begin(); it != m_factions.end(); ++it) { //change all other factions friendliness to other faction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose(!) this loops propagtes the difference damped to the other functions. Please give this block a descriptive name by putting it in some other function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you use this iterator loop? I don't see any reason not to use a foreach loop? |
||
if (it->second.get() != &otherFaction && it->second.get() != &faction) { | ||
float friendliness = getRelation(faction, *it->second.get()).friendliness(); | ||
getRelation(*it->second.get(), otherFaction).changeFriendliness(difference*(friendliness / 100)); | ||
} | ||
} | ||
} | ||
|
||
void FactionMatrix::setupRelations() { | ||
getRelation(playerFaction(), pirateFaction()).setFriendliness(-20.0f); | ||
getRelation(playerFaction(), policeFaction()).setFriendliness(10.0f); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as we have the Singleton, we should use it. Not some obscure pointer that was once retrieved from this singleton