-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Gamemodes.c
107 lines (95 loc) · 4.14 KB
/
Gamemodes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "Protocol.h"
#include "Structs.h"
#include "Types.h"
#include "Util/Enums.h"
#include "../Extern/libmapvxl/libmapvxl.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
static void initCTF(Server* server)
{
memcpy(server->gamemodeName, "ctf", strlen("ctf") + 1);
// Init CTF
server->protocol.gameMode.score[0] = 0;
server->protocol.gameMode.score[1] = 0;
server->protocol.gameMode.scoreLimit = 10;
server->protocol.gameMode.intelFlags = 0;
// intel
server->protocol.gameMode.intel[0] = SetIntelTentSpawnPoint(server, 0);
server->protocol.gameMode.intel[1] = SetIntelTentSpawnPoint(server, 1);
server->protocol.gameMode.intelHeld[0] = 0;
server->protocol.gameMode.intelHeld[1] = 0;
// bases
server->protocol.gameMode.base[0] = SetIntelTentSpawnPoint(server, 0);
server->protocol.gameMode.base[1] = SetIntelTentSpawnPoint(server, 1);
server->protocol.gameMode.base[0].x = floorf(server->protocol.gameMode.base[0].x);
server->protocol.gameMode.base[0].y = floorf(server->protocol.gameMode.base[0].y);
server->protocol.gameMode.base[1].x = floorf(server->protocol.gameMode.base[1].x);
server->protocol.gameMode.base[1].y = floorf(server->protocol.gameMode.base[1].y);
}
static void initTC(Server* server)
{
memcpy(server->gamemodeName, "tc", strlen("tc") + 1);
LOG_WARNING("GameMode not supported properly yet");
server->running = 0;
}
static void initBabel(Server* server)
{
memcpy(server->gamemodeName, "babel", strlen("babel") + 1);
// Init CTF
server->protocol.gameMode.score[0] = 0;
server->protocol.gameMode.score[1] = 0;
server->protocol.gameMode.scoreLimit = 10;
server->protocol.gameMode.intelFlags = 0;
Color4i platformColor;
platformColor.colorArray[B_CHANNEL] = 255;
platformColor.colorArray[G_CHANNEL] = 255;
platformColor.colorArray[R_CHANNEL] = 0;
for (int x = 206; x <= 306; ++x) {
for (int y = 240; y <= 272; ++y) {
mapvxlSetColor(&server->map.map, x, y, 1, platformColor.color);
}
}
// intel
server->protocol.gameMode.intel[0].z =
mapvxlFindTopBlock(&server->map.map, 255, 255); // We still need highest point of map. While this is 0 for normal
// map. The platform may not be there in all sizes
server->protocol.gameMode.intel[0].x = MAP_MAX_X / 2;
server->protocol.gameMode.intel[0].y = MAP_MAX_Y / 2;
server->protocol.gameMode.intelHeld[0] = 0;
server->protocol.gameMode.intel[1].z =
mapvxlFindTopBlock(&server->map.map, 255, 255); // We still need highest point of map. While this is 0 for normal
// map. The platform may not be there in all sizes
server->protocol.gameMode.intel[1].x = MAP_MAX_X / 2;
server->protocol.gameMode.intel[1].y = MAP_MAX_Y / 2;
server->protocol.gameMode.intelHeld[1] = 0;
// bases
server->protocol.gameMode.base[0] = SetIntelTentSpawnPoint(server, 0);
server->protocol.gameMode.base[1] = SetIntelTentSpawnPoint(server, 1);
server->protocol.gameMode.base[0].x = floorf(server->protocol.gameMode.base[0].x);
server->protocol.gameMode.base[0].y = floorf(server->protocol.gameMode.base[0].y);
server->protocol.gameMode.base[1].x = floorf(server->protocol.gameMode.base[1].x);
server->protocol.gameMode.base[1].y = floorf(server->protocol.gameMode.base[1].y);
}
static void initArena(Server* server)
{
memcpy(server->gamemodeName, "arena", strlen("arena") + 1);
LOG_WARNING("GameMode not supported properly yet");
server->running = 0;
}
void initGameMode(Server* server, uint8 gamemode)
{
server->protocol.currentGameMode = gamemode;
if (server->protocol.currentGameMode == GAME_MODE_CTF) {
initCTF(server);
} else if (server->protocol.currentGameMode == GAME_MODE_TC) {
initTC(server);
} else if (server->protocol.currentGameMode == GAME_MODE_BABEL) {
initBabel(server);
} else if (server->protocol.currentGameMode == GAME_MODE_ARENA) {
initArena(server);
} else {
LOG_ERROR("Unknown GameMode");
server->running = 0;
}
}