添加组队
This commit is contained in:
parent
02ce6baf9a
commit
d463951376
@ -114,3 +114,37 @@ bool CircleContainCircle(Vector2D a_pos, float a_rad, Vector2D b_pos, float b_ra
|
||||
float distance = (a_pos - b_pos).Norm();
|
||||
return distance < a_rad - b_rad;
|
||||
}
|
||||
|
||||
bool CalcCircleAabbSafePoint(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b_rad,
|
||||
Vector2D& new_pos)
|
||||
{
|
||||
new_pos = b_pos;
|
||||
bool at_left = std::abs(b_pos.x - a_min.x) < std::abs(b_pos.x - a_max.x);
|
||||
bool at_down = std::abs(b_pos.y - a_min.y) < std::abs(b_pos.y - a_max.y);
|
||||
float x_len = at_left ? std::abs(b_pos.x - a_min.x) : std::abs(b_pos.x - a_max.x);
|
||||
float y_len = at_down ? std::abs(b_pos.y - a_min.y) : std::abs(b_pos.y - a_max.y);
|
||||
if (at_left) {
|
||||
if (x_len < y_len) {
|
||||
//左
|
||||
new_pos.x = a_min.x - b_rad - 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = a_min.y - b_rad - 1;
|
||||
} else {
|
||||
new_pos.y = a_max.y + b_rad + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (x_len < y_len) {
|
||||
//右
|
||||
new_pos.x = a_max.x + b_rad + 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = a_min.y - b_rad - 1;
|
||||
} else {
|
||||
new_pos.y = a_max.y + b_rad + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -6,4 +6,6 @@ bool IntersectAabbCircle(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b
|
||||
bool IntersectAabbAabb(Vector2D a_min, Vector2D a_max, Vector2D b_min, Vector2D b_max);
|
||||
bool IntersectCircleCircle(Vector2D a_pos, float a_rad, Vector2D b_pos, float b_rad);
|
||||
bool CircleContainCircle(Vector2D a_pos, float a_rad, Vector2D b_pos, float b_rad);
|
||||
bool CalcCircleAabbSafePoint(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b_rad,
|
||||
Vector2D& new_pos);
|
||||
void TestGlm();
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "bullet.h"
|
||||
#include "collider.h"
|
||||
#include "loot.h"
|
||||
#include "collision.h"
|
||||
|
||||
Human::Human()
|
||||
{
|
||||
@ -646,5 +647,24 @@ void Human::FindLocation()
|
||||
a8::SetBitFlag(detection_flags, ET_Building);
|
||||
}
|
||||
room->CollisionDetection(this, detection_flags, objects);
|
||||
if (objects.size() > 1) {
|
||||
abort();
|
||||
}
|
||||
if (!objects.empty()) {
|
||||
Building* building = (Building*)objects[0];
|
||||
Vector2D a_min;
|
||||
Vector2D a_max;
|
||||
Vector2D new_pos;
|
||||
bool ret = CalcCircleAabbSafePoint(
|
||||
a_min,
|
||||
a_max,
|
||||
pos,
|
||||
GetRadius(),
|
||||
new_pos
|
||||
);
|
||||
if (!ret) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Human : public Entity
|
||||
public:
|
||||
int team_id = 0;
|
||||
std::string account_id;
|
||||
std::string team_uniid;
|
||||
std::string team_uuid;
|
||||
MetaData::Player* meta = nullptr;
|
||||
MetaData::Equip* helmet_meta = nullptr;
|
||||
MetaData::Equip* chest_meta = nullptr;
|
||||
|
@ -25,7 +25,7 @@ Player* PlayerMgr::CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg)
|
||||
hum->account_id = msg.account_id();
|
||||
hum->name = msg.name();
|
||||
hum->health = 0;
|
||||
hum->team_uniid = msg.team_uuid();
|
||||
hum->team_uuid = msg.team_uuid();
|
||||
hum->team_mode = msg.team_mode();
|
||||
hum->player_count = msg.player_count();
|
||||
hum->auto_fill = msg.auto_fill();
|
||||
|
@ -269,6 +269,15 @@ void Room::AddPlayer(Player* hum)
|
||||
pair.second->AddToPartObjects(hum);
|
||||
hum->AddToNewObjects(pair.second);
|
||||
hum->AddToPartObjects(pair.second);
|
||||
if (!hum->team_uuid.empty() && pair.second->team_uuid == hum->team_uuid) {
|
||||
if (!pair.second->team_members) {
|
||||
pair.second->team_id = NewTeam();
|
||||
pair.second->team_members = &team_hash_[pair.second->team_id];
|
||||
pair.second->team_members->insert(pair.second);
|
||||
}
|
||||
pair.second->team_members->insert(hum);
|
||||
hum->team_id = pair.second->team_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto& pair : uniid_hash_) {
|
||||
@ -656,6 +665,13 @@ void Room::OnHumanDie(Human* hum)
|
||||
--alive_count_;
|
||||
}
|
||||
|
||||
int Room::NewTeam()
|
||||
{
|
||||
++current_teamid;
|
||||
team_hash_[current_teamid] = std::set<Human*>();
|
||||
return current_teamid;
|
||||
}
|
||||
|
||||
void Room::ClearDeletedObjects()
|
||||
{
|
||||
for (auto& pair : frame_data.deleted_objects_hash) {
|
||||
@ -976,8 +992,10 @@ void Room::AutoMatchTeam()
|
||||
{
|
||||
std::vector<Human*> humans;
|
||||
for (auto& pair : human_hash_) {
|
||||
if (pair.second->team_uuid.empty()) {
|
||||
humans.push_back(pair.second);
|
||||
}
|
||||
}
|
||||
std::random_shuffle(humans.begin(), humans.end());
|
||||
std::set<Human*>* team_members = nullptr;
|
||||
for (size_t i = 0; i < humans.size(); ++i) {
|
||||
|
@ -77,6 +77,7 @@ public:
|
||||
Vector2D pos, Vector2D dir, float fly_distance);
|
||||
|
||||
void OnHumanDie(Human* hum);
|
||||
int NewTeam();
|
||||
|
||||
private:
|
||||
unsigned short AllocUniid();
|
||||
|
Loading…
x
Reference in New Issue
Block a user