Skip to content

Commit 4b43325

Browse files
committed
Make warp core ejection require two crew members
Signed-off-by: Stephen M. Cameron <[email protected]>
1 parent 5ca4dbf commit 4b43325

File tree

5 files changed

+72
-6
lines changed

5 files changed

+72
-6
lines changed

snis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "shape_collision.h"
4242

4343
#define DEFAULT_SOLAR_SYSTEM "default"
44-
#define SNIS_PROTOCOL_VERSION "SNIS063"
44+
#define SNIS_PROTOCOL_VERSION "SNIS064"
4545
#define COMMON_MTWIST_SEED 97872
4646
/* dimensions of the "known" universe */
4747
#define XKNOWN_DIM 600000.0

snis_client.c

+23-4
Original file line numberDiff line numberDiff line change
@@ -12493,6 +12493,8 @@ int nav_ui_lights_active(__attribute__((unused)) void *notused)
1249312493
return o->tsd.ship.exterior_lights;
1249412494
}
1249512495

12496+
static void eject_warp_core_button_pressed(void *x);
12497+
1249612498
static void init_nav_ui(void)
1249712499
{
1249812500
int x, y;
@@ -12577,6 +12579,14 @@ static void init_nav_ui(void)
1257712579
snis_button_set_sound(nav_ui.lights_button, UISND7);
1257812580
snis_button_set_hover_color(nav_ui.lights_button, hover_color);
1257912581
y += button_y_spacing;
12582+
nav_ui.eject_warp_core_button = snis_button_init(SCREEN_WIDTH - txx(nav_ui.gauge_radius * 2.2 + 10),
12583+
txy(nav_ui.gauge_radius * 2 + y), -1, -1, "EJECT WARP CORE",
12584+
button_color,
12585+
NANO_FONT, eject_warp_core_button_pressed,
12586+
(void *) (intptr_t) DISPLAYMODE_NAVIGATION);
12587+
snis_button_set_sound(nav_ui.eject_warp_core_button, UISND7);
12588+
snis_button_set_hover_color(nav_ui.eject_warp_core_button, hover_color);
12589+
y += button_y_spacing;
1258012590
nav_ui.custom_button = snis_button_init(SCREEN_WIDTH - txx(nav_ui.gauge_radius * 2.2 + 10),
1258112591
txy(nav_ui.gauge_radius * 2 + y), -1, -1, "CUSTOM BUTTON",
1258212592
button_color,
@@ -12617,6 +12627,10 @@ static void init_nav_ui(void)
1261712627
"SWITCH BETWEEN NAVIGATION\nAND STAR MAP SCREENS");
1261812628
ui_add_button(nav_ui.lights_button, DISPLAYMODE_NAVIGATION,
1261912629
"TOGGLE EXTERIOR LIGHTS ON/OFF");
12630+
ui_add_button(nav_ui.eject_warp_core_button, DISPLAYMODE_NAVIGATION,
12631+
"EJECT THE WARP CORE\n"
12632+
"(WITH CONFIRMATION FROM\n"
12633+
"ENGINEERING)");
1262012634
ui_add_button(nav_ui.custom_button, DISPLAYMODE_NAVIGATION, "CUSTOM BUTTON");
1262112635
ui_add_button(nav_ui.reverse_button, DISPLAYMODE_NAVIGATION,
1262212636
"TOGGLE REVERSE THRUST");
@@ -14107,9 +14121,11 @@ static void robot_manual_button_pressed(__attribute__((unused)) void *x)
1410714121
queue_to_server(snis_opcode_pkt("bb", OPCODE_ROBOT_AUTO_MANUAL, DAMCON_ROBOT_MANUAL_MODE));
1410814122
}
1410914123

14110-
static void eject_warp_core_button_pressed(__attribute__((unused)) void *x)
14124+
static void eject_warp_core_button_pressed(void *x)
1411114125
{
14112-
queue_to_server(snis_opcode_pkt("b", OPCODE_EJECT_WARP_CORE));
14126+
intptr_t v = (intptr_t) x;
14127+
unsigned char which = v & 0xff;
14128+
queue_to_server(snis_opcode_pkt("bb", OPCODE_EJECT_WARP_CORE, which));
1411314129
return;
1411414130
}
1411514131

