From a2357eab14b19e70a90d308a4e2c44e6ae5062fe Mon Sep 17 00:00:00 2001 From: Ryan Babij Date: Thu, 12 Jul 2018 00:13:06 +1000 Subject: [PATCH] 0.0.006 -> 0.0.007 Add Tribe_Elf. Elven tribes can now spawn into the game. Add Elf Tribe texture. Fix some Tribe spawning rules. Tribes are now less likely to be unable to spawn. Minor dependency cleanup. --- CompileCount.hpp | 2 +- Driver_LoadTextures.hpp | 5 ++ Driver_Settings.cpp | 12 +-- Tribe.cpp | 2 +- Tribe_Dwarven.cpp | 15 ++-- Tribe_Elf.cpp | 161 ++++++++++++++++++++++++++++++++++++++++ Tribe_Elf.hpp | 41 ++++++++++ Tribe_Human.cpp | 6 +- World.cpp | 30 +++++++- World.hpp | 12 ++- 10 files changed, 261 insertions(+), 25 deletions(-) create mode 100644 Tribe_Elf.cpp create mode 100644 Tribe_Elf.hpp diff --git a/CompileCount.hpp b/CompileCount.hpp index f29138d..da17a32 100644 --- a/CompileCount.hpp +++ b/CompileCount.hpp @@ -9,5 +9,5 @@ */ #include - const std::string COMPILE_COUNT = "4199"; + const std::string COMPILE_COUNT = "4222"; #endif diff --git a/Driver_LoadTextures.hpp b/Driver_LoadTextures.hpp index a627a94..1f003c6 100644 --- a/Driver_LoadTextures.hpp +++ b/Driver_LoadTextures.hpp @@ -41,6 +41,9 @@ const std::string PATH_TEX_WORLD_UNIT_NOMAD_01 = "Textures/World/Unit/Nomad/00.p Texture TEX_WORLD_UNIT_DWARF_01; const std::string PATH_TEX_WORLD_UNIT_DWARF_01 = "Textures/World/Unit/Dwarf/00.png"; +Texture TEX_WORLD_UNIT_ELF_01; +const std::string PATH_TEX_WORLD_UNIT_ELF_01 = "Textures/World/Unit/Elf/00.png"; + Texture TEX_WORLD_SETTLEMENT_DWARFFORT_01; const std::string PATH_TEX_WORLD_SETTLEMENT_DWARFFORT_01 = "Textures/World/Settlement/DwarfFort/01.png"; @@ -135,6 +138,8 @@ void loadTextures() // LOAD WORLD OBJECT TEXTURES loadTextureVerbose(PATH_TEX_WORLD_UNIT_NOMAD_01,&TEX_WORLD_UNIT_NOMAD_01); loadTextureVerbose(PATH_TEX_WORLD_UNIT_DWARF_01,&TEX_WORLD_UNIT_DWARF_01); + loadTextureVerbose(PATH_TEX_WORLD_UNIT_ELF_01,&TEX_WORLD_UNIT_ELF_01); + loadTextureVerbose(PATH_TEX_WORLD_SETTLEMENT_DWARFFORT_01,&TEX_WORLD_SETTLEMENT_DWARFFORT_01); loadTextureVerbose(PATH_TEX_WORLD_SETTLEMENT_TOWN_URBAN01,&TEX_WORLD_SETTLEMENT_TOWN_URBAN01); diff --git a/Driver_Settings.cpp b/Driver_Settings.cpp index d338dc9..89bb55e 100644 --- a/Driver_Settings.cpp +++ b/Driver_Settings.cpp @@ -26,9 +26,9 @@ volatile const std::string devmessage = "HEY THIS IS GARO WADDUP."; /* DEBUG MENU SHORTCUTS */ //bool AUTO_GENERATE_WORLD = false; //bool AUTO_NEW_SIMULATION = true; -bool QUICKSTART = true; // Skip menu stuff and jump right into the game. (Will use defaults). +bool QUICKSTART = false; // Skip menu stuff and jump right into the game. (Will use defaults). //Quickly go straight into the simulator. -bool QUICKSTART_SIMULATOR = true; // Skip menu stuff and jump right into the game. (Will use defaults). +bool QUICKSTART_SIMULATOR = false; // Skip menu stuff and jump right into the game. (Will use defaults). // DEFAULT WORLD WHICH IS AUTO-GENERATED. int QUICKSTART_WORLD_SIZE = 129; /* Please set to (power of 2)+1. */ @@ -36,11 +36,11 @@ int QUICKSTART_WORLD_SIZE = 129; /* Please set to (power of 2)+1. */ long long int INITIAL_YEARS_SIMULATE = 0; // Default setting on the GUI -int DEFAULT_WORLD_SIZE_SLOT = 1; /* 0 = 129, 1 = 257, 513, 1025, 2049, 4097. You can set it lower for easier debugging. */ +int DEFAULT_WORLD_SIZE_SLOT = 2; /* 0 = 129, 1 = 257, 513, 1025, 2049, 4097. You can set it lower for easier debugging. */ -int DEFAULT_NUMBER_TRIBES_DWARVEN = 10; -int DEFAULT_NUMBER_TRIBES_HUMAN = 0; -int DEFAULT_NUMBER_TRIBES_ELVEN = 0; +int DEFAULT_NUMBER_TRIBES_DWARVEN = 12; +int DEFAULT_NUMBER_TRIBES_HUMAN = 12; +int DEFAULT_NUMBER_TRIBES_ELVEN = 12; int DEFAULT_NUMBER_CIVS = 0; bool FOG_OF_WAR = true; diff --git a/Tribe.cpp b/Tribe.cpp index 1c8fbfc..ca18724 100644 --- a/Tribe.cpp +++ b/Tribe.cpp @@ -601,7 +601,7 @@ bool Tribe::spawn() worldX=spawnTile->x; worldY=spawnTile->y; - world->putObject(this); + world->putObject(this,worldX, worldY); world->vTribe.push(this); return true; diff --git a/Tribe_Dwarven.cpp b/Tribe_Dwarven.cpp index 341a0ff..71bb52b 100644 --- a/Tribe_Dwarven.cpp +++ b/Tribe_Dwarven.cpp @@ -31,15 +31,18 @@ bool Tribe_Dwarven::spawn() { if ( world == 0 ) + { return false; } + + HasXY* spawnTile = world->getRandomTileOfType(World::MOUNTAIN); + + if ( spawnTile == 0 ) { - return false; + spawnTile = world->getRandomTileOfType(World::GRASSLAND); } - - HasXY* spawnTile = world->getRandomTileOfType(World::MOUNTAIN); - + if ( spawnTile == 0 ) { - std::cout<<"ABORT: Couldn't find mountain tile.\n"; + std::cout<<"ABORT: Dwarf couldn't find tile to spawn into.\n"; return false; } @@ -49,7 +52,7 @@ bool Tribe_Dwarven::spawn() worldX=spawnTile->x; worldY=spawnTile->y; - world->putObject(this); + world->putObject(this,worldX,worldY); world->vTribe.push(this); return true; diff --git a/Tribe_Elf.cpp b/Tribe_Elf.cpp new file mode 100644 index 0000000..ba685c7 --- /dev/null +++ b/Tribe_Elf.cpp @@ -0,0 +1,161 @@ +#pragma once +#ifndef WORLDSIM_TRIBE_ELF_CPP +#define WORLDSIM_TRIBE_ELF_CPP + +/* WorldSim: Tribe_Elf.hpp + #include "Tribe_Elf.hpp" + + Description: + Tribes are nomadic groups. They wander the map trying to survive until they develop enough to become a civilization. Elven tribes live in forests and jungles. They know a lot about the magic arts. + +*/ + +#include "Tribe_Elf.hpp" + +#include "Character.hpp" + +class World; + +#include "GuildCalendar.hpp" +#include "WorldObjectGlobal.hpp" + +#include + +Tribe_Elf::Tribe_Elf() +{ + race = ELVEN; +} + + +bool Tribe_Elf::spawn() +{ + + if ( world == 0 ) + { + return false; + } + + HasXY* spawnTile = 0; + if (Random::oneIn(3) ) + { + spawnTile = world->getRandomTileOfType(World::FOREST); + } + else + { + spawnTile = world->getRandomTileOfType(World::JUNGLE); + } + if ( spawnTile == 0 ) + { + spawnTile = world->getRandomTileOfType(World::GRASSLAND); + } + + if ( spawnTile == 0 ) + { + std::cout<<"ABORT: Elf couldn't find tile to spawn into.\n"; + return false; + } + + name = globalNameGen.generateName(); + nFood = 10; + + worldX=spawnTile->x; + worldY=spawnTile->y; + + world->putObject(this,worldX,worldY); + world->vTribe.push(this); + + return true; + +} + + /* SIMULATE X TURNS OF THE CIV. */ +void Tribe_Elf::incrementTicks ( int nTicks ) +{ + actionPoints+=nTicks; + dailyCounter+=nTicks; + monthlyCounter+=nTicks; + + while (monthlyCounter >= 2592000) + { + for ( int i=0;i<30;++i) + { + + + if ( foundSettlement == false ) + { + if ( world->getTileType(worldX,worldY) == "forest" && random.oneIn(10) ) + { + //foundSettlement = true; + //world->evolveToCiv(this); + break; + } + else + { + wander(); + } + } + + + } + + monthlyCounter-=2592000; + } + + while ( dailyCounter >= 86400 ) + { + if ( foundSettlement == false ) + { + if ( world->getTileType(worldX,worldY) == "forest" && random.oneIn(10) ) + { + //foundSettlement = true; + //world->evolveToCiv(this); + break; + } + else + { + wander(); + } + } + dailyCounter-=86400; + } + + +} + +void Tribe_Elf::wander() +{ + if (world==0 || foundSettlement) { return; } + + int destinationX = worldX + random.randomIntRange(-1,1); + int destinationY = worldY + random.randomIntRange(-1,1); + + // Moving options: + // Move to food + // Move to unexplored territory + + //aTerrain.getNeighborVector(_x,_y,&vTerrain,false /* DON'T INCLUDE SELF */); + //Vector * vXY = world->aTerrain.getNeighbors(worldX, worldY, false); + //vXY->shuffle(); + + //HasXY* xyDestination = 0; + + /* If all else fails, move randomly. */ + if (world->isSafe(destinationX,destinationY) && world->isLand(destinationX,destinationY)) + { + // MOVE THE TRIBE TO THE LOCATION. + worldX=destinationX; + worldY=destinationY; + } +} + + +Texture* Tribe_Elf::currentTexture() +{ + if (foundSettlement) + { + return &TEX_WORLD_SETTLEMENT_DWARFFORT_01; + } + return &TEX_WORLD_UNIT_ELF_01; +} + +#endif \ No newline at end of file diff --git a/Tribe_Elf.hpp b/Tribe_Elf.hpp new file mode 100644 index 0000000..f58a9c7 --- /dev/null +++ b/Tribe_Elf.hpp @@ -0,0 +1,41 @@ +#pragma once +#ifndef WORLDSIM_TRIBE_ELF_HPP +#define WORLDSIM_TRIBE_ELF_HPP + +/* WorldSim: Tribe_Elf.hpp + #include "Tribe_Elf.hpp" + + Description: + Tribes are nomadic groups. They wander the map trying to survive until they develop enough to become a civilization. Elven tribes live in forests and jungles. They know a lot about the magic arts. + +*/ + +#include "Character.hpp" + +class World; + +#include "GuildCalendar.hpp" +#include "WorldObjectGlobal.hpp" + +#include + + +class Tribe_Elf: public Tribe +{ + public: + + //RandomNonStatic random; + + Tribe_Elf(); + + bool spawn(); + + /* SIMULATE X TURNS OF THE CIV. */ + void incrementTicks ( int /* nTicks */ ); + + void wander(); + + Texture* currentTexture(); +}; + +#endif \ No newline at end of file diff --git a/Tribe_Human.cpp b/Tribe_Human.cpp index be3fdf8..de1780a 100644 --- a/Tribe_Human.cpp +++ b/Tribe_Human.cpp @@ -32,11 +32,11 @@ bool Tribe_Human::spawn() return false; } - HasXY* spawnTile = world->getRandomTileOfType(World::MOUNTAIN); + HasXY* spawnTile = world->getRandomTileOfType(World::GRASSLAND); if ( spawnTile == 0 ) { - std::cout<<"ABORT: Couldn't find mountain tile.\n"; + std::cout<<"ABORT: Human couldn't find tile to spawn into.\n"; return false; } @@ -46,7 +46,7 @@ bool Tribe_Human::spawn() worldX=spawnTile->x; worldY=spawnTile->y; - world->putObject(this); + world->putObject(this,worldX,worldY); world->vTribe.push(this); return true; diff --git a/World.cpp b/World.cpp index 4040034..b8d1524 100644 --- a/World.cpp +++ b/World.cpp @@ -19,8 +19,15 @@ #include "Civ.cpp" #include "Civ_Dwarven.cpp" +#include "Tribe.cpp" +#include "Tribe_Human.cpp" +#include "Tribe_Dwarven.cpp" +#include "Tribe_Elf.cpp" + #include "Settlement.cpp" +#include "WorldObjectGlobal.hpp" + World::World(): seaLevel(0), mountainLevel(0) { // aHeightMap.init(1,1,0); @@ -183,10 +190,17 @@ void World::generateTribes( int nTribesHuman = DEFAULT_NUMBER_TRIBES_HUMAN, int { std::cout<<"Generate tribes\n"; - if (nTribesHuman < 1 || nTribesHuman > 999) - { - std::cout<<"WARNING: Excessive tribes.\n"; - } + if (nTribesHuman < 0 ) { nTribesHuman = 0; } + if (nTribesDwarven < 0 ) { nTribesDwarven = 0; } + if (nTribesElven < 0 ) { nTribesElven = 0; } + + if (nTribesHuman < 0 || nTribesHuman > 999) + { std::cout<<"WARNING: Unexpected number of human tribes.\n"; } + if (nTribesDwarven < 0 || nTribesDwarven > 999) + { std::cout<<"WARNING: Unexpected number of human tribes.\n"; } + if (nTribesElven < 0 || nTribesElven > 999) + { std::cout<<"WARNING: Unexpected number of human tribes.\n"; } + for (int i=0;ispawn(); t->generateCouples(7); } + + for (int i=0;iinit(this); + t->spawn(); + t->generateCouples(7); + } std::cout<<"END Generate tribes\n"; diff --git a/World.hpp b/World.hpp index a6ab2e8..6d13b9f 100644 --- a/World.hpp +++ b/World.hpp @@ -25,10 +25,11 @@ NameGen globalNameGen; #include #include