Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Plugins/Public/base_plugin/ClientCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ void SendBaseStatus(uint client, PlayerBase* base)
{
base_status += L"<TEXT>Hit Points: Indestructible</TEXT><PARA/>";
}
base_status += L"<TEXT>Population: " + Int64ToPrettyStr((INT64)base->HasMarketItem(set_base_crew_type)) + L"</TEXT><PARA/>";
uint population = 0;
for (uint hash : humanCargoList)
{
population += base->HasMarketItem(hash);
}
base_status += L"<TEXT>Crew: " + Int64ToPrettyStr((INT64)base->HasMarketItem(set_base_crew_type)) + L"</TEXT><PARA/>";
base_status += L"<TEXT>Total population: " + Int64ToPrettyStr((INT64)population) + L"</TEXT><PARA/>";

if (single_vulnerability_window)
{
Expand Down
48 changes: 27 additions & 21 deletions Plugins/Public/base_plugin/CoreModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <hookext_exports.h>

CoreModule::CoreModule(PlayerBase* the_base) : Module(TYPE_CORE), base(the_base), space_obj(0), dont_eat(false),
dont_rust(false)
dont_rust(false), wasDamagedSinceLastUpdate(false), undergoingDestruction(false)
{
}

Expand Down Expand Up @@ -132,6 +132,9 @@ void CoreModule::Spawn()

pub::SpaceObj::SetRelativeHealth(space_obj, base->base_health / base->max_base_health);

base->baseCSolar = (CSolar*)CObject::Find(space_obj, CObject::CSOLAR_OBJECT);
base->baseCSolar->Release();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh we should not be calling release on something we just shoved into our object


if (shield_reinforcement_threshold_map.count(base->base_level))
base->base_shield_reinforcement_threshold = shield_reinforcement_threshold_map[base->base_level];
else
Expand Down Expand Up @@ -248,13 +251,6 @@ bool CoreModule::Timer(uint time)
return false;
}

// if health is 0 then the object will be destroyed but we won't
// receive a notification of this so emulate it.
if (base->base_health < 1)
{
return SpaceObjDestroyed(space_obj);
}

if ((base->logic == 0) && (base->invulnerable == 1))
{
return false;
Expand All @@ -269,7 +265,7 @@ bool CoreModule::Timer(uint time)
float no_crew_penalty = isCrewSufficient ? 1.0f : no_crew_damage_multiplier;
// Reduce hitpoints to reflect wear and tear. This will eventually
// destroy the base unless it is able to repair itself.
float damage_taken = (set_damage_per_tick * base->base_level) * no_crew_penalty;
float damage_taken = set_damage_per_tick * no_crew_penalty;
base->base_health -= damage_taken;
}

Expand All @@ -287,6 +283,7 @@ bool CoreModule::Timer(uint time)
else if (base->base_health <= 0)
{
base->base_health = 0;
return SpaceObjDestroyed(space_obj);
}