@@ -14162,7 +14178,7 @@ static void init_damcon_ui(void)
1416214178
snis_button_set_sound(damcon_ui.robot_manual_button, UISND25);
1416314179
damcon_ui.eject_warp_core_button = snis_button_init(txx(300), txy(30), txx(90), txy(25),
1416414180
"EJECT WARP CORE", UI_COLOR(damcon_button), NANO_FONT,
14165-
eject_warp_core_button_pressed, (void *) 0);
14181+
eject_warp_core_button_pressed, (void *) (intptr_t) DISPLAYMODE_DAMCON);
1416614182
snis_button_set_hover_color(damcon_ui.eject_warp_core_button, hover_color);
1416714183
snis_button_set_sound(damcon_ui.eject_warp_core_button, UISND12); /* FIXME: custom sound here */
1416814184

@@ -14176,7 +14192,10 @@ static void init_damcon_ui(void)
1417614192
ui_add_button(damcon_ui.robot_auto_button, DISPLAYMODE_DAMCON, "SELECT AUTONOMOUS ROBOT OPERATION");
1417714193
ui_add_button(damcon_ui.robot_manual_button, DISPLAYMODE_DAMCON, "SELECT MANUAL ROBOT CONTROL");
1417814194
ui_add_label(damcon_ui.robot_controls, DISPLAYMODE_DAMCON);
14179-
ui_add_button(damcon_ui.eject_warp_core_button, DISPLAYMODE_DAMCON, "EJECT THE WARP CORE");
14195+
ui_add_button(damcon_ui.eject_warp_core_button, DISPLAYMODE_DAMCON,
14196+
"EJECT THE WARP CORE\n"
14197+
"(WITH CONFIRMATION\n"
14198+
"FROM NAVIGATION)");
1418014199
}
1418114200

1418214201
static int process_custom_button(void)

snis_opcode_def.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int snis_opcode_def_init(void)
110110
rc |= init_opcode_def(OPCODE_ECON_UPDATE_SHIP, "bwwSSSQbbb");
111111
/* rc |= init_opcode_def(OPCODE_SHIP_SDATA, "bwbbbbbbbbr"); */
112112
rc |= init_opcode_def(OPCODE_LOAD_TORPEDO, "b");
113-
rc |= init_opcode_def(OPCODE_EJECT_WARP_CORE, "b");
113+
rc |= init_opcode_def(OPCODE_EJECT_WARP_CORE, "bb");
114114
rc |= init_opcode_def(OPCODE_ENGAGE_WARP, "bwb");
115115
rc |= init_opcode_def(OPCODE_ROLE_ONSCREEN, "bb");
116116
rc |= init_opcode_def(OPCODE_SCI_SELECT_TARGET, "bbw");

snis_server.c

+46
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ static struct bridge_data {
648648
uint32_t last_missile_fail_time; /* universe timestamp of last missile failure */
649649
int enforce_solarsystem;
650650
char resident_solarsystem[SSGL_LOCATIONSIZE];
651+
int warp_core_ejection_armed;
652+
int warp_core_ejection_confirm_countdown;
651653
} bridgelist[MAXCLIENTS];
652654
static int nbridges = 0; /* Number of elements present in bridgelist[] */
653655
static int announce_players = 0; /* Announce new players via TTS? */
@@ -10102,6 +10104,24 @@ static void maybe_reboot_terminals(struct snis_entity *player_ship)
1010210104
reboot_random_terminals(player_ship);
1010310105
}
1010410106

10107+
static void update_warp_ejection_countdown(struct snis_entity *o)
10108+
{
10109+
int bn = lookup_bridge_by_shipid(o->id);
10110+
if (bn < 0)
10111+
return;
10112+
/* If armed, decrement count down, if countdown hits zero before confirmation, disarm. */
10113+
if (bridgelist[bn].warp_core_ejection_armed == -1)
10114+
return;
10115+
10116+
if (bridgelist[bn].warp_core_ejection_confirm_countdown > 0)
10117+
bridgelist[bn].warp_core_ejection_confirm_countdown--;
10118+
if (bridgelist[bn].warp_core_ejection_confirm_countdown == 0) {
10119+
bridgelist[bn].warp_core_ejection_armed = -1;
10120+
snis_queue_add_text_to_speech("Warp core ejection sequence aborted.",
10121+
ROLE_TEXT_TO_SPEECH, o->id);
10122+
}
10123+
}
10124+
1010510125
static void aim_high_gain_antenna(struct snis_entity *o)
1010610126
{
1010710127
union vec3 straight_ahead = { { 1.0, 0.0, 0.0 } };
@@ -10365,6 +10385,7 @@ static void player_move(struct snis_entity *o)
1036510385
}
1036610386
check_science_selection(o);
1036710387
maybe_reboot_terminals(o);
10388+
update_warp_ejection_countdown(o);
1036810389

