OpenFusion/src/Groups.hpp

38 lines
1016 B
C++
Raw Normal View History

#pragma once
#include "EntityRef.hpp"
#include <vector>
2022-11-27 22:36:47 +00:00
#include <assert.h>
2022-04-23 01:13:00 +00:00
struct Group {
std::vector<EntityRef> members;
std::vector<EntityRef> filter(EntityKind kind) {
2022-04-23 01:13:00 +00:00
std::vector<EntityRef> filtered;
std::copy_if(members.begin(), members.end(), std::back_inserter(filtered), [kind](EntityRef e) {
return e.kind == kind;
});
return filtered;
}
2022-11-27 22:36:47 +00:00
EntityRef getLeader() {
assert(members.size() > 0);
return members[0];
}
Group(EntityRef leader);
2022-04-23 01:13:00 +00:00
};
namespace Groups {
2021-12-16 02:34:15 +00:00
void init();
2022-04-23 01:13:00 +00:00
void sendToGroup(Group* group, void* buf, uint32_t type, size_t size);
void sendToGroup(Group* group, EntityRef excluded, void* buf, uint32_t type, size_t size);
void groupTickInfo(CNSocket* sock);
2022-04-23 01:13:00 +00:00
void groupKick(Group* group, EntityRef ref);
void addToGroup(Group* group, EntityRef member);
bool removeFromGroup(Group* group, EntityRef member); // true iff group deleted
2022-04-23 01:13:00 +00:00
void disbandGroup(Group* group);
}