Added monitors to storage

This commit is contained in:
Martijn Braam 2020-10-20 20:39:45 +02:00
parent d74b5e3409
commit 78b6cc9873
No known key found for this signature in database
GPG Key ID: C4280ACB000B060F
1 changed files with 25 additions and 2 deletions

27
main.c
View File

@ -151,8 +151,8 @@ const char locations[][45] = {
enum player_location doors[][10] = {
[LOC_CAFETERIA] = { LOC_MEDBAY, LOC_ADMIN, LOC_WEAPONS, LOC_COUNT },
[LOC_REACTOR] = { LOC_UPPER_ENGINE, LOC_SECURITY, LOC_LOWER_ENGINE, LOC_COUNT },
[LOC_UPPER_ENGINE] = { LOC_REACTOR, LOC_ELECTRICAL, LOC_MEDBAY, LOC_COUNT },
[LOC_LOWER_ENGINE] = { LOC_REACTOR, LOC_ELECTRICAL, LOC_COUNT },
[LOC_UPPER_ENGINE] = { LOC_REACTOR, LOC_SECURITY, LOC_ELECTRICAL, LOC_MEDBAY, LOC_COUNT },
[LOC_LOWER_ENGINE] = { LOC_REACTOR, LOC_SECURITY, LOC_ELECTRICAL, LOC_COUNT },
[LOC_SECURITY] = { LOC_UPPER_ENGINE, LOC_REACTOR, LOC_LOWER_ENGINE, LOC_COUNT },
[LOC_MEDBAY] = { LOC_UPPER_ENGINE, LOC_CAFETERIA, LOC_COUNT },
[LOC_ELECTRICAL] = { LOC_LOWER_ENGINE, LOC_STORAGE, LOC_COUNT },
@ -431,6 +431,26 @@ task_completed(size_t pid, size_t task_id, int long_task)
check_win_condition();
}
void
list_rooms_with_players(size_t pid) {
int count[LOC_COUNT] = {0};
char buf[100];
for (size_t i = 0; i < NUM_PLAYERS; i++) {
if (players[i].fd != -1 && alive(players[i]))
count[players[i].location]++;
}
for (int i=0;i<LOC_COUNT;i++) {
if (count[i] > 0) {
snprintf(buf, sizeof(buf), " * There are %d players in %s\n",
count[i], locations[i]);
write(players[pid].fd, buf, strlen(buf));
}
}
}
void
player_list_tasks(size_t pid)
{
@ -915,6 +935,9 @@ adventure(size_t pid, char *input)
} else if (strcmp(input, "check tasks") == 0) {
player_list_tasks(pid);
return;
} else if (strcmp(input, "look at monitors") == 0) {
list_rooms_with_players(pid);
return;
} else if (strcmp(input, "help") == 0) {
snprintf(buf, sizeof(buf), "Commands: help, examine room, go [room], murder crewmate, report, check tasks\n# ");
} else if (strncmp(input, "map", 3) == 0) {