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
|
||||
|
||||
## DESCRIPTION
|
||||
ttrts is a tiny terminal based RTS where that uses text
|
||||
files as order lists to control it's units
|
||||
# DESCRIPTION
|
||||
ttrts is a tiny terminal based RTS that uses text files as order lists to control the units
|
||||
|
||||
This means that any user, program or cat that can read
|
||||
and write to text files can play the game
|
||||
This means that any user, program or cat that can read and write to text files can play the game
|
||||
|
||||
## OPTIONS
|
||||
MAPFILE - File to read in the initial game state from
|
||||
# RETURN VALUE
|
||||
ttrts will return -1 on error, or the winning player on completion
|
||||
|
||||
## USAGE
|
||||
When invoked, ttrts will set up the game in a local
|
||||
directory called `ttrts_{GAME_NAME}`
|
||||
# OPTIONS
|
||||
MAPFILE - File to read in the initial game state. Local or in ${TTRTS_MAPS}
|
||||
|
||||
The GAMESTATE files in this directory can be read and
|
||||
interpreted by human, robot or cat.
|
||||
# USAGE
|
||||
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
|
||||
calculate the turn and output a new GAMESTATE file
|
||||
ttrts will then await order files from each participant
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
The game takes place in a series of simultaneous turns
|
||||
on an arbitrarily sized 2D board
|
||||
## Gamestate File
|
||||
Turn_{TURNNUMBER}.txt
|
||||
|
||||
Each turn, the client outputs a GAMESTATE file and
|
||||
waits for an ORDER file from each player
|
||||
### Contents
|
||||
===== 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
|
||||
fire enabled by default
|
||||
## Order File
|
||||
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 -
|
||||
* All remaining units are controlled by a single player
|
||||
* No units are left (draw)
|
||||
* All units left are unable to move (draw)
|
||||
* All remaining units are controlled by a single player
|
||||
* No units are left (draw)
|
||||
* All units left are unable to move (draw)
|
||||
|
||||
## UNITS
|
||||
Each unit occupies a single tile on the board, facing
|
||||
in a compass direction (NESW)
|
||||
# UNITS
|
||||
Each unit occupies a single tile on the board, facing in a compass direction (NESW)
|
||||
|
||||
Units will only accept orders from their owner
|
||||
|
||||
|
@ -55,48 +80,19 @@
|
|||
|
||||
Units cannot occupy the same tile as other units/walls
|
||||
|
||||
## ORDERS
|
||||
F - Move unit [F]orward one space, leaving a wall
|
||||
|
||||
This wall will remain until the end of the game,
|
||||
blocking movement to that tile
|
||||
# ORDERS
|
||||
### F - Move unit [F]orward one space, leaving a wall
|
||||
|
||||
This wall will remain until the end of the game, blocking movement to that tile
|
||||
|
||||
Movement orders have no effect if impossible, eg.
|
||||
* Attempting to move outside of map
|
||||
* Attempting to move on to tile occupied by unit/wall
|
||||
* Attempting to move outside of map
|
||||
* 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,
|
||||
this order cannot fail
|
||||
Unit will rotate clockwise or counter-clockwise, this order cannot fail
|
||||
|
||||
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
|
||||
### 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.
|
||||
|
|
|
@ -5,6 +5,7 @@ project( ttrts )
|
|||
|
||||
# Include the maths
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
../maths
|
||||
)
|
||||
|
||||
|
@ -16,4 +17,31 @@ set( SOURCES
|
|||
)
|
||||
|
||||
# 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 <iostream>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
// Get the game information as a string
|
||||
std::string GetStringFromGame( const CTTRTSGame& game )
|
||||
|
@ -24,6 +27,9 @@ std::string GetStringFromGame( const CTTRTSGame& game )
|
|||
// Print out the header
|
||||
char header[512];
|
||||
if ( snprintf(header, 512, GAME_HEADER_FORMATTER ,
|
||||
TTRTS_VERSION_MAJOR,
|
||||
TTRTS_VERSION_MINOR,
|
||||
TTRTS_VERSION_PATCH,
|
||||
game.GetName().c_str(),
|
||||
game.GetDimensions().x,
|
||||
game.GetDimensions().y,
|
||||
|
@ -60,16 +66,26 @@ CTTRTSGame GetGameFromString( const std::string& input )
|
|||
std::string units = input.substr(headerEnd + strlen(GAME_HEADER_DELIMITER));
|
||||
|
||||
// Grab information from the header
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
unsigned int patch;
|
||||
char name[64];
|
||||
unsigned int turn;
|
||||
unsigned int sizex;
|
||||
unsigned int sizey;
|
||||
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);
|
||||
}
|
||||
|
||||
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::string walls_str = walls;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#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 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
|
||||
std::string GetStringFromUnit(const CUnit& unit );
|
||||
CUnit GetUnitFromString(const std::string& unit );
|
||||
CUnit GetUnitFromString(const std::string& unit );
|
||||
|
||||
#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