载入中...
搜索中...
未找到
Social.cpp
浏览该文件的文档.
1#include "social/Social.h"
2#include <algorithm>
3#include <simplesquirrel/simplesquirrel.hpp>
5
6// Social.cpp
7namespace eve::social {
8namespace {
9
10std::string at(const std::vector<EntityId>& ids, int index) {
11 return index < 0 || static_cast<std::size_t>(index) >= ids.size() ? std::string{} : ids[index];
12}
13
14const SocialChangeEvent* eventAt(const SocialGraph& graph, int index) {
15 const auto& events = graph.events();
16 return index < 0 || static_cast<std::size_t>(index) >= events.size() ? nullptr : &events[index];
17}
18
19} // namespace
20
22
23std::string Social::idFromInt(int id) const { return SocialGraph::integerId(id); }
24
25bool Social::setOwner(const std::string& entity, const std::string& owner) { return graph_.setOwner(entity, owner); }
29std::string Social::ownerOf(const std::string& entity) const { return graph_.ownerOf(entity); }
30std::string Social::ownerOfInt(int entity) const { return graph_.ownerOf(SocialGraph::integerId(entity)); }
31int Social::ownedCount(const std::string& owner) const { return static_cast<int>(graph_.ownedBy(owner).size()); }
32std::string Social::ownedAt(const std::string& owner, int index) const { return at(graph_.ownedBy(owner), index); }
33
34bool Social::setController(const std::string& entity, const std::string& controller) {
35 return graph_.setController(entity, controller);
36}
37bool Social::setControllerInt(int entity, int controller) {
39}
40std::string Social::controllerOf(const std::string& entity) const { return graph_.controllerOf(entity); }
41std::string Social::controllerOfInt(int entity) const { return graph_.controllerOf(SocialGraph::integerId(entity)); }
42int Social::controlledCount(const std::string& controller) const {
43 return static_cast<int>(graph_.controlledBy(controller).size());
44}
45std::string Social::controlledAt(const std::string& controller, int index) const {
46 return at(graph_.controlledBy(controller), index);
47}
48
49bool Social::assign(const std::string& source, const std::string& role, const std::string& target) {
50 return graph_.assign(source, role, target);
51}
52bool Social::assignInt(int source, const std::string& role, int target) {
54}
55bool Social::unassign(const std::string& source, const std::string& role, const std::string& target) {
56 return graph_.unassign(source, role, target);
57}
58bool Social::isAssigned(const std::string& source, const std::string& role, const std::string& target) const {
59 return graph_.isAssigned(source, role, target);
60}
61int Social::targetCount(const std::string& source, const std::string& role) const {
62 return static_cast<int>(graph_.targetsOf(source, role).size());
63}
64std::string Social::targetAt(const std::string& source, const std::string& role, int index) const {
65 return at(graph_.targetsOf(source, role), index);
66}
67int Social::assigneeCount(const std::string& target, const std::string& role) const {
68 return static_cast<int>(graph_.assigneesOf(target, role).size());
69}
70std::string Social::assigneeAt(const std::string& target, const std::string& role, int index) const {
71 return at(graph_.assigneesOf(target, role), index);
72}
73
74bool Social::setRelation(const std::string& source, const std::string& target, const std::string& type, float value) {
75 return graph_.setRelation(source, target, type, value);
76}
77bool Social::setRelationInt(int source, int target, const std::string& type, float value) {
79}
80float Social::addRelation(const std::string& source, const std::string& target, const std::string& type, float delta) {
81 return static_cast<float>(graph_.addRelation(source, target, type, delta));
82}
83bool Social::link(const std::string& source, const std::string& target, const std::string& type) {
84 return graph_.link(source, target, type);
85}
86bool Social::removeRelation(const std::string& source, const std::string& target, const std::string& type) {
87 return graph_.removeRelation(source, target, type);
88}
89bool Social::hasRelation(const std::string& source, const std::string& target, const std::string& type) const {
90 return graph_.hasRelation(source, target, type);
91}
92float Social::relation(const std::string& source, const std::string& target, const std::string& type,
93 float fallback) const {
94 return static_cast<float>(graph_.relation(source, target, type, fallback));
95}
96int Social::relationTargetCount(const std::string& source, const std::string& type, float minimum) const {
97 return static_cast<int>(graph_.relationTargets(source, type, minimum).size());
98}
99std::string Social::relationTargetAt(const std::string& source, const std::string& type, float minimum,
100 int index) const {
101 return at(graph_.relationTargets(source, type, minimum), index);
102}
103int Social::relationSourceCount(const std::string& target, const std::string& type, float minimum) const {
104 return static_cast<int>(graph_.relationSources(target, type, minimum).size());
105}
106std::string Social::relationSourceAt(const std::string& target, const std::string& type, float minimum,
107 int index) const {
108 return at(graph_.relationSources(target, type, minimum), index);
109}
110
111bool Social::removeEntity(const std::string& entity) { return graph_.removeEntity(entity); }
113void Social::clear() { graph_.clear(); }
114
115int Social::eventCount() const { return static_cast<int>(graph_.events().size()); }
117 const auto* event = eventAt(graph_, index);
118 return event ? static_cast<int>(event->sequence) : 0;
119}
120std::string Social::eventAction(int index) const {
121 const auto* event = eventAt(graph_, index);
122 return event ? event->action : std::string{};
123}
124std::string Social::eventSource(int index) const {
125 const auto* event = eventAt(graph_, index);
126 return event ? event->source : std::string{};
127}
128std::string Social::eventTarget(int index) const {
129 const auto* event = eventAt(graph_, index);
130 return event ? event->target : std::string{};
131}
132std::string Social::eventType(int index) const {
133 const auto* event = eventAt(graph_, index);
134 return event ? event->type : std::string{};
135}
136float Social::eventOldValue(int index) const {
137 const auto* event = eventAt(graph_, index);
138 return event ? static_cast<float>(event->oldValue) : 0.0F;
139}
140float Social::eventNewValue(int index) const {
141 const auto* event = eventAt(graph_, index);
142 return event ? static_cast<float>(event->newValue) : 0.0F;
143}
145
146void Social::expose(ssq::Table& table) {
147 auto cls = table.addClass(name, Social::create, false);
148 expose(cls);
149}
150
151void Social::expose(ssq::Class& cls) {
152 cls.addFunc("getName", &Social::getName);
153 cls.addFunc("idFromInt", &Social::idFromInt);
154 cls.addFunc("setOwner", &Social::setOwner);
155 cls.addFunc("setOwnerInt", &Social::setOwnerInt);
156 cls.addFunc("ownerOf", &Social::ownerOf);
157 cls.addFunc("ownerOfInt", &Social::ownerOfInt);
158 cls.addFunc("ownedCount", &Social::ownedCount);
159 cls.addFunc("ownedAt", &Social::ownedAt);
160 cls.addFunc("setController", &Social::setController);
161 cls.addFunc("setControllerInt", &Social::setControllerInt);
162 cls.addFunc("controllerOf", &Social::controllerOf);
163 cls.addFunc("controllerOfInt", &Social::controllerOfInt);
164 cls.addFunc("controlledCount", &Social::controlledCount);
165 cls.addFunc("controlledAt", &Social::controlledAt);
166 cls.addFunc("assign", &Social::assign);
167 cls.addFunc("assignInt", &Social::assignInt);
168 cls.addFunc("unassign", &Social::unassign);
169 cls.addFunc("isAssigned", &Social::isAssigned);
170 cls.addFunc("targetCount", &Social::targetCount);
171 cls.addFunc("targetAt", &Social::targetAt);
172 cls.addFunc("assigneeCount", &Social::assigneeCount);
173 cls.addFunc("assigneeAt", &Social::assigneeAt);
174 cls.addFunc("setRelation", &Social::setRelation);
175 cls.addFunc("setRelationInt", &Social::setRelationInt);
176 cls.addFunc("addRelation", &Social::addRelation);
177 cls.addFunc("link", &Social::link);
178 cls.addFunc("removeRelation", &Social::removeRelation);
179 cls.addFunc("hasRelation", &Social::hasRelation);
180 cls.addFunc("relation", &Social::relation);
181 cls.addFunc("relationTargetCount", &Social::relationTargetCount);
182 cls.addFunc("relationTargetAt", &Social::relationTargetAt);
183 cls.addFunc("relationSourceCount", &Social::relationSourceCount);
184 cls.addFunc("relationSourceAt", &Social::relationSourceAt);
185 cls.addFunc("removeEntity", &Social::removeEntity);
186 cls.addFunc("removeEntityInt", &Social::removeEntityInt);
187 cls.addFunc("clear", &Social::clear);
188 cls.addFunc("eventCount", &Social::eventCount);
189 cls.addFunc("eventSequence", &Social::eventSequence);
190 cls.addFunc("eventAction", &Social::eventAction);
191 cls.addFunc("eventSource", &Social::eventSource);
192 cls.addFunc("eventTarget", &Social::eventTarget);
193 cls.addFunc("eventType", &Social::eventType);
194 cls.addFunc("eventOldValue", &Social::eventOldValue);
195 cls.addFunc("eventNewValue", &Social::eventNewValue);
196 cls.addFunc("clearEvents", &Social::clearEvents);
197}
198
199} // namespace eve::social
200
201// SocialGraph.cpp
202namespace eve::social {
203namespace {
204
205bool valid(const EntityId& id) { return !id.empty(); }
206
207template <typename Index, typename Key>
208void eraseIndex(Index& index, const Key& key, const EntityId& value) {
209 const auto found = index.find(key);
210 if (found == index.end()) return;
211 found->second.erase(value);
212 if (found->second.empty()) index.erase(found);
213}
214
215} // namespace
216
217EntityId SocialGraph::integerId(std::int64_t id) { return "#" + std::to_string(id); }
218
219void SocialGraph::emit(std::string action, EntityId source, EntityId target, std::string type, double oldValue,
220 double newValue) {
221 events_.push_back({nextSequence_++, std::move(action), std::move(source), std::move(target), std::move(type),
222 oldValue, newValue});
223}
224
225std::vector<EntityId> SocialGraph::values(const EntitySet* set) {
226 std::vector<EntityId> result;
227 if (!set) return result;
228 result.reserve(set->size());
229 for (const auto& [id, ignored] : *set) result.push_back(id);
230 return result;
231}
232
234 if (!valid(entity)) return false;
235 const EntityId old = ownerOf(entity);
236 if (old == owner) return false;
237 if (!old.empty()) eraseIndex(owned_, old, entity);
238 if (owner.empty())
239 owners_.erase(entity);
240 else {
241 owners_[entity] = owner;
242 owned_[owner][entity] = true;
243 }
244 emit("owner_changed", entity, owner, {}, 0.0, 0.0);
245 return true;
246}
247
249 const auto found = owners_.find(entity);
250 return found == owners_.end() ? EntityId{} : found->second;
251}
252
253std::vector<EntityId> SocialGraph::ownedBy(const EntityId& owner) const {
254 const auto found = owned_.find(owner);
255 return values(found == owned_.end() ? nullptr : &found->second);
256}
257
258bool SocialGraph::setController(const EntityId& entity, const EntityId& controller) {
259 if (!valid(entity)) return false;
260 const EntityId old = controllerOf(entity);
261 if (old == controller) return false;
262 if (!old.empty()) eraseIndex(controlled_, old, entity);
263 if (controller.empty())
264 controllers_.erase(entity);
265 else {
266 controllers_[entity] = controller;
267 controlled_[controller][entity] = true;
268 }
269 emit("controller_changed", entity, controller);
270 return true;
271}
272
274 const auto found = controllers_.find(entity);
275 return found == controllers_.end() ? EntityId{} : found->second;
276}
277
278std::vector<EntityId> SocialGraph::controlledBy(const EntityId& controller) const {
279 const auto found = controlled_.find(controller);
280 return values(found == controlled_.end() ? nullptr : &found->second);
281}
282
283bool SocialGraph::assign(const EntityId& source, const std::string& role, const EntityId& target) {
284 if (!valid(source) || !valid(target) || role.empty()) return false;
285 auto& targets = assignmentTargets_[{source, role}];
286 if (targets.contains(target)) return false;
287 targets[target] = true;
288 assignmentSources_[{target, role}][source] = true;
289 emit("assignment_added", source, target, role);
290 return true;
291}
292
293bool SocialGraph::unassign(const EntityId& source, const std::string& role, const EntityId& target) {
294 const PairKey forward{source, role};
295 const auto found = assignmentTargets_.find(forward);
296 if (found == assignmentTargets_.end() || !found->second.contains(target)) return false;
297 eraseIndex(assignmentTargets_, forward, target);
298 eraseIndex(assignmentSources_, PairKey{target, role}, source);
299 emit("assignment_removed", source, target, role);
300 return true;
301}
302
303bool SocialGraph::isAssigned(const EntityId& source, const std::string& role, const EntityId& target) const {
304 const auto found = assignmentTargets_.find({source, role});
305 return found != assignmentTargets_.end() && found->second.contains(target);
306}
307
308std::vector<EntityId> SocialGraph::targetsOf(const EntityId& source, const std::string& role) const {
309 const auto found = assignmentTargets_.find({source, role});
310 return values(found == assignmentTargets_.end() ? nullptr : &found->second);
311}
312
313std::vector<EntityId> SocialGraph::assigneesOf(const EntityId& target, const std::string& role) const {
314 const auto found = assignmentSources_.find({target, role});
315 return values(found == assignmentSources_.end() ? nullptr : &found->second);
316}
317
318bool SocialGraph::setRelation(const EntityId& source, const EntityId& target, const std::string& type, double value) {
319 if (!valid(source) || !valid(target) || type.empty()) return false;
320 const EdgeKey key{source, target, type};
321 const auto found = relations_.find(key);
322 if (found != relations_.end() && found->second == value) return false;
323 const double old = found == relations_.end() ? 0.0 : found->second;
324 relations_[key] = value;
325 relationTargets_[{source, type}][target] = true;
326 relationSources_[{target, type}][source] = true;
327 emit(found == relations_.end() ? "relation_added" : "relation_changed", source, target, type, old, value);
328 return true;
329}
330
331double SocialGraph::addRelation(const EntityId& source, const EntityId& target, const std::string& type, double delta) {
332 const double value = relation(source, target, type) + delta;
334 return value;
335}
336
337bool SocialGraph::link(const EntityId& source, const EntityId& target, const std::string& type) {
338 return setRelation(source, target, type, 1.0);
339}
340
341bool SocialGraph::removeRelation(const EntityId& source, const EntityId& target, const std::string& type) {
342 const EdgeKey key{source, target, type};
343 const auto found = relations_.find(key);
344 if (found == relations_.end()) return false;
345 const double old = found->second;
346 relations_.erase(found);
347 eraseIndex(relationTargets_, PairKey{source, type}, target);
348 eraseIndex(relationSources_, PairKey{target, type}, source);
349 emit("relation_removed", source, target, type, old, 0.0);
350 return true;
351}
352
353bool SocialGraph::hasRelation(const EntityId& source, const EntityId& target, const std::string& type) const {
354 return relations_.contains({source, target, type});
355}
356
357double SocialGraph::relation(const EntityId& source, const EntityId& target, const std::string& type,
358 double fallback) const {
359 const auto found = relations_.find({source, target, type});
360 return found == relations_.end() ? fallback : found->second;
361}
362
363std::vector<EntityId> SocialGraph::relationTargets(const EntityId& source, const std::string& type,
364 double minimum) const {
365 std::vector<EntityId> result;
366 const auto found = relationTargets_.find({source, type});
367 if (found == relationTargets_.end()) return result;
368 for (const auto& [target, ignored] : found->second) {
369 if (relation(source, target, type) >= minimum) result.push_back(target);
370 }
371 return result;
372}
373
374std::vector<EntityId> SocialGraph::relationSources(const EntityId& target, const std::string& type,
375 double minimum) const {
376 std::vector<EntityId> result;
377 const auto found = relationSources_.find({target, type});
378 if (found == relationSources_.end()) return result;
379 for (const auto& [source, ignored] : found->second) {
380 if (relation(source, target, type) >= minimum) result.push_back(source);
381 }
382 return result;
383}
384
386 if (!valid(entity)) return false;
387 bool changed = setOwner(entity, {}) | setController(entity, {});
388
389 const auto owned = ownedBy(entity);
390 for (const auto& child : owned) changed = setOwner(child, {}) || changed;
391 const auto controlled = controlledBy(entity);
392 for (const auto& child : controlled) changed = setController(child, {}) || changed;
393
394 std::vector<std::tuple<EntityId, std::string, EntityId>> assignments;
395 for (const auto& [key, targets] : assignmentTargets_) {
396 for (const auto& [target, ignored] : targets) {
397 if (key.first == entity || target == entity) assignments.emplace_back(key.first, key.second, target);
398 }
399 }
400 for (const auto& [source, role, target] : assignments) changed = unassign(source, role, target) || changed;
401
402 std::vector<EdgeKey> relations;
403 for (const auto& [key, value] : relations_) {
404 if (std::get<0>(key) == entity || std::get<1>(key) == entity) relations.push_back(key);
405 }
406 for (const auto& [source, target, type] : relations) changed = removeRelation(source, target, type) || changed;
407
408 if (changed) emit("entity_removed", entity);
409 return changed;
410}
411
413 owners_.clear();
414 owned_.clear();
415 controllers_.clear();
416 controlled_.clear();
417 assignmentTargets_.clear();
418 assignmentSources_.clear();
419 relations_.clear();
420 relationTargets_.clear();
421 relationSources_.clear();
422 events_.clear();
423 nextSequence_ = 1;
424}
425
426} // namespace eve::social
LogicalId target
ActiveSource owned
bool changed
HSQOBJECT cls
Definition ECS.cpp:39
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
std::vector< FieldTarget > targets
float minimum[3]
std::string relation
std::string id
Poco::JSON::Object::Ptr result
bool valid
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
std::shared_ptr< OceanGpuSpectrum > owner
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:173
std::vector< particles::ParticleRecordEvent > events
std::set< std::string > values
Object::Ptr value
const EntityFact * entity
bool found
std::string_view source
std::size_t at
uint32_t index
V forward
virtual std::string getName() const =0
Returns the name.
bool assign(const EntityId &source, const std::string &role, const EntityId &target)
Adds a role-based source-to-target assignment.
Definition Social.cpp:283
EntityId controllerOf(const EntityId &entity) const
Returns an entity's controller, or an empty string when absent.
Definition Social.cpp:273
bool link(const EntityId &source, const EntityId &target, const std::string &type)
Creates a directed typed relation with weight 1.
Definition Social.cpp:337
std::vector< EntityId > ownedBy(const EntityId &owner) const
Returns entities owned by owner in deterministic ID order.
Definition Social.cpp:253
bool setOwner(const EntityId &entity, const EntityId &owner)
Sets an entity's owner; an empty owner removes ownership.
Definition Social.cpp:233
static EntityId integerId(std::int64_t id)
Converts a stable integer ID to its canonical graph key.
Definition Social.cpp:217
double addRelation(const EntityId &source, const EntityId &target, const std::string &type, double delta)
Adds delta to a directed typed relation and returns its new weight.
Definition Social.cpp:331
void clearEvents()
Clears queued events without changing graph state.
Definition SocialGraph.h:90
std::vector< EntityId > controlledBy(const EntityId &controller) const
Returns entities controlled by controller in deterministic ID order.
Definition Social.cpp:278
bool setRelation(const EntityId &source, const EntityId &target, const std::string &type, double value)
Sets a directed typed relation weight, creating the edge if needed.
Definition Social.cpp:318
bool unassign(const EntityId &source, const std::string &role, const EntityId &target)
Removes a role-based source-to-target assignment.
Definition Social.cpp:293
bool setController(const EntityId &entity, const EntityId &controller)
Sets an entity's controller; an empty controller removes control.
Definition Social.cpp:258
std::vector< EntityId > targetsOf(const EntityId &source, const std::string &role) const
Returns targets assigned from source with role in deterministic order.
Definition Social.cpp:308
bool removeEntity(const EntityId &entity)
Removes an entity and every incoming/outgoing graph reference to it.
Definition Social.cpp:385
std::vector< EntityId > assigneesOf(const EntityId &target, const std::string &role) const
Returns sources assigned to target with role in deterministic order.
Definition Social.cpp:313
EntityId ownerOf(const EntityId &entity) const
Returns an entity's owner, or an empty string when absent.
Definition Social.cpp:248
bool removeRelation(const EntityId &source, const EntityId &target, const std::string &type)
Removes an exact directed typed relation.
Definition Social.cpp:341
void clear()
Clears all graph state and pending events.
Definition Social.cpp:412
bool isAssigned(const EntityId &source, const std::string &role, const EntityId &target) const
Tests whether an exact assignment exists.
Definition Social.cpp:303
double relation(const EntityId &source, const EntityId &target, const std::string &type, double fallback=0.0) const
Gets an exact relation weight, or fallback when absent.
Definition Social.cpp:357
std::vector< EntityId > relationTargets(const EntityId &source, const std::string &type, double minimum=0.0) const
Returns outgoing relation targets filtered by type and minimum weight.
Definition Social.cpp:363
bool hasRelation(const EntityId &source, const EntityId &target, const std::string &type) const
Tests whether an exact directed typed relation exists.
Definition Social.cpp:353
const std::vector< SocialChangeEvent > & events() const
Returns queued mutation events in sequence order.
Definition SocialGraph.h:88
std::vector< EntityId > relationSources(const EntityId &target, const std::string &type, double minimum=0.0) const
Returns incoming relation sources filtered by type and minimum weight.
Definition Social.cpp:374
Script-facing module for generic social graph composition.
Definition Social.h:11
bool removeEntityInt(int entity)
Removes an integer-ID entity and every graph reference to it.
Definition Social.cpp:112
std::string controllerOfInt(int entity) const
Gets controller of an integer ID as a canonical key.
Definition Social.cpp:41
std::string relationSourceAt(const std::string &target, const std::string &type, float minimum, int index) const
Gets incoming relation source by deterministic filtered index.
Definition Social.cpp:106
int ownedCount(const std::string &owner) const
Gets count of deterministically ordered entities owned by owner.
Definition Social.cpp:31
bool unassign(const std::string &source, const std::string &role, const std::string &target)
Removes an exact assignment.
Definition Social.cpp:55
int relationTargetCount(const std::string &source, const std::string &type, float minimum) const
Gets outgoing relation target count after threshold filtering.
Definition Social.cpp:96
std::string relationTargetAt(const std::string &source, const std::string &type, float minimum, int index) const
Gets outgoing relation target by deterministic filtered index.
Definition Social.cpp:99
int eventCount() const
Gets queued change event count.
Definition Social.cpp:115
float eventNewValue(int index) const
Gets event new numeric value by index.
Definition Social.cpp:140
std::string ownerOf(const std::string &entity) const
Gets owner of a string ID.
Definition Social.cpp:29
bool assign(const std::string &source, const std::string &role, const std::string &target)
Adds a role-based assignment between string IDs.
Definition Social.cpp:49
std::string targetAt(const std::string &source, const std::string &role, int index) const
Gets an assignment target by deterministic index.
Definition Social.cpp:64
void clearEvents()
Clears queued events only.
Definition Social.cpp:144
std::string controllerOf(const std::string &entity) const
Gets controller of a string ID.
Definition Social.cpp:40
bool setController(const std::string &entity, const std::string &controller)
Sets control between string IDs.
Definition Social.cpp:34
bool setRelation(const std::string &source, const std::string &target, const std::string &type, float value)
Sets a directed typed relation between string IDs.
Definition Social.cpp:74
bool setRelationInt(int source, int target, const std::string &type, float value)
Sets a directed typed relation between integer IDs.
Definition Social.cpp:77
float eventOldValue(int index) const
Gets event old numeric value by index.
Definition Social.cpp:136
int eventSequence(int index) const
Gets event sequence by index, or zero when out of range.
Definition Social.cpp:116
std::string controlledAt(const std::string &controller, int index) const
Gets a controlled entity by deterministic index.
Definition Social.cpp:45
bool removeEntity(const std::string &entity)
Removes a string-ID entity and every graph reference to it.
Definition Social.cpp:111
int targetCount(const std::string &source, const std::string &role) const
Gets target count for source and role.
Definition Social.cpp:61
bool isAssigned(const std::string &source, const std::string &role, const std::string &target) const
Tests an exact assignment.
Definition Social.cpp:58
bool setOwnerInt(int entity, int owner)
Sets ownership between integer IDs.
Definition Social.cpp:26
bool hasRelation(const std::string &source, const std::string &target, const std::string &type) const
Tests an exact relation.
Definition Social.cpp:89
std::string eventType(int index) const
Gets event type/role by index.
Definition Social.cpp:132
std::string eventSource(int index) const
Gets event source by index.
Definition Social.cpp:124
bool removeRelation(const std::string &source, const std::string &target, const std::string &type)
Removes an exact relation.
Definition Social.cpp:86
int assigneeCount(const std::string &target, const std::string &role) const
Gets assignee count for target and role.
Definition Social.cpp:67
int relationSourceCount(const std::string &target, const std::string &type, float minimum) const
Gets incoming relation source count after threshold filtering.
Definition Social.cpp:103
int controlledCount(const std::string &controller) const
Gets count of deterministically ordered controlled entities.
Definition Social.cpp:42
std::string assigneeAt(const std::string &target, const std::string &role, int index) const
Gets an assignee by deterministic index.
Definition Social.cpp:70
bool assignInt(int source, const std::string &role, int target)
Adds a role-based assignment between integer IDs.
Definition Social.cpp:52
std::string eventTarget(int index) const
Gets event target by index.
Definition Social.cpp:128
std::string ownedAt(const std::string &owner, int index) const
Gets an owned entity by deterministic index.
Definition Social.cpp:32
bool setControllerInt(int entity, int controller)
Sets control between integer IDs.
Definition Social.cpp:37
std::string idFromInt(int id) const
Returns the canonical graph key for an integer entity ID.
Definition Social.cpp:23
std::string eventAction(int index) const
Gets event action by index.
Definition Social.cpp:120
float relation(const std::string &source, const std::string &target, const std::string &type, float fallback) const
Gets relation value or fallback.
Definition Social.cpp:92
std::string ownerOfInt(int entity) const
Gets owner of an integer ID as a canonical key.
Definition Social.cpp:30
bool setOwner(const std::string &entity, const std::string &owner)
Sets ownership between string IDs.
Definition Social.cpp:25
float addRelation(const std::string &source, const std::string &target, const std::string &type, float delta)
Adds to a relation and returns its new value.
Definition Social.cpp:80
void clear()
Clears all graph state and events.
Definition Social.cpp:113
bool link(const std::string &source, const std::string &target, const std::string &type)
Creates a weight-one directed typed relation.
Definition Social.cpp:83
std::unordered_map< const void *, size_t > ids
Definition Snapshot.cpp:109
std::string EntityId
Stable, game-defined identifier used by the social graph.
Definition SocialGraph.h:15