about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--client.c7
-rw-r--r--server.c13
-rw-r--r--torus.h13
3 files changed, 33 insertions, 0 deletions
diff --git a/client.c b/client.c
index d48ba17..c9800cf 100644
--- a/client.c
+++ b/client.c
@@ -271,6 +271,11 @@ static void clientMap(void) {
 	clientMessage(msg);
 }
 
+static void clientTele(uint8_t port) {
+	struct ClientMessage msg = { .type = ClientTele, .port = port };
+	clientMessage(msg);
+}
+
 static struct {
 	enum {
 		ModeNormal,
@@ -402,6 +407,8 @@ static void inputNormal(bool keyCode, wchar_t ch) {
 		break; case Esc: modeNormal(); input.shift = 0;
 		break; case 'q': endwin(); exit(EX_OK);
 
+		break; case 'Q': clientTele(input.color % ARRAY_LEN(Ports));
+
 		break; case '\\': input.delta = (input.delta == 1 ? 4 : 1);
 
 		break; case 'h': clientMove(-input.delta,  0);
diff --git a/server.c b/server.c
index ad9815b..356387f 100644
--- a/server.c
+++ b/server.c
@@ -359,6 +359,16 @@ static bool clientMap(const struct Client *client) {
 	return true;
 }
 
+static bool clientTele(struct Client *client, uint8_t port) {
+	if (port >= ARRAY_LEN(Ports)) return false;
+	struct Client old = *client;
+	client->tileX = Ports[port].tileX;
+	client->tileY = Ports[port].tileY;
+	client->cellX = CellInitX;
+	client->cellY = CellInitY;
+	return clientUpdate(client, &old);
+}
+
 int main(int argc, char *argv[]) {
 	int error;
 
@@ -477,6 +487,9 @@ int main(int argc, char *argv[]) {
 			break; case ClientMap: {
 				success = clientMap(client);
 			}
+			break; case ClientTele: {
+				success = clientTele(client, msg.port);
+			}
 		}
 		if (!success) clientRemove(client);
 	}
diff --git a/torus.h b/torus.h
index a18f515..ba552eb 100644
--- a/torus.h
+++ b/torus.h
@@ -104,6 +104,17 @@ static const size_t TilesSize = sizeof(struct Tile[TileRows][TileCols]);
 static const uint32_t TileInitX = 0;
 static const uint32_t TileInitY = 0;
 
+static const struct {
+	uint32_t tileX;
+	uint32_t tileY;
+} Ports[] = {
+	{ TileInitX, TileInitY },
+	{ TileCols * 3 / 4, TileRows * 3 / 4 }, // NW
+	{ TileCols * 1 / 4, TileRows * 3 / 4 }, // NE
+	{ TileCols * 1 / 4, TileRows * 1 / 4 }, // SE
+	{ TileCols * 3 / 4, TileRows * 1 / 4 }, // SW
+};
+
 enum {
 	MapRows = 11,
 	MapCols = 11,
@@ -152,6 +163,7 @@ struct ClientMessage {
 		ClientFlip,
 		ClientPut,
 		ClientMap,
+		ClientTele,
 	} type;
 	union {
 		struct {
@@ -162,5 +174,6 @@ struct ClientMessage {
 			uint8_t color;
 			uint8_t cell;
 		} put;
+		uint8_t port;
 	};
 };