添加房间读表

This commit is contained in:
aozhiwei 2019-04-09 11:20:08 +08:00
parent 8b5d30762b
commit 3fc0c50c98
5 changed files with 53 additions and 4 deletions

View File

@ -156,7 +156,7 @@ namespace MetaData
for (auto& str : strings) { for (auto& str : strings) {
std::vector<std::string> strings2; std::vector<std::string> strings2;
a8::Split(str, strings2, ':'); a8::Split(str, strings2, ':');
assert(strings.size() == 2); assert(strings2.size() == 2);
rand_space += a8::XValue(strings2[1]).GetInt(); rand_space += a8::XValue(strings2[1]).GetInt();
things.push_back(std::make_tuple( things.push_back(std::make_tuple(
a8::XValue(strings2[0]), a8::XValue(strings2[0]),

View File

@ -79,7 +79,7 @@ private:
item.i = &meta; item.i = &meta;
item.Init(); item.Init();
gamemap_hash[item.i->map_id()] = &item; gamemap_hash[item.i->map_id()] = &item;
#if 0 #if 1
{ {
for (auto& tuple : item.template_list) { for (auto& tuple : item.template_list) {
auto itr = maptpl_meta_hash.find(std::get<0>(tuple)); auto itr = maptpl_meta_hash.find(std::get<0>(tuple));

View File

@ -395,6 +395,50 @@ void Room::ProcDrop(Vector2D center, int drop_id)
} }
} }
void Room::CreateThings()
{
std::string tpl_name = map_meta->RandTemplate();
std::vector<MetaData::MapTplThing>* things = MetaMgr::Instance()->GetMapTplThing(tpl_name);
if (things) {
for (auto& thing_tpl : *things) {
if (thing_tpl.i->weight() >= rand() % 10000) {
int thing_id = thing_tpl.RandThing();
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id);
if (thing_meta) {
if (thing_meta->i->is_house()) {
MetaData::Building* building_meta = MetaMgr::Instance()->GetBuilding(1);
if (building_meta) {
Building* entity = new Building();
entity->room = this;
entity->meta = building_meta;
entity->entity_uniid = AllocUniid();
entity->pos = Vector2D(thing_tpl.i->x(), thing_tpl.i->y());
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
} else {
Obstacle* entity = new Obstacle();
entity->room = this;
entity->meta = thing_meta;
entity->entity_uniid = AllocUniid();
entity->pos = Vector2D(thing_tpl.i->x(), thing_tpl.i->y());
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
}
}
}
}
}
void Room::ClearDeletedObjects() void Room::ClearDeletedObjects()
{ {
for (auto& obj_uniid : frame_data.deleted_objects) { for (auto& obj_uniid : frame_data.deleted_objects) {

View File

@ -61,6 +61,7 @@ public:
std::function<void (Player*, a8::XParams&)> func); std::function<void (Player*, a8::XParams&)> func);
void BeAddedObject(Entity* entity); void BeAddedObject(Entity* entity);
void ProcDrop(Vector2D center, int drop_id); void ProcDrop(Vector2D center, int drop_id);
void CreateThings();
private: private:
void ClearDeletedObjects(); void ClearDeletedObjects();

View File

@ -23,6 +23,10 @@ message MapThing
optional float damage_dia = 7; // optional float damage_dia = 7; //
optional int32 drop = 8; // optional int32 drop = 8; //
optional int32 attackable = 9; // optional int32 attackable = 9; //
optional int32 is_door = 10; //
optional int32 is_house = 11; //
optional int32 is_tree = 12; //
optional int32 house_id = 13; //id
} }
message SafeArea message SafeArea
@ -140,6 +144,6 @@ message MapTplThingJson
optional string name = 2; optional string name = 2;
optional string things = 3; optional string things = 3;
optional int32 weight = 4; optional int32 weight = 4;
// optional float x = 5; optional float x = 5;
// optional float y = 6; optional float y = 6;
} }