Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
royfalk committed Dec 5, 2024
2 parents a86672e + a1b6300 commit 4ac74e8
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 125 deletions.
4 changes: 2 additions & 2 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ENDIF ()
# This is an incrementing number similar to the Google Android API Version
# allowing us to differentiate our Assets API across multiple versions.
# If a release is missing this value, then version `1` can be assumed.
SET(VEGASTRIKE_ASSETS_API_VERSION "2")
SET(VEGASTRIKE_ASSETS_API_VERSION "3")

#IF (COMMAND cmake_policy)
# CMAKE_POLICY (SET CMP0003 NEW)
Expand Down Expand Up @@ -778,7 +778,7 @@ SET(LIBPYTHON_SOURCES
src/python/unit_wrapper.cpp
src/python/universe_util_export.cpp

src/python/base_computer/ship_view.cpp
src/python/infra/get_string.cpp
)

SET(LIBSCRIPT_SOURCES
Expand Down
130 changes: 41 additions & 89 deletions engine/src/cmd/basecomputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ using VSFileSystem::SaveFile;
#include "facet_configuration.h"
#include "vs_logging.h"
#include "controls_factory.h"
#include "python/infra/get_string.h"

#include <boost/python.hpp>
#include "configuration/configuration.h"
#include "python/base_computer/ship_view.h"

//for directory thing
#if defined (_WIN32) && !defined (__CYGWIN__)
Expand All @@ -79,6 +81,12 @@ using VSFileSystem::SaveFile;
#include <sys/stat.h>
#include "vega_cast_utils.h"

// Can't declare in header because PyObject is problematic
extern const std::string GetString(const std::string function_name,
const std::string module_name,
const std::string file_name,
PyObject* args);

using namespace XMLSupport; // FIXME -- Shouldn't include an entire namespace, according to Google Style Guide -- stephengtuggy 2021-09-07

//end for directory thing
Expand Down Expand Up @@ -3931,22 +3939,11 @@ string buildShipDescription(Cargo &item, std::string &texturedescription) {

//UNDER CONSTRUCTION
string buildUpgradeDescription(Cargo &item) {
//load the Unit
string blnk; //modifications to an upgrade item???
Flightgroup *flightGroup = new Flightgroup(); //sigh
int fgsNumber = 0;
current_unit_load_mode = NO_MESH;
Unit *newPart = new Unit(item.GetName().c_str(), false,
FactionUtil::GetUpgradeFaction(), blnk, flightGroup, fgsNumber);
current_unit_load_mode = DEFAULT;
string str = "";
str += item.GetDescription();

showUnitStats(newPart, str, 0, 1, item);

newPart->Kill();
// delete newPart;
return str;
const std::string key = item.GetName() + "__upgrades";
PyObject* args = PyTuple_Pack(1, PyUnicode_FromString(key.c_str()));
const std::string text = GetString("get_upgrade_info", "upgrade_view",
"python/base_computer/upgrade_view.py", args);
return text;
}

class PriceSort {
Expand Down Expand Up @@ -4476,86 +4473,39 @@ static std::string factionColorTextString(int faction) {
return result;
}


// A utility to convert vector to list
boost::python::list VectorToList(const std::vector<std::string> v) {
boost::python::list l;
for (const std::string& value : v) {
l.append(value);
}

return l;
}

//Show the player's basic information.
bool BaseComputer::showPlayerInfo(const EventCommandId &command, Control *control) {
//Heading.
string text = "#b#Factions:#-b#n1.7#";

//Number of kills for each faction.
vector<float> *killList = &_Universe->AccessCockpit()->savegame->getMissionData(string("kills"));

//Make everything bold.
text += "#b#";

//A line for each faction.
const size_t numFactions = FactionUtil::GetNumFactions();
size_t i = 0;
static string disallowedFactions = vs_config->getVariable("graphics", "unprintable_factions", "");
int totkills = 0;
size_t fac_loc_before = 0, fac_loc = 0, fac_loc_after = 0;
for (; i < numFactions; i++) {
Unit *currentplayer = UniverseUtil::getPlayerX(UniverseUtil::getCurrentPlayer());
float relation = 0;
size_t upgrades = FactionUtil::GetUpgradeFaction();
size_t planets = FactionUtil::GetPlanetFaction();
static size_t privateer = FactionUtil::GetFactionIndex("privateer");
size_t neutral = FactionUtil::GetNeutralFaction();
if (i < killList->size() && i != upgrades && i != planets && i != neutral && i != privateer) {
totkills += (int) (*killList)[i];
}
string factionname = FactionUtil::GetFactionName(i);
fac_loc_after = 0;
fac_loc = disallowedFactions.find(factionname, fac_loc_after);
while (fac_loc != string::npos) {
if (fac_loc > 0) {
fac_loc_before = fac_loc - 1;
} else {
fac_loc_before = 0;
}
fac_loc_after = fac_loc + factionname.size();
if ((fac_loc == 0 || disallowedFactions[fac_loc_before] == ' '
|| disallowedFactions[fac_loc_before] == '\t')
&& (disallowedFactions[fac_loc_after] == ' ' || disallowedFactions[fac_loc_after] == '\t'
|| disallowedFactions[fac_loc_after] == '\0')) {
break;
}
fac_loc = disallowedFactions.find(factionname, fac_loc_after);
}
if (fac_loc != string::npos) {
continue;
}
if (currentplayer) {
relation = UnitUtil::getRelationFromFaction(currentplayer, i);
}
if (relation < -1) {
relation = -1;
}
if (relation > 1) {
relation = 1;
}
const int percent = (int) (relation * 100.0);
vector<float> *kill_list = &_Universe->AccessCockpit()->savegame->getMissionData(string("kills"));

//Faction name.
text += factionColorTextString(i) + FactionUtil::GetFactionName(i) + ":#-c ";
const std::vector<std::string> names_vector = FactionUtil::GetFactionNames();
const std::vector<std::string> relations_vector = FactionUtil::GetFactionRelations();
const std::vector<std::string> kills_vector = FactionUtil::GetFactionKills(kill_list);

//Relation color.
float normRelation =
(relation + 1) / 2; //Move relation value into 0-1 range.
normRelation = guiMax(0, guiMin(1, normRelation)); //Make *sure* it's in the right range.
text += colorsToCommandString(1 - normRelation, normRelation, guiMin(1 - normRelation, normRelation));
boost::python::list names_list = VectorToList(names_vector);
boost::python::list relations_list = VectorToList(relations_vector);
boost::python::list kills_list = VectorToList(kills_vector);

//End the line.
text += XMLSupport::tostring(percent) + "#-c";
if (i < killList->size()) {
text += ", kills: " + XMLSupport::tostring((int) (*killList)[i]);
}
text += "#n#";
}
//Total Kills if we have it.
text += "#n##b#Total Kills: " + XMLSupport::tostring(totkills) + "#-b#";
PyObject* args = PyTuple_Pack(3, names_list.ptr(), relations_list.ptr(), kills_list.ptr());

const std::string text = GetString("get_player_info", "player_info",
"python/base_computer/player_info.py", args);

//Put this in the description.
StaticDisplay *desc = static_cast< StaticDisplay * > ( window()->findControlById("Description"));
assert(desc != NULL);

desc->setText(text);

return true;
Expand Down Expand Up @@ -4702,7 +4652,9 @@ void showUnitStats(Unit *playerUnit, string &text, int subunitlevel, int mode, C
}
if (!mode) {
std::map<std::string, std::string> ship_map = playerUnit->UnitToMap();
text += GetShipView(ship_map);
text += GetString("get_ship_description", "ship_view",
"python/base_computer/ship_view.py",
ship_map);
}
if (mode && replacement_mode == 2 && playerUnit->getMass() != blankUnit->getMass())
PRETTY_ADDU(statcolor + "Effective Mass reduced by: #-c", 100.0 * (1.0 - playerUnit->getMass()), 0, "%");
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/unit_csv_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const std::string keys[] = {"Key", "Directory", "Name", "Object_Type",
"FaceCamera", "Unit_Role", "Attack_Preference", "Hidden_Hold_Volume", "Equipment_Space",

// New stuff
"armor", "shield_strength", "shield_facets"
"armor", "shield_strength", "shield_facets", "accel"

};

Expand Down
23 changes: 15 additions & 8 deletions engine/src/components/drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,23 @@ void Drive::Load(std::string upgrade_key,
retro = Resource<double>(UnitCSVFactory::GetVariable(unit_key, "Retro_Accel", std::string("0.0")),
game_accel_speed, minimal_drive_functionality);

const double lateral_accel = 0.5 * UnitCSVFactory::GetVariable(unit_key, "Left_Accel", 0.0) +
double accel = UnitCSVFactory::GetVariable(unit_key, "accel", -1.0f);
if(accel != -1.0f) {
const std::string accel_string = std::to_string(accel);
lateral = Resource<double>(accel_string, game_accel_speed, minimal_drive_functionality);
vertical = Resource<double>(accel_string, game_accel_speed, minimal_drive_functionality);
} else {
const double lateral_accel = 0.5 * UnitCSVFactory::GetVariable(unit_key, "Left_Accel", 0.0) +
0.5 * UnitCSVFactory::GetVariable(unit_key, "Right_Accel", 0.0);
const std::string lateral_accel_string = std::to_string(lateral_accel);
lateral = Resource<double>(lateral_accel_string, game_accel_speed, minimal_drive_functionality);

const double vertical_accel = 0.5 * UnitCSVFactory::GetVariable(unit_key, "Top_Accel", 0.0) +
0.5 * UnitCSVFactory::GetVariable(unit_key, "Bottom_Accel", 0.0);
const std::string vertical_accel_string = std::to_string(vertical_accel);
vertical = Resource<double>(vertical_accel_string, game_accel_speed, minimal_drive_functionality);
const std::string lateral_accel_string = std::to_string(lateral_accel);
lateral = Resource<double>(lateral_accel_string, game_accel_speed, minimal_drive_functionality);

const double vertical_accel = 0.5 * UnitCSVFactory::GetVariable(unit_key, "Top_Accel", 0.0) +
0.5 * UnitCSVFactory::GetVariable(unit_key, "Bottom_Accel", 0.0);
const std::string vertical_accel_string = std::to_string(vertical_accel);
vertical = Resource<double>(vertical_accel_string, game_accel_speed, minimal_drive_functionality);
}

speed = Resource<double>(UnitCSVFactory::GetVariable(unit_key, "Default_Speed_Governor", std::string("0.0")),
game_speed, minimal_drive_functionality);
}
Expand Down
71 changes: 71 additions & 0 deletions engine/src/faction_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,74 @@ void Faction::ParseAllies(unsigned int thisfaction) {

}


const std::map<std::string, std::string> FactionUtil::GetRelationsMap(const int privateer_faction) {
std::map<std::string, std::string> relations;

for (int i = 0; i < (int)FactionUtil::GetNumFactions(); i++) {
float relation = FactionUtil::GetIntRelation(i, privateer_faction);
string faction_name = FactionUtil::GetFactionName(i);
const int percent = (int) (relation * 100.0);
relations.insert(std::pair<std::string, std::string>(faction_name, std::to_string(percent)));
}
return relations;
}

const std::map<std::string, std::string> FactionUtil::GetKillsMap(const std::vector<float> *kill_list) {
//Number of kills for each faction.
std::map<std::string, std::string> kills;
for (int i; i < (int)FactionUtil::GetNumFactions(); i++) {
string faction_name = FactionUtil::GetFactionName(i);
int kills_for_faction = 0;
size_t upgrades = FactionUtil::GetUpgradeFaction();
size_t planets = FactionUtil::GetPlanetFaction();
static size_t privateer = FactionUtil::GetFactionIndex("privateer");
size_t neutral = FactionUtil::GetNeutralFaction();
if (i < kill_list->size() && i != upgrades && i != planets && i != neutral && i != privateer) {
kills_for_faction = (int) (*kill_list)[i];
}

kills.insert(std::pair<std::string, std::string>(faction_name, std::to_string(kills_for_faction)));
}

return kills;
}

const std::vector<std::string> FactionUtil::GetFactionNames() {
std::vector<std::string> names;

for (int i = 0; i < factions.size(); i++) {
string faction_name = std::string(factions[i]->factionname);
names.push_back(faction_name);
}

return names;
}

const std::vector<std::string> FactionUtil::GetFactionRelations() {
static const int privateer_faction = FactionUtil::GetFactionIndex("privateer");

std::vector<std::string> relations;

for (int i = 0; i < factions.size(); i++) {
double relation = FactionUtil::GetIntRelation(i, privateer_faction);
relations.push_back(std::to_string(relation));
}

return relations;
}

const std::vector<std::string> FactionUtil::GetFactionKills(const std::vector<float> *kill_list) {
std::vector<std::string> kills;

for (int i = 0; i < factions.size(); i++) {
int kills_for_faction = 0;
if (i < (int)kill_list->size()) {
kills_for_faction = (int) (*kill_list)[i];
}

kills.push_back(std::to_string(kills_for_faction));
}

return kills;
}
9 changes: 9 additions & 0 deletions engine/src/faction_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#define VEGA_STRIKE_ENGINE_FACTION_GENERIC_H

#include <string>
#include <map>
#include <vector>
#include <boost/shared_ptr.hpp>
//#include <gnuhash.h>

Expand Down Expand Up @@ -179,6 +181,13 @@ Animation *GetRandExplosionAnimation(int whichfaction, std::string &which);
void LoadFactionPlaylists();
/** Still in faction_xml.cpp because createUnit **/
void LoadContrabandLists();

const std::map<std::string, std::string> GetRelationsMap(const int privateer_faction);
const std::map<std::string, std::string> GetKillsMap(const std::vector<float> *kill_list);

const std::vector<std::string> GetFactionNames();
const std::vector<std::string> GetFactionRelations();
const std::vector<std::string> GetFactionKills(const std::vector<float> *kill_list);
};

#endif //VEGA_STRIKE_ENGINE_FACTION_GENERIC_H
Expand Down
Loading

0 comments on commit 4ac74e8

Please sign in to comment.