完成对room引用的改造
This commit is contained in:
parent
adc58332e0
commit
41546fc2ea
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class Entity;
|
||||
class RoomEntity;
|
||||
class AIComponent
|
||||
{
|
||||
public:
|
||||
Entity* owner = nullptr;
|
||||
RoomEntity* owner = nullptr;
|
||||
|
||||
virtual ~AIComponent();
|
||||
virtual void Update(int delta_time);
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "loot.h"
|
||||
#include "app.h"
|
||||
#include "typeconvert.h"
|
||||
#include "mapservice.h"
|
||||
#include "cs_proto.pb.h"
|
||||
|
||||
Building::Building():Entity()
|
||||
{
|
||||
@ -44,7 +46,7 @@ void Building::RecalcSelfCollider()
|
||||
AutoAdjust(collider_list);
|
||||
}
|
||||
|
||||
void Building::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
void Building::FillMFObjectPart(Room* room, cs::MFObjectPart* part_data)
|
||||
{
|
||||
part_data->set_object_type(ET_Building);
|
||||
cs::MFBuildingPart* p = part_data->mutable_union_obj_3();
|
||||
@ -52,7 +54,7 @@ void Building::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
TypeConvert::ToPb(GetPos(), p->mutable_pos());
|
||||
}
|
||||
|
||||
void Building::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
void Building::FillMFObjectFull(Room* room, cs::MFObjectFull* full_data)
|
||||
{
|
||||
full_data->set_object_type(ET_Building);
|
||||
cs::MFBuildingFull* p = full_data->mutable_union_obj_3();
|
||||
|
@ -23,8 +23,8 @@ class Building : public Entity
|
||||
virtual ~Building() override;
|
||||
virtual void Initialize() override;
|
||||
void RecalcSelfCollider();
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
virtual void FillMFObjectPart(Room* room, cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(Room* room, cs::MFObjectFull* full_data) override;
|
||||
virtual void GetAabbBox(AabbCollider& aabb_box) override;
|
||||
|
||||
private:
|
||||
|
@ -90,7 +90,7 @@ void Bullet::OnHit(std::set<Entity*>& objects)
|
||||
case ET_Obstacle:
|
||||
{
|
||||
Obstacle* obstacle = (Obstacle*)target;
|
||||
if (!obstacle->IsDead() && obstacle->meta->i->attack_type() == 1) {
|
||||
if (!obstacle->IsDead(room) && obstacle->meta->i->attack_type() == 1) {
|
||||
#if 1
|
||||
float dmg = gun_meta->i->atk() * (1 + player->GetBuffAttrRate(kHAT_Atk)) +
|
||||
player->GetBuffAttrAbs(kHAT_Atk);
|
||||
@ -103,18 +103,18 @@ void Bullet::OnHit(std::set<Entity*>& objects)
|
||||
player->stats.damage_amount_out += finaly_dmg;
|
||||
#endif
|
||||
|
||||
obstacle->SetHealth(std::max(0.0f, obstacle->GetHealth() - finaly_dmg));
|
||||
if (obstacle->GetHealth() <= 0.01f) {
|
||||
obstacle->Die();
|
||||
obstacle->SetHealth(room, std::max(0.0f, obstacle->GetHealth(room) - finaly_dmg));
|
||||
if (obstacle->GetHealth(room) <= 0.01f) {
|
||||
obstacle->Die(room);
|
||||
}
|
||||
if (obstacle->IsDead()) {
|
||||
if (obstacle->IsDead(room)) {
|
||||
if (obstacle->meta->i->damage_dia() > 0.01f &&
|
||||
obstacle->meta->i->damage() > 0.01f) {
|
||||
obstacle->Explosion(this);
|
||||
}
|
||||
room->ScatterDrop(obstacle->GetPos(), obstacle->meta->i->drop());
|
||||
}
|
||||
obstacle->BroadcastFullState();
|
||||
obstacle->BroadcastFullState(room);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -137,7 +137,7 @@ void Bullet::ProcBomb()
|
||||
player->team_id == hum->team_id) {
|
||||
continue;
|
||||
}
|
||||
if (TestCollision(hum)) {
|
||||
if (TestCollision(room, hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ void Bullet::ProcBomb()
|
||||
case ET_Obstacle:
|
||||
case ET_Building:
|
||||
{
|
||||
if (TestCollision(entity)) {
|
||||
if (TestCollision(room, entity)) {
|
||||
objects.insert(entity);
|
||||
}
|
||||
}
|
||||
@ -212,7 +212,7 @@ void Bullet::MapServiceUpdate()
|
||||
for (auto& grid : grid_list) {
|
||||
for (Human* hum: grid->human_list) {
|
||||
#if 1
|
||||
if (hum != player && !hum->dead && TestCollision(hum)) {
|
||||
if (hum != player && !hum->dead && TestCollision(room, hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
#else
|
||||
@ -230,7 +230,7 @@ void Bullet::MapServiceUpdate()
|
||||
std::set<ColliderComponent*> colliders;
|
||||
room->map_service.GetColliders(GetX(), GetY(), colliders);
|
||||
for (ColliderComponent* collider : colliders) {
|
||||
if (TestCollision(collider)) {
|
||||
if (TestCollision(room, collider)) {
|
||||
objects.insert(collider->owner);
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,6 @@ Entity::~Entity()
|
||||
|
||||
void Entity::Initialize()
|
||||
{
|
||||
#if 0
|
||||
xtimer_attacher.xtimer = &room->xtimer;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Entity::GetAabbBox(AabbCollider& aabb_box)
|
||||
@ -37,24 +34,14 @@ void Entity::GetCircleBox(CircleCollider& circle_box)
|
||||
circle_box.rad = 1;
|
||||
}
|
||||
|
||||
bool Entity::IsDead()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
long long Entity::GetDeadFrameNo()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Entity::TestCollision(Entity* b)
|
||||
bool Entity::TestCollision(Room* room, Entity* b)
|
||||
{
|
||||
App::Instance()->perf.test_times++;
|
||||
if (b->IsDead()) {
|
||||
if (b->IsDead(room)) {
|
||||
return false;
|
||||
}
|
||||
OnPreCollision();
|
||||
b->OnPreCollision();
|
||||
OnPreCollision(room);
|
||||
b->OnPreCollision(room);
|
||||
for (auto& a_collider : colliders) {
|
||||
for (auto& b_collider : b->colliders) {
|
||||
if (a_collider->Intersect(b_collider)) {
|
||||
@ -65,13 +52,13 @@ bool Entity::TestCollision(Entity* b)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Entity::TestCollision(ColliderComponent* b)
|
||||
bool Entity::TestCollision(Room* room,ColliderComponent* b)
|
||||
{
|
||||
if (b->owner->IsDead()) {
|
||||
if (b->owner->IsDead(room)) {
|
||||
return false;
|
||||
}
|
||||
OnPreCollision();
|
||||
b->owner->OnPreCollision();
|
||||
OnPreCollision(room);
|
||||
b->owner->OnPreCollision(room);
|
||||
for (auto& a_collider : colliders) {
|
||||
if (a_collider->Intersect(b)) {
|
||||
return true;
|
||||
@ -80,11 +67,11 @@ bool Entity::TestCollision(ColliderComponent* b)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Entity::TestCollisionEx(const a8::Vec2& aabb_pos, AabbCollider& aabb_box)
|
||||
bool Entity::TestCollisionEx(Room* room, const a8::Vec2& aabb_pos, AabbCollider& aabb_box)
|
||||
{
|
||||
OnPreCollision();
|
||||
OnPreCollision(room);
|
||||
if (aabb_box.owner) {
|
||||
aabb_box.owner->OnPreCollision();
|
||||
aabb_box.owner->OnPreCollision(room);
|
||||
}
|
||||
for (auto& a_collider : colliders) {
|
||||
if (a_collider->IntersectEx(aabb_pos, &aabb_box)) {
|
||||
@ -103,7 +90,7 @@ void Entity::ClearColliders()
|
||||
colliders.clear();
|
||||
}
|
||||
|
||||
void Entity::BroadcastFullState()
|
||||
void Entity::BroadcastFullState(Room* room)
|
||||
{
|
||||
std::set<GridCell*> grid_list;
|
||||
room->grid_service.GetAllCells(grid_id, grid_list);
|
||||
@ -114,7 +101,7 @@ void Entity::BroadcastFullState()
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::BroadcastDeleteState()
|
||||
void Entity::BroadcastDeleteState(Room* room)
|
||||
{
|
||||
std::set<GridCell*> grid_list;
|
||||
room->grid_service.GetAllCells(grid_id, grid_list);
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "gridservice.h"
|
||||
#include "room.h"
|
||||
|
||||
namespace cs
|
||||
{
|
||||
@ -14,6 +13,7 @@ class Obstacle;
|
||||
class ColliderComponent;
|
||||
class AabbCollider;
|
||||
class CircleCollider;
|
||||
class MapService;
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
@ -21,7 +21,6 @@ class Entity
|
||||
EntityType_e entity_type = ET_None;
|
||||
EntitySubType_e entity_subtype = EST_None;
|
||||
long long create_frameno = 0;
|
||||
Room* room = nullptr;
|
||||
int updated_times = 0;
|
||||
bool deleted = false;
|
||||
|
||||
@ -36,19 +35,19 @@ class Entity
|
||||
virtual ~Entity();
|
||||
virtual void Initialize();
|
||||
virtual void Update(int delta_time) {};
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) {};
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) {};
|
||||
virtual void FillMFObjectPart(Room* room, cs::MFObjectPart* part_data) {};
|
||||
virtual void FillMFObjectFull(Room* room, cs::MFObjectFull* full_data) {};
|
||||
virtual float GetSpeed() { return 1.0f;};
|
||||
virtual void GetAabbBox(AabbCollider& aabb_box);
|
||||
virtual void GetCircleBox(CircleCollider& circle_box);
|
||||
virtual bool IsDead();
|
||||
virtual long long GetDeadFrameNo();
|
||||
virtual void OnPreCollision() {};
|
||||
bool TestCollision(Entity* b);
|
||||
bool TestCollision(ColliderComponent* b);
|
||||
bool TestCollisionEx(const a8::Vec2& aabb_pos, AabbCollider& aabb_box);
|
||||
void BroadcastFullState();
|
||||
void BroadcastDeleteState();
|
||||
virtual bool IsDead(Room* room) {};
|
||||
virtual long long GetDeadFrameNo(Room* room) { return 0;};
|
||||
virtual void OnPreCollision(Room* room) {};
|
||||
bool TestCollision(Room* room, Entity* b);
|
||||
bool TestCollision(Room* room, ColliderComponent* b);
|
||||
bool TestCollisionEx(Room* room, const a8::Vec2& aabb_pos, AabbCollider& aabb_box);
|
||||
void BroadcastFullState(Room* room);
|
||||
void BroadcastDeleteState(Room* room);
|
||||
void AddCollider(ColliderComponent* collider);
|
||||
a8::Vec2 GetPos() { return pos_; };
|
||||
bool IsPermanent();
|
||||
|
@ -26,11 +26,11 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
itr->FillMFObjectFull(msg->add_full_objects());
|
||||
itr->FillMFObjectFull(room, msg->add_full_objects());
|
||||
}
|
||||
for (auto& itr : hum->part_objects) {
|
||||
Entity* entity = itr;
|
||||
if (entity->IsDead() && hum->room->frame_no - entity->GetDeadFrameNo() > 10) {
|
||||
if (entity->IsDead(room) && hum->room->frame_no - entity->GetDeadFrameNo(room) > 10) {
|
||||
continue;
|
||||
} else {
|
||||
#if 0
|
||||
@ -42,7 +42,7 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
entity->FillMFObjectPart(msg->add_part_objects());
|
||||
entity->FillMFObjectPart(room, msg->add_part_objects());
|
||||
}
|
||||
for (auto& itr : hum->del_objects) {
|
||||
msg->add_del_objids(itr);
|
||||
|
@ -104,7 +104,7 @@ float Human::GetSpeed4()
|
||||
return meta->i->move_speed4();
|
||||
}
|
||||
|
||||
void Human::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
void Human::FillMFObjectPart(Room* room, cs::MFObjectPart* part_data)
|
||||
{
|
||||
part_data->set_object_type(ET_Player);
|
||||
cs::MFPlayerPart* p = part_data->mutable_union_obj_1();
|
||||
@ -113,7 +113,7 @@ void Human::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
TypeConvert::ToPb(attack_dir, p->mutable_dir());
|
||||
}
|
||||
|
||||
void Human::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
void Human::FillMFObjectFull(Room* room, cs::MFObjectFull* full_data)
|
||||
{
|
||||
full_data->set_object_type(ET_Player);
|
||||
cs::MFPlayerFull* p = full_data->mutable_union_obj_1();
|
||||
@ -248,12 +248,12 @@ void Human::GetAabbBox(AabbCollider& aabb_box)
|
||||
aabb_box._max.y = meta->i->radius();
|
||||
}
|
||||
|
||||
bool Human::IsDead()
|
||||
bool Human::IsDead(Room * room)
|
||||
{
|
||||
return dead;
|
||||
}
|
||||
|
||||
long long Human::GetDeadFrameNo()
|
||||
long long Human::GetDeadFrameNo(Room* room)
|
||||
{
|
||||
return dead_frameno;
|
||||
}
|
||||
@ -450,7 +450,7 @@ bool Human::IsCollisionInMapService()
|
||||
{
|
||||
Obstacle* obstacle = (Obstacle*)collider->owner;
|
||||
#if 1
|
||||
if (!obstacle->IsDead() &&
|
||||
if (!obstacle->IsDead(room) &&
|
||||
(
|
||||
(collider->type == CT_Aabb && aabb_box.Intersect((ColliderComponent*)collider)) ||
|
||||
(collider->type == CT_Circle && self_collider_->Intersect((ColliderComponent*)collider))
|
||||
@ -460,13 +460,13 @@ bool Human::IsCollisionInMapService()
|
||||
if (!collider->owner->dead && TestCollision((ColliderComponent*)collider)) {
|
||||
#endif
|
||||
if (last_collision_door != collider->owner) {
|
||||
if (!obstacle->IsDead() &&
|
||||
if (!obstacle->IsDead(room) &&
|
||||
obstacle->meta->i->attack_type() == 1 &&
|
||||
obstacle->meta->i->drop() != 0 &&
|
||||
room->gas_data.gas_mode != GasInactive
|
||||
) {
|
||||
obstacle->Die();
|
||||
if (obstacle->IsDead()) {
|
||||
obstacle->Die(room);
|
||||
if (obstacle->IsDead(room)) {
|
||||
#if 0
|
||||
if (obstacle->meta->i->damage_dia() > 0.01f &&
|
||||
obstacle->meta->i->damage() > 0.01f) {
|
||||
@ -475,7 +475,7 @@ bool Human::IsCollisionInMapService()
|
||||
#endif
|
||||
room->ScatterDrop(obstacle->GetPos(), obstacle->meta->i->drop());
|
||||
}
|
||||
obstacle->BroadcastFullState();
|
||||
obstacle->BroadcastFullState(room);
|
||||
} else {
|
||||
Global::last_collider = collider;
|
||||
return true;
|
||||
@ -1109,7 +1109,7 @@ void Human::FindLocation()
|
||||
case ET_Obstacle:
|
||||
{
|
||||
if (!target) {
|
||||
if (TestCollision(entity)) {
|
||||
if (TestCollision(room, entity)) {
|
||||
target = entity;
|
||||
}
|
||||
}
|
||||
@ -1120,7 +1120,7 @@ void Human::FindLocation()
|
||||
if (!target || target->entity_type != ET_Building) {
|
||||
AabbCollider aabb_box;
|
||||
entity->GetAabbBox(aabb_box);
|
||||
if (TestCollision(&aabb_box)) {
|
||||
if (TestCollision(room, &aabb_box)) {
|
||||
target = entity;
|
||||
}
|
||||
}
|
||||
@ -1483,7 +1483,7 @@ void Human::SendUpdateMsg()
|
||||
}
|
||||
for (Entity* entity : view_objects) {
|
||||
if (new_objects.find(entity) == new_objects.end()) {
|
||||
entity->FillMFObjectFull(msg->add_full_objects());
|
||||
entity->FillMFObjectFull(room, msg->add_full_objects());
|
||||
}
|
||||
}
|
||||
refreshed_view = true;
|
||||
@ -1757,7 +1757,7 @@ void Human::CheckSkinTank()
|
||||
return;
|
||||
}
|
||||
float old_rad = hum->last_tank_attacker->self_collider_->rad;
|
||||
if (!hum->TestCollision(hum->last_tank_attacker)) {
|
||||
if (!hum->TestCollision(hum->room, hum->last_tank_attacker)) {
|
||||
hum->last_tank_attacker->self_collider_->rad = old_rad;
|
||||
hum->last_tank_attacker = nullptr;
|
||||
hum->last_tank_attack_idx = 0;
|
||||
@ -1788,7 +1788,7 @@ void Human::CheckSkinTank()
|
||||
!hum->tank_weapon.meta &&
|
||||
hum->last_tank_attacker != this &&
|
||||
(hum->team_id == 0 || team_id != hum->team_id)) {
|
||||
if (TestCollision(hum)) {
|
||||
if (TestCollision(room, hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
@ -2361,7 +2361,7 @@ void Human::FindLocationWithTarget(Entity* target)
|
||||
switch (entity->entity_type) {
|
||||
case ET_Building:
|
||||
{
|
||||
if (TestCollision(entity)) {
|
||||
if (TestCollision(room, entity)) {
|
||||
building = entity;
|
||||
}
|
||||
}
|
||||
@ -2383,7 +2383,7 @@ void Human::FindLocationWithTarget(Entity* target)
|
||||
std::set<ColliderComponent*> colliders;
|
||||
room->map_service.GetColliders(GetX(), GetY(), colliders);
|
||||
for (ColliderComponent* collider : colliders) {
|
||||
if (TestCollision(collider)) {
|
||||
if (TestCollision(room, collider)) {
|
||||
is_collision = true;
|
||||
break;
|
||||
}
|
||||
|
@ -138,12 +138,12 @@ class Human : public RoomEntity
|
||||
virtual void Initialize() override;
|
||||
virtual float GetSpeed() override;
|
||||
virtual float GetSpeed4();
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
virtual void FillMFObjectPart(Room* room, cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(Room* room, cs::MFObjectFull* full_data) override;
|
||||
virtual void FillMFPlayerStats(cs::MFPlayerStats* stats);
|
||||
virtual void GetAabbBox(AabbCollider& aabb_box);
|
||||
virtual bool IsDead() override;
|
||||
virtual long long GetDeadFrameNo() override;
|
||||
virtual bool IsDead(Room* room) override;
|
||||
virtual long long GetDeadFrameNo(Room* room) override;
|
||||
void FillMFTeamData(cs::MFTeamData* team_data);
|
||||
void Shot(a8::Vec2& target_dir);
|
||||
void TankShot(a8::Vec2& target_dir);
|
||||
|
@ -29,7 +29,7 @@ void Loot::RecalcSelfCollider()
|
||||
{
|
||||
}
|
||||
|
||||
void Loot::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
void Loot::FillMFObjectPart(Room* room, cs::MFObjectPart* part_data)
|
||||
{
|
||||
part_data->set_object_type(ET_Loot);
|
||||
cs::MFLootPart* p = part_data->mutable_union_obj_5();
|
||||
@ -37,7 +37,7 @@ void Loot::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
TypeConvert::ToPb(GetPos(), p->mutable_pos());
|
||||
}
|
||||
|
||||
void Loot::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
void Loot::FillMFObjectFull(Room* room, cs::MFObjectFull* full_data)
|
||||
{
|
||||
full_data->set_object_type(ET_Loot);
|
||||
cs::MFLootFull* p = full_data->mutable_union_obj_5();
|
||||
|
@ -26,6 +26,6 @@ class Loot : public RoomEntity
|
||||
virtual ~Loot() override;
|
||||
virtual void Initialize() override;
|
||||
void RecalcSelfCollider();
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
virtual void FillMFObjectPart(Room* room, cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(Room* room, cs::MFObjectFull* full_data) override;
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "human.h"
|
||||
#include "app.h"
|
||||
#include "typeconvert.h"
|
||||
#include "bullet.h"
|
||||
|
||||
enum ObstacleDataFlags_e
|
||||
{
|
||||
@ -91,7 +92,7 @@ void Obstacle::RecalcSelfCollider()
|
||||
}
|
||||
}
|
||||
|
||||
void Obstacle::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
void Obstacle::FillMFObjectPart(Room* room, cs::MFObjectPart* part_data)
|
||||
{
|
||||
part_data->set_object_type(ET_Obstacle);
|
||||
cs::MFObstaclePart* p = part_data->mutable_union_obj_2();
|
||||
@ -100,7 +101,7 @@ void Obstacle::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
p->set_scale(1.0f);
|
||||
}
|
||||
|
||||
void Obstacle::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
void Obstacle::FillMFObjectFull(Room* room, cs::MFObjectFull* full_data)
|
||||
{
|
||||
full_data->set_object_type(ET_Obstacle);
|
||||
cs::MFObstacleFull* p = full_data->mutable_union_obj_2();
|
||||
@ -111,7 +112,7 @@ void Obstacle::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
p->set_obstacle_id(meta->i->thing_id());
|
||||
p->set_health(health_);
|
||||
p->set_dead(dead_);
|
||||
p->set_dead_at_thisframe(IsDead() ? dead_frameno_ <= room->frame_no : false);
|
||||
p->set_dead_at_thisframe(IsDead(room) ? dead_frameno_ <= room->frame_no : false);
|
||||
|
||||
p->set_is_door(is_door_);
|
||||
#if 0
|
||||
@ -157,7 +158,7 @@ void Obstacle::GetCircleBox(CircleCollider& circle_box)
|
||||
|
||||
}
|
||||
|
||||
bool Obstacle::IsDead()
|
||||
bool Obstacle::IsDead(Room* room)
|
||||
{
|
||||
if (IsPermanent()) {
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
@ -172,7 +173,7 @@ bool Obstacle::IsDead()
|
||||
|
||||
}
|
||||
|
||||
long long Obstacle::GetDeadFrameNo()
|
||||
long long Obstacle::GetDeadFrameNo(Room* room)
|
||||
{
|
||||
if (IsPermanent()) {
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
@ -186,7 +187,7 @@ long long Obstacle::GetDeadFrameNo()
|
||||
}
|
||||
}
|
||||
|
||||
void Obstacle::OnPreCollision()
|
||||
void Obstacle::OnPreCollision(Room* room)
|
||||
{
|
||||
if (!is_door_) {
|
||||
return;
|
||||
@ -213,6 +214,7 @@ void Obstacle::OnPreCollision()
|
||||
|
||||
void Obstacle::Explosion(Bullet* bullet)
|
||||
{
|
||||
Room* room = bullet->room;
|
||||
float old_rad = self_collider_->rad;
|
||||
if (self_collider_) {
|
||||
self_collider_->rad = meta->i->damage_dia();
|
||||
@ -224,7 +226,7 @@ void Obstacle::Explosion(Bullet* bullet)
|
||||
room->grid_service.GetAllCellsByXy(GetX(), GetY(), grid_list);
|
||||
for (auto& grid : grid_list) {
|
||||
for (Human* hum: grid->human_list) {
|
||||
if (TestCollision(hum)) {
|
||||
if (TestCollision(room, hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
@ -233,7 +235,7 @@ void Obstacle::Explosion(Bullet* bullet)
|
||||
case ET_Obstacle:
|
||||
case ET_Building:
|
||||
{
|
||||
if (entity != this && TestCollision(entity)) {
|
||||
if (entity != this && TestCollision(room, entity)) {
|
||||
objects.insert(entity);
|
||||
}
|
||||
}
|
||||
@ -271,19 +273,20 @@ void Obstacle::Explosion(Bullet* bullet)
|
||||
case ET_Obstacle:
|
||||
{
|
||||
Obstacle* obstacle = (Obstacle*)target;
|
||||
if (!obstacle->IsDead() && obstacle->meta->i->attack_type() == 1) {
|
||||
if (!obstacle->IsDead(room) && obstacle->meta->i->attack_type() == 1) {
|
||||
float dmg = meta->i->damage();
|
||||
float def = 0;
|
||||
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
|
||||
|
||||
obstacle->SetHealth(std::max(0.0f, obstacle->health_ - finaly_dmg));
|
||||
if (obstacle->GetHealth() <= 0.01f) {
|
||||
obstacle->Die();
|
||||
obstacle->SetHealth(room,
|
||||
std::max(0.0f, obstacle->health_ - finaly_dmg));
|
||||
if (obstacle->GetHealth(room) <= 0.01f) {
|
||||
obstacle->Die(room);
|
||||
}
|
||||
if (obstacle->IsDead()) {
|
||||
if (obstacle->IsDead(room)) {
|
||||
room->ScatterDrop(obstacle->GetPos(), obstacle->meta->i->drop());
|
||||
}
|
||||
obstacle->BroadcastFullState();
|
||||
obstacle->BroadcastFullState(room);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -314,13 +317,13 @@ bool Obstacle::IsDoor()
|
||||
return is_door_;
|
||||
}
|
||||
|
||||
DoorState_e Obstacle::GetDoorState()
|
||||
DoorState_e Obstacle::GetDoorState(Room *room)
|
||||
{
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
return p->door_state;
|
||||
}
|
||||
|
||||
void Obstacle::SetDoorState(DoorState_e state)
|
||||
void Obstacle::SetDoorState(Room* room, DoorState_e state)
|
||||
{
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
p->door_state = state;
|
||||
@ -346,13 +349,13 @@ const metatable::DoorObjJson* Obstacle::GetDoorState1()
|
||||
return door_state1_;
|
||||
}
|
||||
|
||||
void Obstacle::IncDoorOpenTimes()
|
||||
void Obstacle::IncDoorOpenTimes(Room* room)
|
||||
{
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
++(p->door_open_times);
|
||||
}
|
||||
|
||||
float Obstacle::GetHealth()
|
||||
float Obstacle::GetHealth(Room* room)
|
||||
{
|
||||
if (IsPermanent()) {
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
@ -366,7 +369,7 @@ float Obstacle::GetHealth()
|
||||
}
|
||||
}
|
||||
|
||||
void Obstacle::SetHealth(float value)
|
||||
void Obstacle::SetHealth(Room* room, float value)
|
||||
{
|
||||
if (IsPermanent()) {
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
@ -380,7 +383,7 @@ void Obstacle::SetHealth(float value)
|
||||
}
|
||||
}
|
||||
|
||||
void Obstacle::Die()
|
||||
void Obstacle::Die(Room* room)
|
||||
{
|
||||
if (IsPermanent()) {
|
||||
ObstacleData* p = room->GetPermanentObstacleData(entity_uniid);
|
||||
|
@ -13,6 +13,7 @@ namespace metatable
|
||||
class DoorObjJson;
|
||||
}
|
||||
|
||||
class Room;
|
||||
class Human;
|
||||
class Building;
|
||||
class CircleCollider;
|
||||
@ -27,26 +28,26 @@ class Obstacle : public Entity
|
||||
virtual ~Obstacle() override;
|
||||
virtual void Initialize() override;
|
||||
void RecalcSelfCollider();
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
virtual void FillMFObjectPart(Room* room, cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(Room* room, cs::MFObjectFull* full_data) override;
|
||||
virtual void GetAabbBox(AabbCollider& aabb_box) override;
|
||||
virtual void GetCircleBox(CircleCollider& circle_box) override;
|
||||
virtual bool IsDead() override;
|
||||
virtual long long GetDeadFrameNo() override;
|
||||
virtual void OnPreCollision() override;
|
||||
virtual bool IsDead(Room* room) override;
|
||||
virtual long long GetDeadFrameNo(Room* room) override;
|
||||
virtual void OnPreCollision(Room* room) override;
|
||||
void Explosion(Bullet* bullet);
|
||||
void SetDoorInfo(Building* building, int door_id_x);
|
||||
bool IsDoor();
|
||||
DoorState_e GetDoorState();
|
||||
void SetDoorState(DoorState_e state);
|
||||
DoorState_e GetDoorState(Room* room);
|
||||
void SetDoorState(Room* room, DoorState_e state);
|
||||
void SetBuilding(Building* building);
|
||||
Building* GetBuilding();
|
||||
const metatable::DoorObjJson* GetDoorState0();
|
||||
const metatable::DoorObjJson* GetDoorState1();
|
||||
void IncDoorOpenTimes();
|
||||
float GetHealth();
|
||||
void SetHealth(float value);
|
||||
void Die();
|
||||
void IncDoorOpenTimes(Room* room);
|
||||
float GetHealth(Room* room);
|
||||
void SetHealth(Room* room, float value);
|
||||
void Die(Room* room);
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
|
@ -131,7 +131,7 @@ void Player::UpdateMove()
|
||||
}
|
||||
a8::Vec2 old_pos = GetPos();
|
||||
_UpdateMove(std::max(1, (int)GetSpeed()));
|
||||
if (last_collision_door && !TestCollision(last_collision_door)) {
|
||||
if (last_collision_door && !TestCollision(room, last_collision_door)) {
|
||||
last_collision_door = nullptr;
|
||||
}
|
||||
if (tank_weapon.meta) {
|
||||
@ -472,24 +472,24 @@ void Player::ProcInteraction()
|
||||
void Player::ObstacleInteraction(Obstacle* entity)
|
||||
{
|
||||
if (entity->IsDoor()) {
|
||||
if (entity->GetDoorState() == DoorStateClose) {
|
||||
entity->SetDoorState(DoorStateOpen);
|
||||
if (entity->GetDoorState(room) == DoorStateClose) {
|
||||
entity->SetDoorState(room, DoorStateOpen);
|
||||
float x = entity->GetBuilding()->GetX() + entity->GetDoorState1()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
|
||||
float y = entity->GetBuilding()->GetY() + entity->GetDoorState1()->y() - entity->GetBuilding()->meta->i->tileheight() / 2.0;
|
||||
entity->SetPos(a8::Vec2(x, y));
|
||||
} else {
|
||||
entity->SetDoorState(DoorStateClose);
|
||||
entity->SetDoorState(room, DoorStateClose);
|
||||
float x = entity->GetBuilding()->GetX() + entity->GetDoorState0()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
|
||||
float y = entity->GetBuilding()->GetY() + entity->GetDoorState0()->y() - entity->GetBuilding()->meta->i->tileheight() / 2.0;
|
||||
entity->SetPos(a8::Vec2(x, y));
|
||||
}
|
||||
entity->IncDoorOpenTimes();
|
||||
entity->IncDoorOpenTimes(room);
|
||||
entity->RecalcSelfCollider();
|
||||
room->TouchHumanList(a8::XParams(),
|
||||
[entity] (Human* hum, a8::XParams& param) -> bool
|
||||
{
|
||||
hum->AddToNewObjects(entity);
|
||||
if (entity->TestCollision(hum)) {
|
||||
if (entity->TestCollision(hum->room, hum)) {
|
||||
hum->last_collision_door = entity;
|
||||
} else if (hum->last_collision_door == entity) {
|
||||
hum->last_collision_door = nullptr;
|
||||
@ -623,7 +623,7 @@ void Player::LootInteraction(Loot* entity)
|
||||
if (add_num < entity->count) {
|
||||
//刷新数量
|
||||
entity->count -= add_num;
|
||||
entity->BroadcastFullState();
|
||||
entity->BroadcastFullState(room);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
@ -375,7 +375,7 @@ Obstacle* Room::CreateObstacle(int id, float x, float y)
|
||||
});
|
||||
assert(entity);
|
||||
if (entity) {
|
||||
entity->BroadcastFullState();
|
||||
entity->BroadcastFullState(this);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
@ -415,7 +415,7 @@ int Room::CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv)
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
grid_service.AddEntity(entity);
|
||||
entity->BroadcastFullState();
|
||||
entity->BroadcastFullState(this);
|
||||
return entity->entity_uniid;
|
||||
} else {
|
||||
return 0;
|
||||
@ -449,7 +449,7 @@ void Room::RemoveObjectLater(RoomEntity* entity)
|
||||
{
|
||||
auto remove_func = [] (const a8::XParams& param)
|
||||
{
|
||||
Entity* entity = (Entity*)param.sender.GetUserData();
|
||||
RoomEntity* entity = (RoomEntity*)param.sender.GetUserData();
|
||||
switch (entity->entity_type) {
|
||||
case ET_Bullet:
|
||||
{
|
||||
@ -459,7 +459,7 @@ void Room::RemoveObjectLater(RoomEntity* entity)
|
||||
break;
|
||||
case ET_Loot:
|
||||
{
|
||||
entity->BroadcastDeleteState();
|
||||
entity->BroadcastDeleteState(entity->room);
|
||||
entity->room->grid_service.DelEntity(entity);
|
||||
}
|
||||
break;
|
||||
@ -619,7 +619,7 @@ Entity* Room::FindFirstCollisonEntity(const a8::Vec2& aabb_pos, AabbCollider& aa
|
||||
case ET_Obstacle:
|
||||
{
|
||||
if (!target) {
|
||||
if (entity->TestCollisionEx(aabb_pos, aabb_box)) {
|
||||
if (entity->TestCollisionEx(this, aabb_pos, aabb_box)) {
|
||||
target = entity;
|
||||
}
|
||||
}
|
||||
@ -1165,7 +1165,6 @@ Obstacle* Room::InternalCreateObstacle(int id, float x, float y,
|
||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(id);
|
||||
if (thing) {
|
||||
Obstacle* entity = new Obstacle();
|
||||
entity->room = this;
|
||||
entity->meta = thing;
|
||||
entity->entity_uniid = AllocUniid();
|
||||
entity->SetPos(a8::Vec2(x, y));
|
||||
|
@ -5,6 +5,7 @@
|
||||
class RoomEntity : public Entity
|
||||
{
|
||||
public:
|
||||
Room* room = nullptr;
|
||||
a8::XTimerAttacher xtimer_attacher;
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user