1036910390
update_flare_cooldown_timer(o);
1037010391

@@ -11566,6 +11587,8 @@ static void init_player(struct snis_entity *o)
1156611587
memset(bridgelist[b].guessed_key, '_', sizeof(bridgelist[b].guessed_key));
1156711588
memset(bridgelist[b].enciphered_message, 0, sizeof(bridgelist[b].enciphered_message));
1156811589
bridgelist[b].flare_cooldown = 0;
11590+
bridgelist[b].warp_core_ejection_confirm_countdown = 0; /* not counting */
11591+
bridgelist[b].warp_core_ejection_armed = -1; /* not armed */
1156911592
}
1157011593
quat_init_axis(&o->tsd.ship.computer_desired_orientation, 0, 1, 0, 0);
1157111594
o->tsd.ship.computer_steering_time_left = 0;
@@ -23614,12 +23637,33 @@ static int process_eject_warp_core(struct game_client *c)
2361423637
struct snis_entity *ship = &go[c->ship_index];
2361523638
union vec3 relvel = { { 1.0, 0.0, 0.0, }, };
2361623639
int b = c->bridge;
23640+
unsigned char which;
23641+
unsigned char buffer[10];
23642+
int rc;
23643+
23644+
rc = read_and_unpack_buffer(c, buffer, "b", &which);
23645+
if (rc != 0)
23646+
return -1;
2361723647

2361823648
if (ship->tsd.ship.warp_core_status == WARP_CORE_STATUS_EJECTED) {
2361923649
snis_queue_add_text_to_speech("The warp core has already been ejected.",
2362023650
ROLE_TEXT_TO_SPEECH, ship->id);
2362123651
return 0; /* Warp core is already ejected */
2362223652
}
23653+
23654+
if (bridgelist[b].warp_core_ejection_armed == -1) { /* not armed */
23655+
bridgelist[b].warp_core_ejection_armed = which; /* which person pressed eject 1st time. */
23656+
bridgelist[b].warp_core_ejection_confirm_countdown = 10 * 10; /* 10 seconds */
23657+
snis_queue_add_text_to_speech("Warp core ejection sequence armed.",
23658+
ROLE_TEXT_TO_SPEECH, ship->id);
23659+
return 0;
23660+
} else if (bridgelist[b].warp_core_ejection_armed == which) { /* the same person pressed eject again */
23661+
/* Do nothing. */
23662+
return 0;
23663+
}
23664+
bridgelist[b].warp_core_ejection_armed = -1; /* reset for next time */
23665+
bridgelist[b].warp_core_ejection_confirm_countdown = 0;
23666+
2362323667
snis_queue_add_text_to_speech("Ejecting the warp core.", ROLE_TEXT_TO_SPEECH, ship->id);
2362423668
quat_rot_vec_self(&relvel, &ship->orientation);
2362523669
add_warp_core(ship->x, ship->y, ship->z,
@@ -26003,6 +26047,8 @@ static int add_new_player(struct game_client *c, int enforce_solarsystem)
2600326047
bridgelist[nbridges].active_custom_buttons = 0;
2600426048
bridgelist[nbridges].last_missile_fail_time = 0;
2600526049
bridgelist[nbridges].enforce_solarsystem = enforce_solarsystem;
26050+
bridgelist[nbridges].warp_core_ejection_armed = -1;
26051+
bridgelist[nbridges].warp_core_ejection_confirm_countdown = 0;
2600626052
memset(bridgelist[nbridges].custom_button_text, 0, sizeof(bridgelist[nbridges].custom_button_text));
2600726053
memset(bridgelist[nbridges].cipher_key, '_', sizeof(bridgelist[nbridges].cipher_key));
2600826054
memset(bridgelist[nbridges].guessed_key, '_', sizeof(bridgelist[nbridges].guessed_key));

snis_ui.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct navigation_ui {
3838
struct button *starmap_button;
3939
struct button *lights_button;
4040
struct button *camera_pos_button;
41+
struct button *eject_warp_core_button;
4142
struct button *custom_button;
4243
int gauge_radius;
4344
struct snis_text_input_box *computer_input;

0 commit comments

Comments
 (0)