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:
mdiluzio 2014-12-30 18:37:46 +00:00
parent 53e882ae12
commit 2273c93f11
8 changed files with 179 additions and 83 deletions

29
scripts/gen_manpage.sh Executable file
View 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
View 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
View 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

View file

@ -1,91 +1,48 @@
# 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 GAMEPLAY ${TTRTS_MAPS} - Map file lookup location, defaults to `/usr/share/ttrts/maps/`
## RULES ${TTRTS_GAMES} - Game directory for I/O, defaults to `/tmp/`
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)
## UNITS
Each unit occupies a single tile on the board, facing
in a compass direction (NESW)
Units will only accept orders from their owner
Units can receive only a single order each turn
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
Movement orders have no effect if impossible, eg.
* 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
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 # FILES
`/usr/share/ttrts/maps/` holds a sample set of maps
## Gamestate File ## Gamestate File
Turn_{TURN_NUMBER}.txt Turn_{TURNNUMBER}.txt
### Contents ### Contents
===== ttrts v{MAJOR}.{MINOR}.{PATCH} ===== ===== ttrts v{MAJOR}.{MINOR}.{PATCH} =====
NAME:{GAMENAME} NAME:{GAMENAME}
SIZE:[{X},{Y}] SIZE:[{X},{Y}]
TURN:{TURN_NUMBER} TURN:{TURNNUMBER}
WALL:[{X},{Y}][{X},{Y}][{X},{Y}]...{repeat for all walls} WALL:[{X},{Y}][{X},{Y}][{X},{Y}]...{repeat for all walls}
~~~~ ~~~~
UNIT:{ID} pl:{PLAYER} vs:{VIS} dr:{DIR(NESW)} ps:[{X},{Y}] UNIT:{ID} pl:{PLAYER} vs:{VIS} dr:{DIR(NESW)} ps:[{X},{Y}]
@ -100,3 +57,42 @@
... {continue for all orders} ... {continue for all orders}
END 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)
# UNITS
Each unit occupies a single tile on the board, facing in a compass direction (NESW)
Units will only accept orders from their owner
Units can receive only a single order each turn
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
Movement orders have no effect if impossible, eg.
* 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
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.

View file

@ -5,6 +5,7 @@ project( ttrts )
# Include the maths # Include the maths
include_directories( include_directories(
${CMAKE_CURRENT_BINARY_DIR}
../maths ../maths
) )
@ -17,3 +18,30 @@ 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 )

View file

@ -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;

View file

@ -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

View file

@ -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_