Update with more install targets.
Installing headers and library to /usr/local/ Requires workaround for version information header generation Install a man page Install some basic bash completion for maps Also update the readme to fit with the manpage and new autocompletion features Fixes the oddity where generated map files were missing the initial line of the header
This commit is contained in:
parent
53e882ae12
commit
2273c93f11
8 changed files with 179 additions and 83 deletions
29
scripts/gen_manpage.sh
Executable file
29
scripts/gen_manpage.sh
Executable file
|
@ -0,0 +1,29 @@
|
||||||
|
#! /bin/bash
|
||||||
|
# Used to a man page from markdown
|
||||||
|
|
||||||
|
echo ".\" Man page for the ttrts project" > $1
|
||||||
|
echo ".\" this man page is auto-generated, do not edit directly" >> $1
|
||||||
|
|
||||||
|
echo ".TH TTRTS\ v0.3.0 6 $(date +%Y-%m-%d) http://mdiluz.github.io/ttrts/" >> $1
|
||||||
|
|
||||||
|
# sections to section headers
|
||||||
|
# sub-sections in man page sub-sections
|
||||||
|
# 4-space lines to tabs
|
||||||
|
# tab starts removed
|
||||||
|
# Environment variables in bold
|
||||||
|
# User variables in italics
|
||||||
|
# remove all line-widths
|
||||||
|
# Put all back-ticks quotes in bold
|
||||||
|
# underline mapfile opt
|
||||||
|
# ensure name section uses correct
|
||||||
|
cat "$2" \
|
||||||
|
| sed -r 's/^# (\w+)/.SH \1/g' \
|
||||||
|
| sed -r 's/^##+ (\w+)/.SS \1/g' \
|
||||||
|
| sed -r 's/^ (.*)$/\n\t\1\n/g' \
|
||||||
|
| sed -r 's/^\t//g' \
|
||||||
|
| sed -r 's/\$\{(\w+)\}/\\fB\$\1\\fR/g' \
|
||||||
|
| sed -r 's/\{(\w+)\}/\\fI\1\\fR/g' \
|
||||||
|
| sed -r 's/-----+//g' \
|
||||||
|
| sed -r 's/`(.*?)`/\\fB\1\\fR/g' \
|
||||||
|
| sed -r 's/MAPFILE/\\fImapfile\\fR/g' \
|
||||||
|
| sed -r 's/\tttrts -/\tttrts \\-/g' >> $1
|
13
scripts/gen_version_header.sh
Executable file
13
scripts/gen_version_header.sh
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
HEADER="// Auto generated ttrts version header
|
||||||
|
// do not edit manually
|
||||||
|
#ifndef _TTRTS_VERSION_H_
|
||||||
|
#define _TTRTS_VERSION_H_
|
||||||
|
|
||||||
|
#define TTRTS_VERSION_MAJOR $1
|
||||||
|
#define TTRTS_VERSION_MINOR $2
|
||||||
|
#define TTRTS_VERSION_PATCH $3
|
||||||
|
#define TTRTS_VERSION_STRING \"v$1.$2.$3\"
|
||||||
|
|
||||||
|
#endif //_TTRTS_VERSION_H_"
|
||||||
|
|
||||||
|
echo "$HEADER" > "version.h"
|
23
scripts/ttrts_complete
Executable file
23
scripts/ttrts_complete
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
# ttrts completion
|
||||||
|
|
||||||
|
test ! -z TTRTS_MAPS && TTRTS_MAPS=/usr/share/ttrts/maps/
|
||||||
|
|
||||||
|
have ttrts &&
|
||||||
|
function _ttrts
|
||||||
|
{
|
||||||
|
commandnames=""
|
||||||
|
for filename in ${TTRTS_MAPS}/*
|
||||||
|
do
|
||||||
|
map="${filename##*/}"
|
||||||
|
commandnames+="$map "
|
||||||
|
done
|
||||||
|
|
||||||
|
local cur prev
|
||||||
|
COMPREPLY=()
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
|
COMPREPLY=( $(compgen -W "${commandnames}" -- ${cur}) )
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _ttrts ttrts
|
|
@ -1,53 +1,78 @@
|
||||||
# ttrts - Tiny Terminal RTS
|
# NAME
|
||||||
|
ttrts - Tiny Terminal RTS
|
||||||
|
|
||||||
## SYNOPSIS
|
# SYNOPSIS
|
||||||
ttrts MAPFILE
|
ttrts MAPFILE
|
||||||
|
|
||||||
## DESCRIPTION
|
# DESCRIPTION
|
||||||
ttrts is a tiny terminal based RTS where that uses text
|
ttrts is a tiny terminal based RTS that uses text files as order lists to control the units
|
||||||
files as order lists to control it's units
|
|
||||||
|
|
||||||
This means that any user, program or cat that can read
|
This means that any user, program or cat that can read and write to text files can play the game
|
||||||
and write to text files can play the game
|
|
||||||
|
|
||||||
## OPTIONS
|
# RETURN VALUE
|
||||||
MAPFILE - File to read in the initial game state from
|
ttrts will return -1 on error, or the winning player on completion
|
||||||
|
|
||||||
## USAGE
|
# OPTIONS
|
||||||
When invoked, ttrts will set up the game in a local
|
MAPFILE - File to read in the initial game state. Local or in ${TTRTS_MAPS}
|
||||||
directory called `ttrts_{GAME_NAME}`
|
|
||||||
|
|
||||||
The GAMESTATE files in this directory can be read and
|
# USAGE
|
||||||
interpreted by human, robot or cat.
|
When invoked, ttrts will set up the game in a directory within ${TTRTS_GAMES} by the name of the map
|
||||||
|
|
||||||
ttrts will then await ORDER files from each participant
|
The files in this directory can be read and interpreted by human, robot or cat
|
||||||
|
|
||||||
Once all ORDER files have been received ttrts will
|
ttrts will then await order files from each participant
|
||||||
calculate the turn and output a new GAMESTATE file
|
|
||||||
|
Once all order files have been received ttrts will calculate the turn and output a new gamestate file
|
||||||
|
|
||||||
This process repeats until the game is over
|
This process repeats until the game is over
|
||||||
|
|
||||||
|
# ENVIRONMENT
|
||||||
|
${TTRTS_MAPS} - Map file lookup location, defaults to `/usr/share/ttrts/maps/`
|
||||||
|
|
||||||
|
${TTRTS_GAMES} - Game directory for I/O, defaults to `/tmp/`
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
# TTRTS GAMEPLAY
|
# FILES
|
||||||
|
`/usr/share/ttrts/maps/` holds a sample set of maps
|
||||||
|
|
||||||
## RULES
|
## Gamestate File
|
||||||
The game takes place in a series of simultaneous turns
|
Turn_{TURNNUMBER}.txt
|
||||||
on an arbitrarily sized 2D board
|
|
||||||
|
|
||||||
Each turn, the client outputs a GAMESTATE file and
|
### Contents
|
||||||
waits for an ORDER file from each player
|
===== ttrts v{MAJOR}.{MINOR}.{PATCH} =====
|
||||||
|
NAME:{GAMENAME}
|
||||||
|
SIZE:[{X},{Y}]
|
||||||
|
TURN:{TURNNUMBER}
|
||||||
|
WALL:[{X},{Y}][{X},{Y}][{X},{Y}]...{repeat for all walls}
|
||||||
|
~~~~
|
||||||
|
UNIT:{ID} pl:{PLAYER} vs:{VIS} dr:{DIR(NESW)} ps:[{X},{Y}]
|
||||||
|
... {continue for all units}
|
||||||
|
END
|
||||||
|
|
||||||
All commands are evaluated simultaneously with friendly
|
## Order File
|
||||||
fire enabled by default
|
Player_{PLAYER_ID}_Turn_{TURN_NUMBER}.txt
|
||||||
|
|
||||||
|
### Contents
|
||||||
|
ORDER:{ORDER_CHAR} id:{UNIT_ID}
|
||||||
|
... {continue for all orders}
|
||||||
|
END
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
# GAMEPLAY
|
||||||
|
|
||||||
|
The game takes place in a series of simultaneous turns on an arbitrarily sized 2D board
|
||||||
|
|
||||||
|
Each turn, the client outputs a gamestate file and waits for an order file from each player
|
||||||
|
|
||||||
|
All commands are evaluated simultaneously with friendly fire enabled by default
|
||||||
|
|
||||||
The game is over when any of three conditions are met -
|
The game is over when any of three conditions are met -
|
||||||
* All remaining units are controlled by a single player
|
* All remaining units are controlled by a single player
|
||||||
* No units are left (draw)
|
* No units are left (draw)
|
||||||
* All units left are unable to move (draw)
|
* All units left are unable to move (draw)
|
||||||
|
|
||||||
## UNITS
|
# UNITS
|
||||||
Each unit occupies a single tile on the board, facing
|
Each unit occupies a single tile on the board, facing in a compass direction (NESW)
|
||||||
in a compass direction (NESW)
|
|
||||||
|
|
||||||
Units will only accept orders from their owner
|
Units will only accept orders from their owner
|
||||||
|
|
||||||
|
@ -55,48 +80,19 @@
|
||||||
|
|
||||||
Units cannot occupy the same tile as other units/walls
|
Units cannot occupy the same tile as other units/walls
|
||||||
|
|
||||||
## ORDERS
|
# ORDERS
|
||||||
F - Move unit [F]orward one space, leaving a wall
|
### F - Move unit [F]orward one space, leaving a wall
|
||||||
|
|
||||||
This wall will remain until the end of the game,
|
This wall will remain until the end of the game, blocking movement to that tile
|
||||||
blocking movement to that tile
|
|
||||||
|
|
||||||
Movement orders have no effect if impossible, eg.
|
Movement orders have no effect if impossible, eg.
|
||||||
* Attempting to move outside of map
|
* Attempting to move outside of map
|
||||||
* Attempting to move on to tile occupied by unit/wall
|
* Attempting to move on to tile occupied by unit/wall
|
||||||
|
|
||||||
L/R - Rotate unit [L]eft or [R]ight
|
### L/R - Rotate unit [L]eft or [R]ight
|
||||||
|
|
||||||
Unit will rotate clockwise or counter-clockwise,
|
Unit will rotate clockwise or counter-clockwise, this order cannot fail
|
||||||
this order cannot fail
|
|
||||||
|
|
||||||
A - [A]ttack in straight line in front of unit
|
### A - [A]ttack in straight line in front of unit
|
||||||
|
|
||||||
Attack will continue forward until unit can't progress,
|
|
||||||
all units within the path of the attack are destroyed.
|
|
||||||
|
|
||||||
-----------------------------------------------------------
|
|
||||||
# FILE FORMATS
|
|
||||||
|
|
||||||
## Gamestate File
|
|
||||||
Turn_{TURN_NUMBER}.txt
|
|
||||||
|
|
||||||
### Contents
|
|
||||||
===== ttrts v{MAJOR}.{MINOR}.{PATCH} =====
|
|
||||||
NAME:{GAMENAME}
|
|
||||||
SIZE:[{X},{Y}]
|
|
||||||
TURN:{TURN_NUMBER}
|
|
||||||
WALL:[{X},{Y}][{X},{Y}][{X},{Y}]...{repeat for all walls}
|
|
||||||
~~~~
|
|
||||||
UNIT:{ID} pl:{PLAYER} vs:{VIS} dr:{DIR(NESW)} ps:[{X},{Y}]
|
|
||||||
... {continue for all units}
|
|
||||||
END
|
|
||||||
|
|
||||||
## Order File
|
|
||||||
Player_{PLAYER_ID}_Turn_{TURN_NUMBER}.txt
|
|
||||||
|
|
||||||
### Contents
|
|
||||||
ORDER:{ORDER_CHAR} id:{UNIT_ID}
|
|
||||||
... {continue for all orders}
|
|
||||||
END
|
|
||||||
|
|
||||||
|
Attack will continue forward until unit can't progress, all units within the path of the attack are destroyed.
|
||||||
|
|
|
@ -5,6 +5,7 @@ project( ttrts )
|
||||||
|
|
||||||
# Include the maths
|
# Include the maths
|
||||||
include_directories(
|
include_directories(
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
../maths
|
../maths
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,4 +17,31 @@ set( SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add this library
|
# Add this library
|
||||||
add_library( ttrts ${SOURCES} )
|
add_library( ttrts ${SOURCES} )
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
|
ttrts-version-header ALL
|
||||||
|
${CMAKE_SOURCE_DIR}/scripts/gen_version_header.sh ${TTRTS_VERSION_MAJOR} ${TTRTS_VERSION_MINOR} ${TTRTS_VERSION_PATCH}
|
||||||
|
)
|
||||||
|
|
||||||
|
# ttrts is dependent on this
|
||||||
|
add_dependencies( ${PROJECT_NAME} ttrts-version-header )
|
||||||
|
|
||||||
|
# Install headers
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
game.h
|
||||||
|
unit.h
|
||||||
|
order.h
|
||||||
|
formatters.h
|
||||||
|
vector2.h
|
||||||
|
orderunitpair.h
|
||||||
|
gametypes.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/version.h
|
||||||
|
|
||||||
|
DESTINATION
|
||||||
|
include/ttrts
|
||||||
|
)
|
||||||
|
|
||||||
|
# Install the ttrts static lib
|
||||||
|
install( TARGETS ttrts DESTINATION lib )
|
|
@ -1,4 +1,7 @@
|
||||||
#include "formatters.h"
|
#include "formatters.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
// Get the game information as a string
|
// Get the game information as a string
|
||||||
std::string GetStringFromGame( const CTTRTSGame& game )
|
std::string GetStringFromGame( const CTTRTSGame& game )
|
||||||
|
@ -24,6 +27,9 @@ std::string GetStringFromGame( const CTTRTSGame& game )
|
||||||
// Print out the header
|
// Print out the header
|
||||||
char header[512];
|
char header[512];
|
||||||
if ( snprintf(header, 512, GAME_HEADER_FORMATTER ,
|
if ( snprintf(header, 512, GAME_HEADER_FORMATTER ,
|
||||||
|
TTRTS_VERSION_MAJOR,
|
||||||
|
TTRTS_VERSION_MINOR,
|
||||||
|
TTRTS_VERSION_PATCH,
|
||||||
game.GetName().c_str(),
|
game.GetName().c_str(),
|
||||||
game.GetDimensions().x,
|
game.GetDimensions().x,
|
||||||
game.GetDimensions().y,
|
game.GetDimensions().y,
|
||||||
|
@ -60,16 +66,26 @@ CTTRTSGame GetGameFromString( const std::string& input )
|
||||||
std::string units = input.substr(headerEnd + strlen(GAME_HEADER_DELIMITER));
|
std::string units = input.substr(headerEnd + strlen(GAME_HEADER_DELIMITER));
|
||||||
|
|
||||||
// Grab information from the header
|
// Grab information from the header
|
||||||
|
unsigned int major;
|
||||||
|
unsigned int minor;
|
||||||
|
unsigned int patch;
|
||||||
char name[64];
|
char name[64];
|
||||||
unsigned int turn;
|
unsigned int turn;
|
||||||
unsigned int sizex;
|
unsigned int sizex;
|
||||||
unsigned int sizey;
|
unsigned int sizey;
|
||||||
char walls[512];
|
char walls[512];
|
||||||
if( sscanf(header.c_str(), GAME_HEADER_FORMATTER, name, &sizex, &sizey, &turn, walls) != 5 )
|
if( sscanf(header.c_str(), GAME_HEADER_FORMATTER, &major, &minor, &patch, name, &sizex, &sizey, &turn, walls) != 8 )
|
||||||
{
|
{
|
||||||
|
std::cerr<<"Error: Failed to properly read game state from text"<<std::endl;
|
||||||
return CTTRTSGame(0,0);
|
return CTTRTSGame(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( major != TTRTS_VERSION_MAJOR
|
||||||
|
|| minor != TTRTS_VERSION_MINOR )
|
||||||
|
{
|
||||||
|
std::cerr<<"Error: ttrts map/binary version missmatch BINARY:v"<<major<<"."<<minor<<"."<<patch<<" FILE:"<<TTRTS_VERSION_STRING<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<uvector2> walls_vector;
|
std::vector<uvector2> walls_vector;
|
||||||
{
|
{
|
||||||
std::string walls_str = walls;
|
std::string walls_str = walls;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#define GAME_POS_FORMATTER "[%u,%u]"
|
#define GAME_POS_FORMATTER "[%u,%u]"
|
||||||
|
|
||||||
#define GAME_HEADER_FORMATTER "NAME:%s\nSIZE:" GAME_POS_FORMATTER "\nTURN:%u\nWALL:%s"
|
#define GAME_HEADER_FORMATTER "==== ttrts v%u.%u.%u ====\nNAME:%s\nSIZE:" GAME_POS_FORMATTER "\nTURN:%u\nWALL:%s"
|
||||||
#define GAME_HEADER_DELIMITER "~~~~\n"
|
#define GAME_HEADER_DELIMITER "~~~~\n"
|
||||||
|
|
||||||
#define UNIT_FORMATTER "UNIT:%u pl:%u vs:%c dr:%c ps:" GAME_POS_FORMATTER
|
#define UNIT_FORMATTER "UNIT:%u pl:%u vs:%c dr:%c ps:" GAME_POS_FORMATTER
|
||||||
|
@ -24,6 +24,6 @@ std::string GetStringFromGame( const CTTRTSGame& game );
|
||||||
|
|
||||||
// unit <--> string conversion functions
|
// unit <--> string conversion functions
|
||||||
std::string GetStringFromUnit(const CUnit& unit );
|
std::string GetStringFromUnit(const CUnit& unit );
|
||||||
CUnit GetUnitFromString(const std::string& unit );
|
CUnit GetUnitFromString(const std::string& unit );
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,9 +0,0 @@
|
||||||
#ifndef _TTRTS_VERSION_H_
|
|
||||||
#define _TTRTS_VERSION_H_
|
|
||||||
|
|
||||||
static const int sk_ttrts_version_major = TTRTS_VERSION_MAJOR;
|
|
||||||
static const int sk_ttrts_version_minor = TTRTS_VERSION_MINOR;
|
|
||||||
static const int sk_ttrts_version_patch = TTRTS_VERSION_PATCH;
|
|
||||||
static const char* sk_ttrts_version_string = TTRTS_VERSION_STRING;
|
|
||||||
|
|
||||||
#endif //_TTRTS_VERSION_H_
|
|
Loading…
Add table
Reference in a new issue