Skip to content

Commit

Permalink
allow selectable equipment for fighters
Browse files Browse the repository at this point in the history
TODO: add the actual equipment
  • Loading branch information
Piglit committed Aug 12, 2023
1 parent 5b0b3a1 commit 143b468
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
33 changes: 27 additions & 6 deletions src/GMActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void GameMasterActions::onReceiveClientCommand(int32_t client_id, sp::io::DataBu

void GameMasterActions::equipFighter(P<PlayerSpaceship> ship, sp::io::DataBuffer& packet)
{
string callsign, password, color, model;
packet >> callsign >> password >> color >> model;
string callsign, password, color, model, equipment;
packet >> callsign >> password >> color >> model >> equipment;

if (callsign != "")
ship->setCallSign(callsign);
Expand All @@ -85,6 +85,27 @@ void GameMasterActions::equipFighter(P<PlayerSpaceship> ship, sp::io::DataBuffer
ship->setColor(color);
if (model != "")
ship->setModel(model);
string old_equipment = ship->getEquipment();
if (equipment != "" && equipment != old_equipment)
{
LOG(DEBUG) << "EQUIPMENT strip: " << old_equipment << "\tequip:" << equipment;
// strip old equipment
if (old_equipment == "test")
{}
else if (old_equipment == "beams")
{}
else if (old_equipment == "missiles")
{}

// place new equipment
if (equipment == "test")
{}
else if (equipment == "beams")
{}
else if (equipment == "missiles")
{}
ship->setEquipment(equipment);
}
}

void GameMasterActions::commandRunScript(string code)
Expand All @@ -99,15 +120,15 @@ void GameMasterActions::commandSendGlobalMessage(string message)
packet << CMD_SEND_GLOBAL_MESSAGE << message;
sendClientCommand(packet);
}
void GameMasterActions::commandCreateFighter(string ship_template, int32_t parent_id, string callsign, string password, string color, string model)
void GameMasterActions::commandCreateFighter(string ship_template, int32_t parent_id, string callsign, string password, string color, string model, string equipment)
{
sp::io::DataBuffer packet;
packet << CMD_CREATE_FIGHTER << ship_template << parent_id << callsign << password << color<< model;
packet << CMD_CREATE_FIGHTER << ship_template << parent_id << callsign << password << color<< model << equipment;
sendClientCommand(packet);
}
void GameMasterActions::commandEquipFighter(int32_t ship_id, string callsign, string password, string color, string model)
void GameMasterActions::commandEquipFighter(int32_t ship_id, string callsign, string password, string color, string model, string equipment)
{
sp::io::DataBuffer packet;
packet << CMD_EQUIP_FIGHTER << ship_id << callsign << password << color << model;
packet << CMD_EQUIP_FIGHTER << ship_id << callsign << password << color << model << equipment;
sendClientCommand(packet);
}
4 changes: 2 additions & 2 deletions src/GMActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class GameMasterActions : public MultiplayerObject

void commandRunScript(string code);
void commandSendGlobalMessage(string message);
void commandCreateFighter(string ship_template, int32_t parent_id, string callsign, string password, string color, string model);
void commandEquipFighter(int32_t ship_id, string callsign, string password, string color, string model);
void commandCreateFighter(string ship_template, int32_t parent_id, string callsign, string password, string color, string model, string equipment);
void commandEquipFighter(int32_t ship_id, string callsign, string password, string color, string model, string equipment);
virtual void onReceiveClientCommand(int32_t client_id, sp::io::DataBuffer& packet) override;
private:
void equipFighter(P<PlayerSpaceship> ship, sp::io::DataBuffer& packet);
Expand Down
39 changes: 35 additions & 4 deletions src/screens/extra/hangar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ HangarScreen::HangarScreen(GuiContainer* owner)
password_entry->setText(ship->control_code);
string color = ship->getColor();
string hull = ship->getTypeName();
string equipment = ship->getEquipment();
hull_selector->setSelectionIndex(hull_selector->indexByValue(hull));
getAvailableEquipment(hull);
color_selector->setSelectionIndex(color_selector->indexByValue(color));
equipment_selector->setSelectionIndex(equipment_selector->indexByValue(equipment));

P<ShipTemplate> ship_template = ShipTemplate::getTemplate(ship->getTypeName());
if(ship_template)
Expand Down Expand Up @@ -116,6 +119,8 @@ HangarScreen::HangarScreen(GuiContainer* owner)

hull_selector->setSelectionIndex(0);
color_selector->setSelectionIndex(0);
getAvailableEquipment(hull_selector->getSelectionValue());
equipment_selector->setSelectionIndex(0);
P<ShipTemplate> ship_template = ShipTemplate::getTemplate(hull_selector->getSelectionValue());
if(ship_template)
{
Expand Down Expand Up @@ -173,6 +178,8 @@ HangarScreen::HangarScreen(GuiContainer* owner)
(new GuiLabel(row, "HULL_LABEL", tr("Hull: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(left_col_width, GuiElement::GuiSizeMax);
hull_selector = new GuiSelector(row, "HULL_SELECTOR", [this](int index, string value)
{
getAvailableEquipment(value);
equipment_selector->setSelectionIndex(0);
P<ShipTemplate> ship_template = ShipTemplate::getTemplate(value);
if(ship_template)
{
Expand Down Expand Up @@ -208,9 +215,20 @@ HangarScreen::HangarScreen(GuiContainer* owner)
color_selector->setOptions({"White", "Yellow", "Blue", "Red", "Green", "Grey"})->setSelectionIndex(0);
color_selector->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// Equipment row
row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "EQUIPMENT_LABEL", tr("Equipment: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(left_col_width, GuiElement::GuiSizeMax);
equipment_selector= new GuiSelector(row, "EQUIPMENT_SELECTOR", [this](int index, string value)
{
equipFighter();
});
equipment_selector->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);


// info
row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 400)->setAttribute("layout", "horizontal");
row->setSize(GuiElement::GuiSizeMax, 350)->setAttribute("layout", "horizontal");
playership_info = new GuiScrollText(row, "PLAYERSHIP_INFO", tr("Ship info..."));
playership_info->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

Expand Down Expand Up @@ -240,7 +258,7 @@ HangarScreen::HangarScreen(GuiContainer* owner)
string templ = hull_selector->getSelectionValue();
string callsign = callsign_entry->getText();
string model_name = getModelName(hull_selector->getSelectionValue(), color_selector->getSelectionValue());
gameMasterActions->commandCreateFighter(templ, my_spaceship->getMultiplayerId(), callsign, password_entry->getText(), color_selector->getSelectionValue(), model_name);
gameMasterActions->commandCreateFighter(templ, my_spaceship->getMultiplayerId(), callsign, password_entry->getText(), color_selector->getSelectionValue(), model_name, equipment_selector->getSelectionValue());
creating_fighter = false;
fighter_create_dialog->hide();
select_fighter_label->show();
Expand All @@ -267,7 +285,7 @@ void HangarScreen::equipFighter()
{
model_name = getModelName(hull_selector->getSelectionValue(), color_selector->getSelectionValue());
}
gameMasterActions->commandEquipFighter(id, callsign, password_entry->getText(), color_selector->getSelectionValue(), model_name);
gameMasterActions->commandEquipFighter(id, callsign, password_entry->getText(), color_selector->getSelectionValue(), model_name, equipment_selector->getSelectionValue());
}
}
}
Expand All @@ -281,6 +299,19 @@ void HangarScreen::displayModel()
model_view->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
}

void HangarScreen::getAvailableEquipment(string template_name)
{
if (template_name == "MP52 Hornet")
equipment_selector->setOptions({"None", "test", "beams"});
else if (template_name == "ZX-Lindworm")
equipment_selector->setOptions({"None", "test", "missiles"});
else if (template_name == "Ryu")
equipment_selector->setOptions({});
else
equipment_selector->setOptions({"None"});

}

string HangarScreen::getModelName(string template_name, string color){
string prefix = "";
if (template_name == "MP52 Hornet")
Expand All @@ -302,7 +333,7 @@ void HangarScreen::onUpdate()
for(int n = 0; n < GameGlobalInfo::max_player_ships; n++)
{
P<PlayerSpaceship> ship = gameGlobalInfo->getPlayerShip(n);
// idDocked works only on server, since docking_target is only valid on server
// ifDocked works only on server, since docking_target is only valid on server
if (ship && ship->isDocked(my_spaceship) && my_spaceship->canBeDockedBy(ship) == DockStyle::Internal)
{
string ship_name = ship->getTypeName() + " " + ship->getCallSign();
Expand Down
7 changes: 7 additions & 0 deletions src/screens/extra/hangar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,33 @@ class HangarScreen: public GuiOverlay
private:
GuiKeyValueDisplay* energy_display;
GuiKeyValueDisplay* info_reputation;

GuiToggleButton* shares_energy_with_docked_toggle;
GuiToggleButton* repairs_docked_toggle;
GuiToggleButton* restocks_scan_probes_toggle;
GuiToggleButton* restocks_weapons_toggle;

GuiListbox* player_ship_list;
GuiElement* fighter_create_dialog;
GuiLabel* select_fighter_label;
GuiButton* create_fighter_button;

GuiTextEntry* callsign_entry;
GuiTextEntry* password_entry;
GuiSelector* hull_selector;
GuiSelector* color_selector;
GuiSelector* equipment_selector;

GuiScrollText* playership_info;
GuiElement* playership_visual;
GuiRotatingModelView* model_view = nullptr;

GuiButton* abort_button;
GuiButton* create_ship_button;

bool creating_fighter;
string getModelName(string template_name, string color);
void getAvailableEquipment(string template_name);
void equipFighter();
void displayModel();
public:
Expand Down
2 changes: 2 additions & 0 deletions src/spaceObjects/playerSpaceship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ PlayerSpaceship::PlayerSpaceship()
shields_active = false;
control_code = "";
color = "";
equipment = "";


setFactionId(1);
Expand Down Expand Up @@ -605,6 +606,7 @@ PlayerSpaceship::PlayerSpaceship()
registerMemberReplication(&linked_science_probe_id);
registerMemberReplication(&control_code);
registerMemberReplication(&color);
registerMemberReplication(&equipment);
registerMemberReplication(&custom_functions);

// Determine which stations must provide self-destruct confirmation codes.
Expand Down
7 changes: 6 additions & 1 deletion src/spaceObjects/playerSpaceship.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class PlayerSpaceship : public SpaceShip
// Password to join a ship. Default is empty.
string control_code;
string color;
string equipment;

private:
bool on_new_player_ship_called=false;
Expand Down Expand Up @@ -346,10 +347,14 @@ class PlayerSpaceship : public SpaceShip
// Ship control code/password setter
void setControlCode(string code) { control_code = code.upper(); }

// Set Color
// Set color
void setColor(string col) { color = col; }
string getColor() { return color; }

// Set equipment
void setEquipment(string eq) { equipment = eq; }
string getEquipment() { return equipment; }

// Radar function
virtual void drawOnGMRadar(sp::RenderTarget& renderer, glm::vec2 position, float scale, float rotation, bool long_range) override;

Expand Down

0 comments on commit 143b468

Please sign in to comment.