Add squad invites

main
Cameron Murphy Reikes 2 years ago
parent 5f56bdfbb6
commit 660ec75faf

@ -682,7 +682,7 @@ SerMaybeFailure ser_data(SerState* ser, char* data, size_t data_len, const char*
{ {
char var_name[512] = { 0 }; char var_name[512] = { 0 };
size_t var_name_len = 0; size_t var_name_len = 0;
if(ser->write_varnames) if (ser->write_varnames)
{ {
snprintf(var_name, 512, "%d%s", line, name); // can't have separator before the name, when comparing names skips past the digit snprintf(var_name, 512, "%d%s", line, name); // can't have separator before the name, when comparing names skips past the digit
var_name_len = strlen(var_name); var_name_len = strlen(var_name);
@ -771,6 +771,7 @@ enum GameVersion
VChangedVectorSerializing, VChangedVectorSerializing,
VAddedLastUsedMedbay, VAddedLastUsedMedbay,
VAddedSquads, VAddedSquads,
VAddedSquadInvites,
VMax, // this minus one will be the version used VMax, // this minus one will be the version used
}; };
@ -810,6 +811,14 @@ SerMaybeFailure ser_inputframe(SerState* ser, InputFrame* i)
SER_VAR(&i->id); SER_VAR(&i->id);
SER_MAYBE_RETURN(ser_V2(ser, &i->movement)); SER_MAYBE_RETURN(ser_V2(ser, &i->movement));
SER_VAR(&i->take_over_squad); SER_VAR(&i->take_over_squad);
SER_ASSERT(i->take_over_squad >= 0 || i->take_over_squad == -1);
SER_ASSERT(i->take_over_squad < SquadLast);
if (ser->version >= VAddedSquadInvites)
{
SER_VAR(&i->accept_cur_squad_invite);
SER_VAR(&i->reject_cur_squad_invite);
SER_MAYBE_RETURN(ser_entityid(ser, &i->invite_this_player));
}
SER_VAR(&i->seat_action); SER_VAR(&i->seat_action);
SER_MAYBE_RETURN(ser_entityid(ser, &i->seat_to_inhabit)); SER_MAYBE_RETURN(ser_entityid(ser, &i->seat_to_inhabit));
@ -831,7 +840,7 @@ SerMaybeFailure ser_player(SerState* ser, Player* p)
if (p->connected) if (p->connected)
{ {
SER_VAR(&p->unlocked_bombs); SER_VAR(&p->unlocked_bombs);
if(ser->version >= VAddedSquads) if (ser->version >= VAddedSquads)
SER_VAR(&p->squad); SER_VAR(&p->squad);
SER_MAYBE_RETURN(ser_entityid(ser, &p->entity)); SER_MAYBE_RETURN(ser_entityid(ser, &p->entity));
if (ser->version >= VAddedLastUsedMedbay) if (ser->version >= VAddedLastUsedMedbay)
@ -915,9 +924,12 @@ SerMaybeFailure ser_entity(SerState* ser, GameState* gs, Entity* e)
if (e->is_player) if (e->is_player)
{ {
SER_ASSERT(e->no_save_to_disk); SER_ASSERT(e->no_save_to_disk);
SER_MAYBE_RETURN(ser_entityid(ser, &e->currently_inside_of_box)); SER_MAYBE_RETURN(ser_entityid(ser, &e->currently_inside_of_box));
if(ser->version >= VAddedSquads) if (ser->version >= VAddedSquads)
SER_VAR(&e->presenting_squad); SER_VAR(&e->presenting_squad);
if (ser->version >= VAddedSquadInvites)
SER_VAR(&e->squad_invited_to);
SER_VAR(&e->goldness); SER_VAR(&e->goldness);
} }
@ -1495,6 +1507,15 @@ void process(GameState* gs, float dt)
} }
player->input.take_over_squad = -1; player->input.take_over_squad = -1;
} }
// squad invites
Entity* possibly_to_invite = get_entity(gs, player->input.invite_this_player);
if (player->input.invite_this_player.generation > 0)
player->input.invite_this_player = (EntityID){ 0 }; // just in case
if (player->squad != SquadNone && possibly_to_invite != NULL && possibly_to_invite->is_player)
{
possibly_to_invite->squad_invited_to = player->squad;
}
Entity* p = get_entity(gs, player->entity); Entity* p = get_entity(gs, player->entity);
if (p == NULL) if (p == NULL)
{ {
@ -1511,6 +1532,21 @@ void process(GameState* gs, float dt)
assert(p->is_player); assert(p->is_player);
p->presenting_squad = player->squad; p->presenting_squad = player->squad;
if (p->squad_invited_to != SquadNone)
{
if (player->input.accept_cur_squad_invite)
{
player->squad = p->squad_invited_to;
p->squad_invited_to = SquadNone;
player->input.accept_cur_squad_invite = false;
}
if (player->input.reject_cur_squad_invite)
{
p->squad_invited_to = SquadNone;
player->input.reject_cur_squad_invite = false;
}
}
#ifdef INFINITE_RESOURCES #ifdef INFINITE_RESOURCES
p->damage = 0.0f; p->damage = 0.0f;
#endif #endif
@ -1657,7 +1693,7 @@ void process(GameState* gs, float dt)
} }
p->damage = clamp01(p->damage); p->damage = clamp01(p->damage);
} }
if (get_entity(gs, gs->cur_spacestation) == NULL) if (get_entity(gs, gs->cur_spacestation) == NULL)
{ {

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

851
main.c

File diff suppressed because it is too large Load Diff

@ -299,6 +299,14 @@ void server(void* info_raw)
// prevents setting the event input to false before it's been processed. // prevents setting the event input to false before it's been processed.
if (cur_input.take_over_squad >= 0) if (cur_input.take_over_squad >= 0)
gs.players[player_slot].input.take_over_squad = cur_input.take_over_squad; gs.players[player_slot].input.take_over_squad = cur_input.take_over_squad;
if (cur_input.accept_cur_squad_invite)
gs.players[player_slot].input.accept_cur_squad_invite = cur_input.accept_cur_squad_invite;
if (cur_input.reject_cur_squad_invite)
gs.players[player_slot].input.reject_cur_squad_invite = cur_input.reject_cur_squad_invite;
if (cur_input.invite_this_player.generation > 0)
{
gs.players[player_slot].input.invite_this_player = cur_input.invite_this_player;
}
if (cur_input.seat_action) if (cur_input.seat_action)
{ {
gs.players[player_slot].input.seat_action = cur_input.seat_action; gs.players[player_slot].input.seat_action = cur_input.seat_action;

@ -143,8 +143,8 @@ static bool entityids_same(EntityID a, EntityID b)
return (a.generation == b.generation) && (a.index == b.index); return (a.generation == b.generation) && (a.index == b.index);
} }
// when updated, must update serialization, AND comparison // when updated, must update serialization, comparison in main.c, and the server
// function in main.c // on input received processing function
typedef struct InputFrame typedef struct InputFrame
{ {
uint64_t tick; uint64_t tick;
@ -152,6 +152,9 @@ typedef struct InputFrame
V2 movement; V2 movement;
int take_over_squad; // -1 means not taking over any squad int take_over_squad; // -1 means not taking over any squad
bool accept_cur_squad_invite;
bool reject_cur_squad_invite;
EntityID invite_this_player; // null means inviting nobody! @Robust make it so just sends interact pos input, and server processes who to invite. This depends on client side prediction + proper input processing at the right tick.
bool seat_action; bool seat_action;
EntityID seat_to_inhabit; EntityID seat_to_inhabit;
@ -186,6 +189,7 @@ typedef struct Entity
bool is_player; bool is_player;
enum Squad presenting_squad; enum Squad presenting_squad;
EntityID currently_inside_of_box; EntityID currently_inside_of_box;
enum Squad squad_invited_to; // if squad none, then no squad invite
float goldness; // how much the player is a winner float goldness; // how much the player is a winner
// explosion // explosion
@ -457,6 +461,17 @@ typedef struct AABB
float x, y, width, height; float x, y, width, height;
} AABB; } AABB;
static AABB centered_at(V2 point, V2 size)
{
return (AABB)
{
.x = point.x - size.x / 2.0f,
.y = point.y - size.y / 2.0f,
.width = size.x,
.height = size.y,
};
}
static bool has_point(AABB aabb, V2 point) static bool has_point(AABB aabb, V2 point)
{ {
return point.x > aabb.x && point.x < aabb.x + aabb.width && point.y > aabb.y && point.y < aabb.y + aabb.height; return point.x > aabb.x && point.x < aabb.x + aabb.width && point.y > aabb.y && point.y < aabb.y + aabb.height;

Loading…
Cancel
Save