-
Notifications
You must be signed in to change notification settings - Fork 34
POB: Optimizations to damage-taking code, other updates #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| { | ||
| } | ||
|
|
||
|
|
@@ -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(); | ||
|
|
||
| if (shield_reinforcement_threshold_map.count(base->base_level)) | ||
| base->base_shield_reinforcement_threshold = shield_reinforcement_threshold_map[base->base_level]; | ||
| else | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
| } | ||
|
|
||
|
|
@@ -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); | ||
|
|
@@ -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) | ||
| { | ||
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
@@ -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); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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")) | ||
| { | ||
|
|
@@ -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) | ||
|
|
@@ -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; | ||
| } | ||
|
|
@@ -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; | ||
|
|
||
|
|
@@ -2566,7 +2578,6 @@ bool ExecuteCommandString_Callback(CCmds* cmd, const wstring &args) | |
| } | ||
| } | ||
|
|
||
|
|
||
| if (!base) | ||
| { | ||
| cmd->Print(L"ERR Base doesn't exist"); | ||
|
|
@@ -2624,39 +2635,6 @@ bool ExecuteCommandString_Callback(CCmds* cmd, const wstring &args) | |
| } | ||
|
|
||
|
|
||
| return true; | ||
| } | ||
| else if (args.find(L"basedespawn") == 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
There was a problem hiding this comment.
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