diff --git a/README.md b/README.md index b50441f..08876e1 100644 --- a/README.md +++ b/README.md @@ -80,16 +80,16 @@ Some messages consist of only type character others contain more data. - `j` `` `\n` - new player has joined the game room - `l` `` `\n` - player `` has either left or lost the game - `m` `` ` ` `` ` ` `` `\n` - unit of id `` has moved to `;` -- `a` `` ` ` `` `\n` - unit of id `` attacked unit of id `` -- `d` `` `\n` - unit of id `` mined a resource +- `a` `` ` ` `` ` ` `` `\n` - unit of id `` attacked unit of id `` and target unit has now `` hp left +- `d` `` ` ` `` `\n` - unit of id `` mined a resource and resource has now `` hp left - `u` `` ` ` `` ` ` `` ` ` `` - player `` has aquired unit of id `` on field `;` - `f` `` ` ` `` ` ` `` `\n` - new resource spawned on field `;` - `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` `` `\n` - client lost the game (and was moved out of game room), `` is the name of the player who won +- `W` `` `\n` - client won the game (and was moved out of game room), `` is the name of the player who won ### Board state message diff --git a/src/rts/game.cpp b/src/rts/game.cpp index 14babdb..8bbd1d1 100644 --- a/src/rts/game.cpp +++ b/src/rts/game.cpp @@ -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 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 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(); diff --git a/src/rts/unit.cpp b/src/rts/unit.cpp index 169fe6e..658162a 100644 --- a/src/rts/unit.cpp +++ b/src/rts/unit.cpp @@ -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 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); @@ -57,7 +58,8 @@ void rts::unit::attack(unit* target){ std::vector 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());