Switch to CTable class.

This commit is contained in:
lzwdgc 2015-07-12 16:04:53 +03:00
parent e93b472416
commit f0388c4b33
6 changed files with 82 additions and 61 deletions

View file

@ -21,8 +21,11 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")
endif(MSVC) endif(MSVC)
include_directories(../DatabaseManager/include) if (NOT DATABASE_MANAGER_DIR)
add_subdirectory(../DatabaseManager DatabaseManager) message(FATAL_ERROR "Please, set DATABASE_MANAGER_DIR variable")
endif()
add_subdirectory(${DATABASE_MANAGER_DIR} DatabaseManager)
include_directories(${DATABASE_MANAGER_DIR}/include)
set_target_properties(sqlite3 PROPERTIES FOLDER Extern) set_target_properties(sqlite3 PROPERTIES FOLDER Extern)
set_target_properties(DatabaseManager PROPERTIES FOLDER Extern) set_target_properties(DatabaseManager PROPERTIES FOLDER Extern)

View file

@ -1,2 +1,3 @@
file(GLOB common_src "*.h" "*.cpp") file(GLOB common_src "*.h" "*.cpp")
add_library(common ${common_src}) add_library(common ${common_src})
add_dependencies(common version)

View file

@ -7,7 +7,11 @@ import subprocess
banned_ext = [ banned_ext = [
'.obj', '.obj',
'.txt' '.mtl',
'.txt',
'.tm',
'.TM',
'.tga',
] ]
def main(): def main():
@ -22,7 +26,7 @@ def run(dir):
for file in sorted(os.listdir(dir)): for file in sorted(os.listdir(dir)):
if os.path.isdir(file) or os.path.splitext(file)[1] in banned_ext: if os.path.isdir(file) or os.path.splitext(file)[1] in banned_ext:
continue continue
p = subprocess.Popen(['mod_converter.exe', dir + '/' + file]) p = subprocess.Popen(['mod_converter.exe', '-m', dir + '/' + file])
p.communicate() p.communicate()
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -24,6 +24,9 @@
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#define _USE_MATH_DEFINES
#include <math.h>
#include "objects.h" #include "objects.h"
#include "other.h" #include "other.h"
@ -31,6 +34,8 @@
#include <common.h> #include <common.h>
#define RAD2GRAD(x) (x) = (x) / M_PI * 100.0
using namespace std; using namespace std;
std::string prefix; std::string prefix;
@ -40,10 +45,10 @@ struct storage
{ {
string name; string name;
Objects objects; Objects objects;
MechGroups mgs; MechGroups mechGroups;
MapGoods mg; MapGoods mapGoods;
MapMusic mm; MapMusic mapMusic;
MapSounds ms; MapSounds mapSounds;
// aim2 // aim2
Organizations orgs; Organizations orgs;
OrganizationBases orgsBases; OrganizationBases orgsBases;
@ -52,12 +57,12 @@ struct storage
void load(buffer &b) void load(buffer &b)
{ {
objects.load(b); objects.load(b);
mgs.load(b); mechGroups.load(b);
if (b.eof()) // custom maps if (b.eof()) // custom maps
return; return;
mg.load(b); mapGoods.load(b);
mm.load(b); mapMusic.load(b);
ms.load(b); mapSounds.load(b);
if (gameType == GameType::Aim2) if (gameType == GameType::Aim2)
{ {
orgs.load(b); orgs.load(b);
@ -144,7 +149,7 @@ void write_mmo(string db, const storage &s)
bld_ids[o] = bld->getId(); bld_ids[o] = bld->getId();
} }
else else
bld_ids[o] = iter->second->getId(); bld_ids[o] = iter->getId();
} }
for (auto &object : segment->objects) for (auto &object : segment->objects)
{ {
@ -155,9 +160,13 @@ void write_mmo(string db, const storage &s)
mb.x = object.position.x; mb.x = object.position.x;
mb.y = object.position.y; mb.y = object.position.y;
mb.z = object.position.z; mb.z = object.position.z;
mb.yaw = atan2(object.m_rotate_z[1].x, object.m_rotate_z[0].x);
mb.pitch = atan2(-object.m_rotate_z[2].x, sqrt(object.m_rotate_z[2].y * object.m_rotate_z[2].y + object.m_rotate_z[2].z * object.m_rotate_z[2].z));
mb.roll = atan2(object.m_rotate_z[2].y, object.m_rotate_z[2].z); mb.roll = atan2(object.m_rotate_z[2].y, object.m_rotate_z[2].z);
mb.pitch = atan2(-object.m_rotate_z[2].x, sqrt(object.m_rotate_z[2].y * object.m_rotate_z[2].y + object.m_rotate_z[2].z * object.m_rotate_z[2].z));
mb.yaw = atan2(object.m_rotate_z[1].x, object.m_rotate_z[0].x);
// to grad
RAD2GRAD(mb.roll);
RAD2GRAD(mb.pitch);
RAD2GRAD(mb.yaw);
auto i = find_if(storage->mapBuildings.begin(), storage->mapBuildings.end(), [&](const decltype(Storage::mapBuildings)::value_type &p) auto i = find_if(storage->mapBuildings.begin(), storage->mapBuildings.end(), [&](const decltype(Storage::mapBuildings)::value_type &p)
{ {
return *p.second.get() == mb; return *p.second.get() == mb;
@ -192,7 +201,7 @@ void write_mmo(string db, const storage &s)
bld_ids[o] = bld->getId(); bld_ids[o] = bld->getId();
} }
else else
bld_ids[o] = iter->second->getId(); bld_ids[o] = iter->getId();
} }
for (auto &object : segment->objects) for (auto &object : segment->objects)
{ {
@ -203,9 +212,13 @@ void write_mmo(string db, const storage &s)
mb.x = object.position.x; mb.x = object.position.x;
mb.y = object.position.y; mb.y = object.position.y;
mb.z = object.position.z; mb.z = object.position.z;
mb.yaw = atan2(object.m_rotate_z[1].x, object.m_rotate_z[0].x);
mb.pitch = atan2(-object.m_rotate_z[2].x, sqrt(object.m_rotate_z[2].y * object.m_rotate_z[2].y + object.m_rotate_z[2].z * object.m_rotate_z[2].z));
mb.roll = atan2(object.m_rotate_z[2].y, object.m_rotate_z[2].z); mb.roll = atan2(object.m_rotate_z[2].y, object.m_rotate_z[2].z);
mb.pitch = atan2(-object.m_rotate_z[2].x, sqrt(object.m_rotate_z[2].y * object.m_rotate_z[2].y + object.m_rotate_z[2].z * object.m_rotate_z[2].z));
mb.yaw = atan2(object.m_rotate_z[1].x, object.m_rotate_z[0].x);
// to grad
RAD2GRAD(mb.roll);
RAD2GRAD(mb.pitch);
RAD2GRAD(mb.yaw);
auto i = find_if(storage->mapObjects.begin(), storage->mapObjects.end(), [&](const decltype(Storage::mapObjects)::value_type &p) auto i = find_if(storage->mapObjects.begin(), storage->mapObjects.end(), [&](const decltype(Storage::mapObjects)::value_type &p)
{ {
return *p.second.get() == mb; return *p.second.get() == mb;
@ -227,7 +240,7 @@ try
{ {
if (argc != 4) if (argc != 4)
{ {
cout << "Usage:\n" << argv[0] << " db.sqlite file.mmo" << "\n"; cout << "Usage:\n" << argv[0] << " db.sqlite file.mmo prefix" << "\n";
return 1; return 1;
} }
prefix = argv[3]; prefix = argv[3];

View file

@ -66,8 +66,8 @@ enum class SegmentType : uint32_t
struct Segment struct Segment
{ {
SegmentType segment_type; SegmentType segment_type;
uint32_t segment_len; uint32_t segment_len = 0;
uint32_t n_objects; uint32_t n_objects = 0;
virtual ~Segment(){} virtual ~Segment(){}
static Segment *create_segment(buffer &b); static Segment *create_segment(buffer &b);
@ -92,10 +92,10 @@ struct SegmentObjects : public Segment
struct Vector4 struct Vector4
{ {
float x; float x = 0;
float y; float y = 0;
float z; float z = 0;
float w; float w = 0;
}; };
struct Common struct Common
@ -126,7 +126,7 @@ struct MapObject : public Common
struct MapObjectWithArray : public MapObject struct MapObjectWithArray : public MapObject
{ {
uint32_t len; uint32_t len = 0;
vector<uint32_t> unk7; vector<uint32_t> unk7;
void load(buffer &b) void load(buffer &b)
@ -179,7 +179,7 @@ UNKNOWN_OBJECT(unk1);
struct Objects struct Objects
{ {
uint32_t n_segments; uint32_t n_segments = 0;
vector<Segment *> segments; vector<Segment *> segments;
void load(buffer &b); void load(buffer &b);

View file

@ -40,19 +40,19 @@ struct MechGroup
{ {
char name[0x20]; char name[0x20];
char org[0x20]; char org[0x20];
uint32_t type1; uint32_t type1 = 0;
uint32_t len1; uint32_t len1 = 0;
char name1[0x70]; char name1[0x70];
//{3,4 //{3,4
uint32_t unk30; uint32_t unk30 = 0;
//} //}
//{2 //{2
uint32_t len; uint32_t len = 0;
vector<uint32_t> unk11; vector<uint32_t> unk11;
//} //}
//{1,0 //{1,0
uint32_t unk20; uint32_t unk20 = 0;
uint32_t unk21; uint32_t unk21 = 0;
//} //}
vector<string> configs; vector<string> configs;
char unk100; char unk100;
@ -91,8 +91,8 @@ struct MechGroup
struct MechGroups struct MechGroups
{ {
uint32_t length; uint32_t length = 0;
uint32_t n; uint32_t n = 0;
char prefix[0x30]; char prefix[0x30];
vector<MechGroup> mgs; vector<MechGroup> mgs;
@ -117,8 +117,8 @@ struct Good
{ {
char name[0x20]; char name[0x20];
char unk1[0x40]; char unk1[0x40];
uint32_t unk1_2; uint32_t unk1_2 = 0;
float price; float price = 0;
float unk2[10]; float unk2[10];
float unk2_2[4]; float unk2_2[4];
@ -140,7 +140,7 @@ struct Good
struct BuildingGoods struct BuildingGoods
{ {
char name[0x20]; char name[0x20];
uint32_t n; uint32_t n = 0;
vector<Good> goods; vector<Good> goods;
@ -160,10 +160,10 @@ struct BuildingGoods
struct MapGoods struct MapGoods
{ {
uint32_t length; uint32_t length = 0;
uint32_t unk2; uint32_t unk2 = 0;
uint32_t unk3; uint32_t unk3 = 0;
uint32_t n; uint32_t n = 0;
vector<BuildingGoods> bgs; vector<BuildingGoods> bgs;
@ -188,14 +188,14 @@ struct MapGoods
struct MapMusic struct MapMusic
{ {
uint32_t unk1; uint32_t unk1 = 0;
char name1[0x20]; char name1[0x20];
char name2[0x20]; char name2[0x20];
uint32_t n1; uint32_t n1 = 0;
vector<string> names1; vector<string> names1;
uint32_t n2; uint32_t n2 = 0;
vector<string> names2; vector<string> names2;
void load(buffer &b) void load(buffer &b)
@ -226,7 +226,7 @@ struct MapSound
{ {
char name[0x20]; char name[0x20];
float unk1[4]; float unk1[4];
uint32_t unk2; uint32_t unk2 = 0;
float unk3[4]; float unk3[4];
void load(buffer &b) void load(buffer &b)
@ -240,7 +240,7 @@ struct MapSound
struct MapSounds struct MapSounds
{ {
uint32_t n; uint32_t n = 0;
vector<MapSound> sounds; vector<MapSound> sounds;
void load(buffer &b) void load(buffer &b)
@ -257,7 +257,7 @@ struct MapSounds
struct OrganizationConfig struct OrganizationConfig
{ {
uint32_t n_configs; uint32_t n_configs = 0;
vector<string> configs; vector<string> configs;
void load(buffer &b) void load(buffer &b)
@ -271,7 +271,7 @@ struct OrganizationConfig
struct Organization struct Organization
{ {
uint32_t unk0; uint32_t unk0 = 0;
char name[0x20]; char name[0x20];
char unk1[0xE0]; char unk1[0xE0];
OrganizationConfig configs[3]; OrganizationConfig configs[3];
@ -288,8 +288,8 @@ struct Organization
struct Organizations struct Organizations
{ {
uint32_t len; uint32_t len = 0;
uint32_t n; uint32_t n = 0;
vector<Organization> organizations; vector<Organization> organizations;
void load(buffer &b) void load(buffer &b)
@ -309,7 +309,7 @@ struct OrganizationBase
{ {
char base_name[0x20]; char base_name[0x20];
char org_name[0x20]; char org_name[0x20];
uint32_t unk0; uint32_t unk0 = 0;
void load(buffer &b) void load(buffer &b)
{ {
@ -321,7 +321,7 @@ struct OrganizationBase
struct OrganizationBases struct OrganizationBases
{ {
uint32_t n; uint32_t n = 0;
vector<OrganizationBase> organizationBases; vector<OrganizationBase> organizationBases;
void load(buffer &b) void load(buffer &b)
@ -339,8 +339,8 @@ struct OrganizationBases
struct Price struct Price
{ {
char tov_name[0x20]; char tov_name[0x20];
uint32_t unk0; uint32_t unk0 = 0;
uint32_t unk1; uint32_t unk1 = 0;
float unk2[3]; float unk2[3];
void load(buffer &b) void load(buffer &b)
@ -355,7 +355,7 @@ struct Price
struct BuildingPrice struct BuildingPrice
{ {
char name[0x20]; char name[0x20];
uint32_t n_tov; uint32_t n_tov = 0;
vector<Price> prices; vector<Price> prices;
void load(buffer &b) void load(buffer &b)
@ -373,9 +373,9 @@ struct BuildingPrice
struct BuildingPrices struct BuildingPrices
{ {
uint32_t n_tov; uint32_t n_tov = 0;
vector<Price> prices; vector<Price> prices;
uint32_t n_bases; uint32_t n_bases = 0;
vector<BuildingPrice> buildingPrices; vector<BuildingPrice> buildingPrices;
void load(buffer &b) void load(buffer &b)
@ -399,8 +399,8 @@ struct BuildingPrices
struct Prices struct Prices
{ {
uint32_t len; uint32_t len = 0;
uint32_t unk0; uint32_t unk0 = 0;
BuildingPrices buildingPrices; BuildingPrices buildingPrices;
void load(buffer &b) void load(buffer &b)