pub::SpaceObj::SetRelativeHealth(space_obj, base->base_health / base->max_base_health);
Expand Down Expand Up @@ -351,7 +348,12 @@ bool CoreModule::Timer(uint time)
float CoreModule::SpaceObjDamaged(uint space_obj, uint attacking_space_obj, float curr_hitpoints, float new_hitpoints)
{

base->SpaceObjDamaged(space_obj, attacking_space_obj, curr_hitpoints, new_hitpoints);
base->shield_timeout = time(nullptr) + 60;
if (!base->isShieldOn)
{
base->isShieldOn = true;
EnableShieldFuse(true);
}

if (!base->vulnerableWindowStatus || base->invulnerable == 1 || base->shield_strength_multiplier >= 1.0f)
{
Expand Down Expand Up @@ -386,14 +388,25 @@ float CoreModule::SpaceObjDamaged(uint space_obj, uint attacking_space_obj, floa
base->shield_strength_multiplier += shield_reinforcement_increment;
}

base->base_health -= damageTaken;
return curr_hitpoints - damageTaken;
if (!wasDamagedSinceLastUpdate)
{
base->baseCSolar->set_hit_pts(base->base_health);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be doing this after we modify base->base_health below?

wasDamagedSinceLastUpdate = true;
}

float newHealth = max(0, curr_hitpoints - damageTaken);

base->SpaceObjDamaged(space_obj, attacking_space_obj, curr_hitpoints, newHealth);

base->base_health = newHealth;
return newHealth;
}

bool CoreModule::SpaceObjDestroyed(uint space_obj, bool moveFile, bool broadcastDeath)
{
if (this->space_obj == space_obj)
if (this->space_obj == space_obj && !undergoingDestruction)
{
undergoingDestruction = true;
if (set_plugin_debug > 1)
ConPrint(L"CoreModule::destroyed space_obj=%u\n", space_obj);
pub::SpaceObj::LightFuse(space_obj, "player_base_explode_fuse", 0);
Expand Down Expand Up @@ -434,14 +447,7 @@ bool CoreModule::SpaceObjDestroyed(uint space_obj, bool moveFile, bool broadcast
}
Log::LogBaseAction(wstos(base->basename), msg.c_str());

if (!base->last_attacker.empty())
{
ConPrint(L"BASE: Base %s destroyed. Last attacker: %s\n", base->basename.c_str(), base->last_attacker.c_str());
}
else
{
ConPrint(L"BASE: Base %s destroyed\n", base->basename.c_str());
}
ConPrint(L"BASE: Base %s destroyed\n", base->basename.c_str());

// Unspawn, delete base and save file.
DeleteBase(base, moveFile);
Expand Down
7 changes: 6 additions & 1 deletion Plugins/Public/base_plugin/Jumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void HyperJump::LoadHyperspaceHubConfig(const string& configPath)
static map<uint, vector<SYSTEMJUMPCOORDS>> mapSystemJumps;
uint lastJumpholeRandomization = 0;
uint randomizationCooldown = 3600 * 23;
uint randomizationCooldownOffset = 3600 * 9;
INI_Reader ini;

if (ini.open(cfg_filehyperspaceHubTimer.c_str(), false))
Expand All @@ -186,6 +187,10 @@ void HyperJump::LoadHyperspaceHubConfig(const string& configPath)
{
randomizationCooldown = ini.get_value_int(0);
}
if (ini.is_value("randomizationCooldownOffset"))
{
randomizationCooldownOffset = ini.get_value_int(0);
}
if (ini.is_value("systemToExclude"))
{
unchartedSystemToExclude = CreateID(ini.get_value_string(0));
Expand Down Expand Up @@ -390,5 +395,5 @@ void HyperJump::LoadHyperspaceHubConfig(const string& configPath)
}
}

WritePrivateProfileString("Timer", "lastRandomization", itos((int)currTime).c_str(), cfg_filehyperspaceHubTimer.c_str());
WritePrivateProfileString("Timer", "lastRandomization", itos((int)(currTime - (currTime % randomizationCooldown) + randomizationCooldownOffset)).c_str(), cfg_filehyperspaceHubTimer.c_str());
}
56 changes: 17 additions & 39 deletions Plugins/Public/base_plugin/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ string set_status_path_html;
string set_status_path_json;

/// Damage to the base every tick
uint set_damage_per_tick = 600;
float set_damage_per_tick = 600;

/// Additional damage penalty for stations without proper crew
float no_crew_damage_multiplier = 1;
Expand Down Expand Up @@ -524,7 +524,7 @@ void LoadSettingsActual()
}
else if (ini.is_value("damage_per_tick"))
{
set_damage_per_tick = ini.get_value_int(0);
set_damage_per_tick = ini.get_value_float(0);
}
else if (ini.is_value("no_crew_damage_multiplier"))
{
Expand Down Expand Up @@ -1142,9 +1142,17 @@ bool __stdcall HkCb_Land(IObjInspectImpl *obj, uint base_dock_id, uint base)
if (clients[client].player_base)
return true;

CUSTOM_MOBILE_DOCK_CHECK_STRUCT info;
info.iClientID = client;
info.isMobileDocked = false;
Plugin_Communication(CUSTOM_MOBILE_DOCK_CHECK, &info);
if (!info.isMobileDocked)
{
clients[client].last_player_base = 0;
}

// If we're not docking at a player base then clear
// the last base flag
clients[client].last_player_base = 0;
clients[client].player_base = 0;

if (base == 0)
Expand Down Expand Up @@ -1532,9 +1540,9 @@ static bool IsDockingAllowed(PlayerBase *base, uint client)
}

