Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ Some messages consist of only type character others contain more data.
- `j` `<player name>` `\n` - new player has joined the game room
- `l` `<player name>` `\n` - player `<player name>` has either left or lost the game
- `m` `<id>` ` ` `<x>` ` ` `<y>` `\n` - unit of id `<id>` has moved to `<x>;<y>`
- `a` `<id1>` ` ` `<id2>` `\n` - unit of id `<id1>` attacked unit of id `<id2>`
- `d` `<id>` `\n` - unit of id `<id>` mined a resource
- `a` `<id1>` ` ` `<id2>` ` ` `<hp>` `\n` - unit of id `<id1>` attacked unit of id `<id2>` and target unit has now `<hp>` hp left
- `d` `<id>` ` ` `<hp>` `\n` - unit of id `<id>` mined a resource and resource has now `<hp>` hp left
- `u` `<player name>` ` ` `<id>` ` ` `<x>` ` ` `<y>` - player `<player name>` has aquired unit of id `<id>` on field `<x>;<y>`
- `f` `<x>` ` ` `<y>` ` ` `<hp>` `\n` - new resource spawned on field `<x>;<y>`
- `t` `\n` - sent to all players in game room in regular time intervals, marks the and of each tick and a start of the next one
- `q` `\n` - player was sent to queue (in response to: `j`)
- `y` `\n` - client request accepted (in response to: `n`)
- `n` `\n` - client request denied (in response to: `j` or `n`)
- `L` `\n` - client lost the game (and was moved out of game room)
- `W` `\n` - client won the game (and was moved out of game room)
- `L` `<name>` `\n` - client lost the game (and was moved out of game room), `<name>` is the name of the player who won
- `W` `<name>` `\n` - client won the game (and was moved out of game room), `<name>` is the name of the player who won

### Board state message

Expand Down
11 changes: 8 additions & 3 deletions src/rts/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,20 @@ void rts::game::deletePlayer(player* pl){
void rts::game::playerLostAllUnits(player* pl) {
assert(pl);
assert(activePlayers.find(pl) != activePlayers.end());
pl->getClient()->sendToClient({'L','\n'});
std::vector<char> buff = {'l'};
message::appendStringWDelim(buff, pl->getName(), '\n');
pl->getClient()->sendToClient(buff);
removePlayerFromRoomOrQueue(pl);
}

void rts::game::tryWin(player* pl){
if (pl->units.size() >= unitsToWin) {
pl->getClient()->sendToClient({'W','\n'});
std::vector<char> buff = {'W'};
message::appendStringWDelim(buff, pl->getName(), '\n');
pl->getClient()->sendToClient(buff);
buff[0] = 'L';
for (player* p : activePlayers){
if (p != pl) p->getClient()->sendToClient({'L','\n'});
if (p != pl) p->getClient()->sendToClient(buff);
}

clearRoom();
Expand Down
8 changes: 5 additions & 3 deletions src/rts/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ rts::unit::unit(player* owner_, field* field_, unsigned int id_) :

void rts::unit::mine(){
if (!movedThisRound && f->hasResource()) {
f->mine(owner->getGame()->getUnitDamage());

std::vector<char> buff = {'d'};
message::appendNumberWDelim(buff, id, '\n');
message::appendNumberWDelim(buff, id, ' ');
message::appendNumberWDelim(buff, f->getHp(), '\n');
owner->getGame()->sendToPlayers(buff);

f->mine(owner->getGame()->getUnitDamage());
if (f->getHp() <= 0) {
field* nf = owner->getGame()->_board.closestEmptyField(f);
if (nf) owner->newUnit(nf);
Expand Down Expand Up @@ -57,7 +58,8 @@ void rts::unit::attack(unit* target){

std::vector<char> buff = {'a'};
message::appendNumberWDelim(buff, id, ' ');
message::appendNumberWDelim(buff, target->id, '\n');
message::appendNumberWDelim(buff, target->id, ' ');
message::appendNumberWDelim(buff, target->hp - owner->getGame()->getUnitDamage(), '\n');
owner->getGame()->sendToPlayers(buff);

target->recvDamage(owner->getGame()->getUnitDamage());
Expand Down