New ttrts-gen target to generate game files
This commit is contained in:
parent
a75e6e290d
commit
870f459f75
5 changed files with 67 additions and 1 deletions
|
@ -16,5 +16,8 @@ endif()
|
|||
# Subprojects
|
||||
add_subdirectory( ttrts )
|
||||
add_subdirectory( game )
|
||||
add_subdirectory( test )
|
||||
add_subdirectory( ui )
|
||||
|
||||
# Auxhilary binaries
|
||||
add_subdirectory( test )
|
||||
add_subdirectory( gen )
|
||||
|
|
|
@ -92,6 +92,7 @@ public:
|
|||
// Set the game name
|
||||
// NOTE: Names with spaces not allowed
|
||||
inline std::string SetName( const std::string& in ) { return (name = in); }
|
||||
inline std::string GetName() const { return name; }
|
||||
|
||||
// Set the turn of the game
|
||||
inline int SetTurn( int in ) { return (turn = in); }
|
||||
|
|
17
gen/CMakeLists.txt
Normal file
17
gen/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
# ====================== gen =======================
|
||||
# Project name
|
||||
project( ttrts-gen )
|
||||
|
||||
include_directories(
|
||||
../game
|
||||
../maths
|
||||
)
|
||||
|
||||
set( SOURCES
|
||||
gen.cpp
|
||||
)
|
||||
|
||||
# Add the executable
|
||||
add_executable( ttrts-gen ${SOURCES} )
|
||||
|
||||
target_link_libraries( ttrts-gen game )
|
44
gen/gen.cpp
Normal file
44
gen/gen.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "game.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
void AddUnitToGame( player_id_t player, Team team, char vis, uvector2 vec, CTTRTSGame& game )
|
||||
{
|
||||
CUnit unit = CUnit::GetUnitFromVis(vis);
|
||||
unit.setPos( vec );
|
||||
unit.setPlayer(player);
|
||||
unit.setTeam(team);
|
||||
game.AddUnit(std::move(unit));
|
||||
}
|
||||
|
||||
void OutputGame( CTTRTSGame& game )
|
||||
{
|
||||
std::ofstream output;
|
||||
output.open (game.GetName() + ".txt");
|
||||
output << game.GetStateAsString();
|
||||
output.close();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Basic 5v5 game
|
||||
{
|
||||
CTTRTSGame game(21, 11);
|
||||
game.SetName("Basic_5_v_5");
|
||||
|
||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 1), game);
|
||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 3), game);
|
||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 5), game);
|
||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 7), game);
|
||||
AddUnitToGame(0, Team::Blue, '>', uvector2(1, 9), game);
|
||||
|
||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 1), game);
|
||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 3), game);
|
||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 5), game);
|
||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 7), game);
|
||||
AddUnitToGame(1, Team::Red, '<', uvector2(19, 9), game);
|
||||
|
||||
OutputGame(game);
|
||||
}
|
||||
}
|
|
@ -136,6 +136,7 @@ const char* tests()
|
|||
// Test on a tiny board, whether a unit can correctly attack another
|
||||
{
|
||||
CTTRTSGame game( 2, 1 );
|
||||
game.SetName("Test_578");
|
||||
|
||||
unit_id_t id;
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue