diff options
Diffstat (limited to 'world.cpp')
-rw-r--r-- | world.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -1,6 +1,7 @@ #include <cstdlib> #include <cassert> #include <cstring> +#include <unordered_map> #include "world.h" @@ -351,6 +352,17 @@ Robot* World::targetbot(const Robot *r){ return *targetbotptr(r); } +static int colourCode(const Team *team){ + static unordered_map<const Team*,int> mappings; + static int nextCode=1; + auto it=mappings.find(team); + if(it!=mappings.end())return it->second; + int code=nextCode; + mappings[team]=code; + nextCode=nextCode%6+1; + return code; +} + void World::print(ScreenBuffer &sb) const { for(int y=0;y<SIZE;y++){ sb.moveto(0,y); @@ -359,7 +371,9 @@ void World::print(ScreenBuffer &sb) const { else { char c2="^>v<"[board[y][x]->heading%4]; char c1=board[y][x]->active?c2:'X'; + sb.setfg(colourCode(board[y][x]->team)); sb.printf("%c%c",c1,c2); + sb.setfg(9); } sb.printf(" "); } |