//Hostile listed can't dock even if they are friendly faction listed
for (list<wstring>::iterator i = base->perma_hostile_tags.begin(); i != base->perma_hostile_tags.end(); ++i)
for (auto& i : base->perma_hostile_tags)
{
if (charname.find(*i) == 0)
if (charname.find(i) == 0)
{
return false;
}
Expand Down Expand Up @@ -2370,6 +2378,10 @@ void __stdcall HkCb_AddDmgEntry(DamageList *dmg, unsigned short sID, float& newH
returncode = SKIPPLUGINS_NOFUNCTIONCALL;
return;
}
if (newHealth == 0.0f)
{
damagedModule->SpaceObjDestroyed(iDmgToSpaceID);
}

returncode = SKIPPLUGINS;

Expand Down Expand Up @@ -2566,7 +2578,6 @@ bool ExecuteCommandString_Callback(CCmds* cmd, const wstring &args)
}
}


if (!base)
{
cmd->Print(L"ERR Base doesn't exist");
Expand Down Expand Up @@ -2624,39 +2635,6 @@ bool ExecuteCommandString_Callback(CCmds* cmd, const wstring &args)
}


return true;
}
else if (args.find(L"basedespawn") == 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't people using this? Did you mean to get rid of one of the baserespawn handlers instead?

{
returncode = SKIPPLUGINS_NOFUNCTIONCALL;

RIGHT_CHECK(RIGHT_BASES)

uint client = HkGetClientIdFromCharname(cmd->GetAdminName());

PlayerBase* base;
for (auto& i : player_bases)
{
if (i.second->basename == cmd->ArgStrToEnd(1))
{
base = i.second;
break;
}
}

if (!base)
{
cmd->Print(L"ERR Base doesn't exist\n");
return true;
}

base->base_health = 0;
if (base->base_health < 1)
{
cmd->Print(L"Base despawned\n");
CoreModule(base).SpaceObjDestroyed(CoreModule(base).space_obj, false, false);
}

return true;
}
else if (args.find(L"baserespawn") == 0)
Expand Down
18 changes: 8 additions & 10 deletions Plugins/Public/base_plugin/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ class CoreModule : public Module
// If true, do not take damage
bool dont_rust;

// The list of goods and usage of goods per minute for the autosys effect
map<uint, uint> mapAutosysGood;
bool wasDamagedSinceLastUpdate;
bool undergoingDestruction;

// The list of goods and usage of goods per minute for the autosys effect
map<uint, uint> mapHumansysGood;
Expand Down Expand Up @@ -309,7 +309,6 @@ class PlayerBase

float GetAttitudeTowardsClient(uint client, bool emulated_siege_mode = false);
void SyncReputationForBase();
void SiegeModChainReaction(uint client);
void SyncReputationForBaseObject(uint space_obj);

void SpaceObjDamaged(uint space_obj, uint attacking_space_obj, float curr_hitpoints, float new_hitpoints);
Expand All @@ -320,6 +319,9 @@ class PlayerBase
// The base nickname
string nickname;

// Reference to the base's CSolar object
CSolar* baseCSolar;

// The base affiliation
uint affiliation;

Expand Down Expand Up @@ -401,11 +403,10 @@ class PlayerBase
unordered_set<uint> hostile_factions;

// List of ships that are hostile to this base
unordered_map<wstring, wstring> hostile_tags;
unordered_map<wstring, float> hostile_tags_damage;
unordered_set<wstring> hostile_tags;

// List of ships that are permanently hostile to this base
list<wstring> perma_hostile_tags;
unordered_set<wstring> perma_hostile_tags;

// Modules for base
vector<Module*> modules;
Expand Down Expand Up @@ -434,9 +435,6 @@ class PlayerBase
int logic;
int invulnerable;

//last player attacker
wstring last_attacker;

uint lastVulnerabilityWindowChange = 0;

BASE_VULNERABILITY_WINDOW vulnerabilityWindow1 = { -1, -1 };
Expand Down Expand Up @@ -679,7 +677,7 @@ extern int construction_credit_cost;
extern uint set_damage_per_10sec;

/// Damage to the base every tick
extern uint set_damage_per_tick;
extern float set_damage_per_tick;

/// Additional damage penalty for stations without proper crew
extern float no_crew_damage_multiplier;
Expand Down
Loading