From d2ed14fcabfad493e6dc1b9198f3b0a249f6894f Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 18 Dec 2021 20:37:50 +0100 Subject: [PATCH] Port 3 more tables. --- Mourne-CI/sql/db_13_04_23.sql | 3 ++ app/village/village_model.cpp | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/Mourne-CI/sql/db_13_04_23.sql b/Mourne-CI/sql/db_13_04_23.sql index 9a07db5..d409682 100644 --- a/Mourne-CI/sql/db_13_04_23.sql +++ b/Mourne-CI/sql/db_13_04_23.sql @@ -206,6 +206,7 @@ INSERT INTO `buildings` (`id`, `name`, `description`, `icon`, `rank`, `next_rank -- Table structure for table `building_assignments` -- +--done CREATE TABLE IF NOT EXISTS `building_assignments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `villageid` int(11) NOT NULL, @@ -227,6 +228,7 @@ CREATE TABLE IF NOT EXISTS `building_assignments` ( -- Table structure for table `building_spells` -- +--done CREATE TABLE IF NOT EXISTS `building_spells` ( `id` int(11) NOT NULL AUTO_INCREMENT, `villageid` int(11) NOT NULL, @@ -248,6 +250,7 @@ CREATE TABLE IF NOT EXISTS `building_spells` ( -- Table structure for table `building_spell_cooldowns` -- +--done CREATE TABLE IF NOT EXISTS `building_spell_cooldowns` ( `id` int(11) NOT NULL AUTO_INCREMENT, `villageid` int(11) NOT NULL, diff --git a/app/village/village_model.cpp b/app/village/village_model.cpp index 765edd6..701b6ce 100644 --- a/app/village/village_model.cpp +++ b/app/village/village_model.cpp @@ -13,6 +13,10 @@ #define VILLAGE_BUILDINGS_TABLE_NAME "village_buildings" #define VILLAGE_TECHNOLOGIES_TABLE_NAME "village_technologies" #define VILLAGE_UNITS_TABLE_NAME "village_units" +#define VILLAGE_BUILDING_ASSIGNMENTS_TABLE_NAME "village_building_assignments" +#define VILLAGE_BUILDING_SPELLS_TABLE_NAME "village_building_spells" +#define VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME "village_building_spell_cooldowns" + void VillageModel::create_table() { Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); @@ -134,10 +138,68 @@ void VillageModel::create_table() { //tb->print(); tb->result = ""; + + tb->create_table(VILLAGE_BUILDING_ASSIGNMENTS_TABLE_NAME); + tb->integer("id", 11)->auto_increment()->next_row(); + tb->integer("villageid", 11)->not_null()->next_row(); + tb->integer("slotid", 11)->not_null()->next_row(); + tb->integer("unitid", 11)->not_null()->next_row(); + + tb->integer("num_unit", 11)->not_null()->next_row(); + tb->integer("assignmentid", 11)->not_null()->next_row(); //foregign key + tb->integer("num_bonus", 11)->not_null()->next_row(); + + tb->primary_key("id"); + tb->foreign_key("villageid")->references(VILLAGE_TABLE_NAME, "id"); + tb->ccreate_table(); + + tb->run_query(); + //tb->print(); + + tb->result = ""; + + tb->create_table(VILLAGE_BUILDING_SPELLS_TABLE_NAME); + tb->integer("id", 11)->auto_increment()->next_row(); + tb->integer("villageid", 11)->not_null()->next_row(); + tb->integer("slotid", 11)->not_null()->next_row(); + tb->integer("assignmentid", 11)->not_null()->next_row(); //foregign key + tb->integer("spellid", 11)->not_null()->next_row();//foregign key + + tb->primary_key("id"); + tb->foreign_key("villageid")->references(VILLAGE_TABLE_NAME, "id"); + tb->ccreate_table(); + + tb->run_query(); + //tb->print(); + + tb->result = ""; + + tb->create_table(VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME); + tb->integer("id", 11)->auto_increment()->next_row(); + tb->integer("villageid", 11)->not_null()->next_row(); + tb->integer("slotid", 11)->not_null()->next_row(); + tb->integer("spellid", 11)->not_null()->next_row();//foregign key + tb->integer("cooldown_end", 11)->not_null()->next_row(); + + tb->primary_key("id"); + tb->foreign_key("villageid")->references(VILLAGE_TABLE_NAME, "id"); + tb->ccreate_table(); + + tb->run_query(); + //tb->print(); + + tb->result = ""; } + +#define VILLAGE_BUILDING_SPELLS_TABLE_NAME "village_building_spells" +#define VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME "village_building_spell_cooldowns" + void VillageModel::drop_table() { Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); + tb->drop_table_if_exists(VILLAGE_BUILDING_ASSIGNMENTS_TABLE_NAME)->cdrop_table(); + tb->drop_table_if_exists(VILLAGE_BUILDING_SPELLS_TABLE_NAME)->cdrop_table(); + tb->drop_table_if_exists(VILLAGE_BUILDING_SPELL_COOLDOWNS_TABLE_NAME)->cdrop_table(); tb->drop_table_if_exists(VILLAGE_UNITS_TABLE_NAME)->cdrop_table(); tb->drop_table_if_exists(VILLAGE_TECHNOLOGIES_TABLE_NAME)->cdrop_table(); tb->drop_table_if_exists(VILLAGE_BUILDINGS_TABLE_NAME)->cdrop_table();