#include "Situation.hpp"
#include "Steering.hpp"
+#include "AttackGoal.hpp"
#include "BlobBackgroundTask.hpp"
#include "Goal.hpp"
#include "IdleGoal.hpp"
: resources(resources)
, components()
, total_mass(0.0)
+, total_volume(0.0)
, state_mass{0.0} {
}
std::sort(components.begin(), components.end(), CompositionCompare);
state_mass[resources[res].state] += amount;
total_mass += amount;
+ total_volume += amount / resources[res].density;
}
bool Composition::Has(int res) const noexcept {
* glm::translate(glm::dvec3(0.0, half_size, 0.0));
}
+void Creature::OnCollide(Creature &other) {
+ memory.TrackCollision(other);
+}
+
glm::dmat4 Creature::LocalTransform() noexcept {
const double half_size = size * 0.5;
return CollisionTransform()
void Memory::Erase() {
known_types.clear();
+ known_creatures.clear();
}
bool Memory::RememberLocation(const Composition &accept, glm::dvec3 &pos) const noexcept {
}
}
+void Memory::TrackCollision(Creature &other) {
+ // TODO: find out whose fault it was
+ // TODO: source values from personality
+ Profile &p = known_creatures[&other];
+ p.annoyance += 0.1;
+ const double annoy_fact = p.annoyance / (p.annoyance + 1.0);
+ if (c.GetSimulation().Assets().random.UNorm() > annoy_fact * 0.1 * (1.0 - c.GetStats().Damage().value)) {
+ AttackGoal *g = new AttackGoal(c, other);
+ g->SetDamageTarget(annoy_fact);
+ g->Urgency(annoy_fact);
+ c.AddGoal(std::unique_ptr<Goal>(g));
+ p.annoyance *= 0.5;
+ }
+}
+
void Memory::Tick(double dt) {
Situation &s = c.GetSituation();
if (s.OnSurface()) {