添加地表处理
This commit is contained in:
parent
8e38d882c2
commit
e07988c0ce
@ -15,6 +15,8 @@ class ColliderComponent
|
||||
ColliderType_e type = CT_None;
|
||||
bool active = true;
|
||||
int tag = 0;
|
||||
int param1 = 0;
|
||||
int param2 = 0;
|
||||
|
||||
bool Intersect(ColliderComponent* b);
|
||||
bool IntersectEx(const a8::Vec2& pos, ColliderComponent* b);
|
||||
|
@ -1120,6 +1120,8 @@ void Creature::CheckSpecObject()
|
||||
|
||||
#ifdef DEBUG
|
||||
long long old_cell_flags = cell_flags_;
|
||||
int water_w = 0;
|
||||
int water_h = 0;
|
||||
#endif
|
||||
cell_flags_ = 0;
|
||||
for (const ColliderComponent* collider : colliders) {
|
||||
@ -1129,6 +1131,12 @@ void Creature::CheckSpecObject()
|
||||
{
|
||||
if (TestCollision(room, (ColliderComponent*)collider)) {
|
||||
cell_flags_ |= collider->tag;
|
||||
#ifdef DEBUG
|
||||
if (a8::HasBitFlag(collider->tag, kColliderTag_Water)) {
|
||||
water_w = collider->param1;
|
||||
water_h = collider->param2;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1175,7 +1183,7 @@ void Creature::CheckSpecObject()
|
||||
msg += " 灰:0";
|
||||
}
|
||||
}
|
||||
msg += a8::Format(" o:%d n:%d", {old_cell_flags, cell_flags_});
|
||||
msg += a8::Format(" o:%d n:%d w:%d h:%d", {old_cell_flags, cell_flags_, water_w, water_h});
|
||||
SendDebugMsg(msg);
|
||||
}
|
||||
}
|
||||
|
@ -3253,12 +3253,6 @@ void Human::OnLand()
|
||||
}
|
||||
SetPos(old_pos);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (IsPlayer()) {
|
||||
SummonHero(6001);
|
||||
a8::XPrintf("Summon Hero\n", {});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Human::NextReload(int prev_weapon_id, int prev_weapon_idx)
|
||||
|
@ -162,7 +162,7 @@ void MapInstance::CreateTerrain()
|
||||
return;
|
||||
}
|
||||
metatable::MapLayerJson* first_layer = nullptr;
|
||||
for (auto layer : *layers) {
|
||||
for (auto& layer : *layers) {
|
||||
if (!first_layer) {
|
||||
first_layer = &layer;
|
||||
}
|
||||
@ -190,15 +190,15 @@ void MapInstance::CreateTerrain()
|
||||
}
|
||||
std::set<int> dusts;
|
||||
for (auto idx : terrain->dust()) {
|
||||
dusts.insert(idx);
|
||||
dusts.insert(idx + 1);
|
||||
}
|
||||
std::set<int> waters;
|
||||
for (auto idx : terrain->water()) {
|
||||
waters.insert(idx);
|
||||
waters.insert(idx + 1);
|
||||
}
|
||||
std::set<int> grasses;
|
||||
for (auto idx : terrain->grass()) {
|
||||
grasses.insert(idx);
|
||||
grasses.insert(idx + 1);
|
||||
}
|
||||
|
||||
int mask = A8_DEFINE_RANGE_BIT(int, 0, 22);
|
||||
@ -222,7 +222,7 @@ void MapInstance::CreateTerrain()
|
||||
for (int w = 0; w < first_layer->width(); ++w) {
|
||||
for (int h = 0; h < first_layer->height(); ++h) {
|
||||
assert(w < 300 && h < 300);
|
||||
int grid_val = grids[w * first_layer->width() + h];
|
||||
int grid_val = grids[h * first_layer->width() + w];
|
||||
if (grid_val != 0) {
|
||||
float x = w * thing_meta->i->width() + thing_meta->i->width() / 2.0f;
|
||||
float y = (first_layer->height() * thing_meta->i->height()) - (h * thing_meta->i->height() + thing_meta->i->height() / 2.0f);
|
||||
@ -233,6 +233,7 @@ void MapInstance::CreateTerrain()
|
||||
} else if (waters.find(grid_val) != waters.end()) {
|
||||
a8::SetBitFlag(collider_tag, kColliderTag_Water);
|
||||
assert(collider_tag > 0);
|
||||
|
||||
} else if (grasses.find(grid_val) != grasses.end()) {
|
||||
a8::SetBitFlag(collider_tag, kColliderTag_Grass);
|
||||
assert(collider_tag > 0);
|
||||
@ -244,7 +245,9 @@ void MapInstance::CreateTerrain()
|
||||
[] (Obstacle* entity)
|
||||
{
|
||||
},
|
||||
true);
|
||||
true,
|
||||
w,
|
||||
h);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -324,12 +327,16 @@ void MapInstance::CreateBuilding(int thing_id, float building_x, float building_
|
||||
|
||||
Obstacle* MapInstance::InternalCreateObstacle(int id, float x, float y, int collider_tag,
|
||||
std::function<void (Obstacle*)> on_precreate,
|
||||
bool no_grid_service)
|
||||
bool no_grid_service,
|
||||
int collider_param1,
|
||||
int collider_param2)
|
||||
{
|
||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(id);
|
||||
if (thing) {
|
||||
Obstacle* entity = EntityFactory::Instance()->MakeObstacle(AllocUniid());
|
||||
entity->collider_tag = collider_tag;
|
||||
entity->collider_param1 = collider_param1;
|
||||
entity->collider_param2 = collider_param2;
|
||||
entity->meta = thing;
|
||||
entity->is_permanent = true;
|
||||
entity->permanent_map_service = map_service_;
|
||||
|
@ -31,7 +31,9 @@ class MapInstance
|
||||
void CreateBuilding(int thing_id, float building_x, float building_y);
|
||||
Obstacle* InternalCreateObstacle(int id, float x, float y, int collider_tag,
|
||||
std::function<void (Obstacle*)> on_precreate,
|
||||
bool no_grid_service = false);
|
||||
bool no_grid_service = false,
|
||||
int collider_param1 = 0,
|
||||
int collider_param2 = 0);
|
||||
Entity* GetEntityByUniId(int uniid);
|
||||
int AllocUniid();
|
||||
|
||||
|
@ -99,6 +99,8 @@ void Obstacle::RecalcSelfCollider()
|
||||
}
|
||||
for (auto collider : colliders_) {
|
||||
collider->tag = collider_tag;
|
||||
collider->param1 = collider_param1;
|
||||
collider->param2 = collider_param2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@ class Obstacle : public Entity
|
||||
MapService* permanent_map_service = nullptr;
|
||||
bool is_permanent = false;
|
||||
int collider_tag = 0;
|
||||
int collider_param1 = 0;
|
||||
int collider_param2 = 0;
|
||||
|
||||
virtual ~Obstacle() override;
|
||||
virtual void Initialize() override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user