Share online membership and game setup with the server
Profile, member join/leave and building a fresh game move into the sim library, and the packet reader and writer into protocol.h, so the server can run lobbies exactly as clients do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
465f75f6d7
commit
9613e85706
7 files changed
+181
-105
No files matched your search
+47
@@ -26,6 +26,53 @@ void Sim::tick()
|
||||
world.update(*this);
|
||||
}
|
||||
|
||||
// A fresh online game for some of a lobby's fighters (by index) to play by the rules, bots filling the rest when the
|
||||
// rules say to. Their members, names and colours come along, and it starts from the seed, so everyone builds the same
|
||||
// one. The bots keep their difficulty.
|
||||
void Sim::game_start(Match& lobby, const int* members, int count, const Rules& rules, Uint32 seed)
|
||||
{
|
||||
int owners[MAX_FIGHTERS];
|
||||
int colors[MAX_FIGHTERS];
|
||||
char names[MAX_FIGHTERS][PLAYER_NAME_MAX + 1];
|
||||
for (int k = 0; k < count; k++)
|
||||
{
|
||||
owners[k] = lobby.owners[members[k]];
|
||||
colors[k] = lobby.colors[members[k]];
|
||||
std::memcpy(names[k], lobby.names[members[k]], sizeof(names[k]));
|
||||
}
|
||||
int players = rules.isBotFill ? std::max(rules.players, count) : count;
|
||||
int level = bot.level;
|
||||
bot = Bot{};
|
||||
bot.level = level;
|
||||
weapons = Weapons{};
|
||||
world = World{};
|
||||
match = Match{};
|
||||
match.rules = rules;
|
||||
match.rules.players = players;
|
||||
match.isOnline = true;
|
||||
rng.state = seed ? seed : RNG_SEED;
|
||||
fighterCount = players;
|
||||
|
||||
bool isTaken[COLOR_COUNT] = {};
|
||||
for (int k = 0; k < count; k++)
|
||||
isTaken[colors[k] % COLOR_COUNT] = true;
|
||||
for (int k = 0; k < players; k++)
|
||||
{
|
||||
fighters[k] = Fighter{};
|
||||
fighters[k].init(*this, k);
|
||||
match.owners[k] = k < count ? owners[k] : -1;
|
||||
if (k < count)
|
||||
{
|
||||
match.colors[k] = colors[k];
|
||||
std::memcpy(match.names[k], names[k], sizeof(match.names[k]));
|
||||
continue;
|
||||
}
|
||||
match.colors[k] = std::find(isTaken, isTaken + COLOR_COUNT, false) - isTaken;
|
||||
isTaken[match.colors[k]] = true;
|
||||
}
|
||||
match.start(*this);
|
||||
}
|
||||
|
||||
// Moves a level by a step within the levels there are, cueing whether it went up or down.
|
||||
void level_step(Sim& sim, int& level, int step)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user