2020-10-04 23:54:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-07-31 05:50:03 +00:00
|
|
|
#include "EntityRef.hpp"
|
2020-10-04 23:54:08 +00:00
|
|
|
|
2022-07-16 23:19:40 +00:00
|
|
|
#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;
|
|
|
|
|
2022-04-24 20:50:03 +00:00
|
|
|
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];
|
|
|
|
}
|
2022-07-17 06:33:57 +00:00
|
|
|
|
|
|
|
Group(EntityRef leader);
|
2022-04-23 01:13:00 +00:00
|
|
|
};
|
|
|
|
|
2021-03-16 22:29:13 +00:00
|
|
|
namespace Groups {
|
2021-12-16 02:34:15 +00:00
|
|
|
void init();
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2022-04-23 01:13:00 +00:00
|
|
|
void sendToGroup(Group* group, void* buf, uint32_t type, size_t size);
|
2022-07-17 06:33:57 +00:00
|
|
|
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
|
|
|
|
2022-07-17 06:33:57 +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);
|
2020-10-04 23:54:08 +00:00
|
|
|
}
|