242 lines
7.8 KiB
C++
242 lines
7.8 KiB
C++
#include "precompile.h"
|
|
|
|
#include "metadata.h"
|
|
|
|
namespace MetaData
|
|
{
|
|
void Parameter::Init()
|
|
{
|
|
int_val = a8::XValue(i->param_value());
|
|
float_val = a8::XValue(i->param_value());
|
|
str_val = a8::XValue(i->param_value()).GetString();
|
|
}
|
|
|
|
void Map::Init()
|
|
{
|
|
rand_space = 0;
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(i->template_list(), strings, '|');
|
|
for (auto& str : strings) {
|
|
std::vector<std::string> strings2;
|
|
a8::Split(str, strings2, ':');
|
|
assert(strings2.size() == 2);
|
|
rand_space += a8::XValue(strings2[1]).GetInt();
|
|
template_list.push_back(std::make_tuple(
|
|
strings2[0],
|
|
rand_space
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
std::string Map::RandTemplate()
|
|
{
|
|
if (rand_space <= 0) {
|
|
return "";
|
|
}
|
|
int rnd = rand() % rand_space;
|
|
for (auto& tpl : template_list) {
|
|
if (rnd <= std::get<1>(tpl)) {
|
|
return std::get<0>(tpl);
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
void Equip::Init()
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(i->bullet_born_offset(), strings, '|');
|
|
for (auto& str : strings) {
|
|
std::vector<std::string> strings2;
|
|
a8::Split(str, strings2, ':');
|
|
assert(strings2.size() == 2);
|
|
bullet_born_offset.push_back(std::make_tuple(
|
|
a8::XValue(strings2[0]).GetDouble(),
|
|
a8::XValue(strings2[1]).GetDouble()
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
void Drop::Init()
|
|
{
|
|
std::vector<std::string> item_list;
|
|
{
|
|
a8::Split(i->item_id(), item_list, '|');
|
|
}
|
|
std::vector<std::string> num_list;
|
|
{
|
|
a8::Split(i->num(), num_list, '|');
|
|
}
|
|
std::vector<std::string> weight_list;
|
|
{
|
|
a8::Split(i->weight(), weight_list, '|');
|
|
}
|
|
assert(item_list.size() == num_list.size() &&
|
|
item_list.size() == weight_list.size());
|
|
total_weight = 0;
|
|
for (size_t i = 0; i < item_list.size(); ++i) {
|
|
total_weight += a8::XValue(weight_list[i]).GetInt();
|
|
std::vector<int> itemids;
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(item_list[i], strings, ':');
|
|
for (auto& str : strings) {
|
|
itemids.push_back(a8::XValue(str).GetInt());
|
|
}
|
|
}
|
|
std::vector<int> nums;
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(num_list[i], strings, ':');
|
|
for (auto& str : strings) {
|
|
nums.push_back(a8::XValue(str).GetInt());
|
|
}
|
|
}
|
|
assert(itemids.size() == nums.size());
|
|
if (this->i->type() == 1) {
|
|
auto item_tuple = std::make_tuple(
|
|
itemids,
|
|
nums,
|
|
a8::XValue(weight_list[i]).GetInt()
|
|
);
|
|
items.push_back(item_tuple);
|
|
} else {
|
|
auto item_tuple = std::make_tuple(
|
|
itemids,
|
|
nums,
|
|
total_weight
|
|
);
|
|
items.push_back(item_tuple);
|
|
}
|
|
}
|
|
assert(i->type() == 1 || i->type() == 2);
|
|
}
|
|
|
|
void Drop::RandItems(std::vector<std::tuple<int, int>>& drop_items)
|
|
{
|
|
if (i->type() == 1) {
|
|
for (auto& item : items) {
|
|
if ((rand() % 10000) <= std::get<2>(item)) {
|
|
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
|
|
drop_items.push_back(std::make_tuple(
|
|
std::get<0>(item)[i],
|
|
std::get<1>(item)[i]
|
|
));
|
|
}
|
|
}
|
|
}
|
|
} else if (total_weight > 0) {
|
|
int rnd = rand() % total_weight;
|
|
for (auto& item : items) {
|
|
if (std::get<2>(item) >= rnd) {
|
|
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
|
|
drop_items.push_back(std::make_tuple(
|
|
std::get<0>(item)[i],
|
|
std::get<1>(item)[i]
|
|
));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Building::Init()
|
|
{
|
|
for (auto& door_meta : i->doorobj()) {
|
|
Door* p_door = nullptr;
|
|
for (auto& door : doors) {
|
|
if (door.door_id == door_meta.id()) {
|
|
p_door = &door;
|
|
break;
|
|
}
|
|
}
|
|
if (!p_door) {
|
|
p_door = &a8::FastAppend(doors);
|
|
p_door->door_id = door_meta.id();
|
|
}
|
|
switch (door_meta.type()) {
|
|
case 1:
|
|
{
|
|
p_door->state0 = &door_meta;
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
p_door->state1 = &door_meta;
|
|
}
|
|
break;
|
|
}
|
|
}//end for
|
|
|
|
for (auto& door : doors) {
|
|
if (door.door_id == 0 ||
|
|
!door.state0 || !door.state1) {
|
|
abort();
|
|
} else {
|
|
#if 0
|
|
if (door.state1->x() < door.state0.x()) {
|
|
if (door.state1.y() < door.state0.y()) {
|
|
|
|
} else {
|
|
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
void MapTplThing::Init()
|
|
{
|
|
rand_space = 0;
|
|
std::vector<std::string> strings;
|
|
a8::Split(i->things(), strings, '\n');
|
|
for (auto& str : strings) {
|
|
std::vector<std::string> strings2;
|
|
a8::Split(str, strings2, ':');
|
|
assert(strings2.size() == 2);
|
|
rand_space += a8::XValue(strings2[1]).GetInt();
|
|
things.push_back(std::make_tuple(
|
|
a8::XValue(strings2[0]),
|
|
rand_space
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
int MapTplThing::RandThing()
|
|
{
|
|
if (rand_space <= 0) {
|
|
return 0;
|
|
}
|
|
int rnd = rand() % rand_space;
|
|
for (auto& tuple : things) {
|
|
if (std::get<1>(tuple) > rnd) {
|
|
return std::get<0>(tuple);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void AirLine::Init()
|
|
{
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(i->start_point(), strings, ':');
|
|
start_point_x = a8::XValue(strings[0]).GetDouble();
|
|
start_point_y = a8::XValue(strings[1]).GetDouble();
|
|
}
|
|
{
|
|
std::vector<std::string> strings;
|
|
a8::Split(i->end_point(), strings, ':');
|
|
end_point_x = a8::XValue(strings[0]).GetDouble();
|
|
end_point_y = a8::XValue(strings[1]).GetDouble();
|
|
}
|
|
}
|
|
|
|
}
|