From 1cbba257e3cd87e83493dec51d9842ec04f04748 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Fri, 3 Jan 2025 08:31:41 -0500 Subject: [PATCH 01/28] Adding a few explanatory comments, also makes these lines a touch easier to search for This is just the starting point. Nothing much to see here currently. --- source/GameAction.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 7c7ad06aaa19..9f173ff433c2 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -380,6 +380,7 @@ const vector &GameAction::Ships() const noexcept // Perform the specified tasks. void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const { + // Log entries if(!logText.empty()) player.AddLogEntry(logText); for(auto &&it : specialLogText) @@ -396,15 +397,19 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const // If multiple outfits, ships are being transferred, first remove the ships, // then the outfits, before adding any new ones. + // Removing ships. for(auto &&it : giftShips) if(!it.Giving()) it.Do(player); + // Take outfits. for(auto &&it : giftOutfits) if(it.second < 0) DoGift(player, it.first, it.second, ui); + // Give outfits. for(auto &&it : giftOutfits) if(it.second > 0) DoGift(player, it.first, it.second, ui); + // Give ships. for(auto &&it : giftShips) if(it.Giving()) it.Do(player); @@ -425,14 +430,17 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const // then this action won't offer, so MissionAction payment behavior // is unchanged. } + // giving the player a fine. if(fine) player.Accounts().AddFine(fine); for(const auto &debtEntry : debt) player.Accounts().AddDebt(debtEntry.amount, debtEntry.interest, debtEntry.term); + // Trigger events. for(const auto &it : events) player.AddEvent(*it.first, player.GetDate() + it.second.first); + // Mark and unmark systems. for(const System *system : mark) caller->Mark(system); for(const System *system : unmark) From fedfe4dedc306ce11eff992680e3b6bd13741e8d Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sat, 4 Jan 2025 09:00:35 -0500 Subject: [PATCH 02/28] Creating a map of attribute modifications and some basic error checking for number of elements. --- source/GameAction.cpp | 25 +++++++++++++++++++++++++ source/GameAction.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 9f173ff433c2..987b4dbd4849 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -226,6 +226,24 @@ void GameAction::LoadSingle(const DataNode &child) fail.insert(child.Token(1)); else if(key == "fail") failCaller = true; + else if(key == "attributes") + { + // Current expected format is attributes add/set + if(child.size == 4) + { + if(child.Token(1) == "add") + { + double valueChange = static_cast(child.Value(3)); + modifyAttributes[Get(child.Token(2))] = valueChange; + } + } + else if(child.size > 4) + child.PrintTrace("Error: Skipping \"attributes\" as >4 values is not yet supported:"); + else + child.PrintTrace("Error: Skipping invalid values for \"attributes\":"); + /*else if(child.Token(1) == "set")*/ + /* < code to put the attributes into the set map, to be done after the add is working > ;*/ + } else conditions.Add(child); } @@ -377,6 +395,13 @@ const vector &GameAction::Ships() const noexcept +const map &GameAction::ModifyAttributes() const noexcept +{ + return modifyAttributes; +} + + + // Perform the specified tasks. void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const { diff --git a/source/GameAction.h b/source/GameAction.h index 49a2521d5875..41425a041d7e 100644 --- a/source/GameAction.h +++ b/source/GameAction.h @@ -67,6 +67,9 @@ class GameAction { const std::map &Outfits() const noexcept; const std::vector &Ships() const noexcept; + // references the map of attributes to be changed. + const std::map &ModifyAttributes() const noexcept; + // Perform this action. void Do(PlayerInfo &player, UI *ui, const Mission *caller) const; @@ -94,6 +97,7 @@ class GameAction { std::map> events; std::vector giftShips; std::map giftOutfits; + std::map modifyAttributes; int64_t payment = 0; int64_t paymentMultiplier = 0; From 4b44f917f44e28b89e21f42cd0d610babe562f80 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sat, 4 Jan 2025 10:19:30 -0500 Subject: [PATCH 03/28] size to Size --- source/GameAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 987b4dbd4849..72b9e4c28c17 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -229,7 +229,7 @@ void GameAction::LoadSingle(const DataNode &child) else if(key == "attributes") { // Current expected format is attributes add/set - if(child.size == 4) + if(child.Size == 4) { if(child.Token(1) == "add") { @@ -237,7 +237,7 @@ void GameAction::LoadSingle(const DataNode &child) modifyAttributes[Get(child.Token(2))] = valueChange; } } - else if(child.size > 4) + else if(child.Size > 4) child.PrintTrace("Error: Skipping \"attributes\" as >4 values is not yet supported:"); else child.PrintTrace("Error: Skipping invalid values for \"attributes\":"); From 9be1f5c78dbc36ea3f9ec5d8df89b3a76bca8fc4 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sat, 4 Jan 2025 10:22:45 -0500 Subject: [PATCH 04/28] missing () --- source/GameAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 72b9e4c28c17..3608b5ad12be 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -229,7 +229,7 @@ void GameAction::LoadSingle(const DataNode &child) else if(key == "attributes") { // Current expected format is attributes add/set - if(child.Size == 4) + if(child.Size() == 4) { if(child.Token(1) == "add") { @@ -237,7 +237,7 @@ void GameAction::LoadSingle(const DataNode &child) modifyAttributes[Get(child.Token(2))] = valueChange; } } - else if(child.Size > 4) + else if(child.Size() > 4) child.PrintTrace("Error: Skipping \"attributes\" as >4 values is not yet supported:"); else child.PrintTrace("Error: Skipping invalid values for \"attributes\":"); From b131c7a386571682d83671435a36b53ffc95e732 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sun, 5 Jan 2025 10:18:32 -0500 Subject: [PATCH 05/28] Test job and test error check --- data/human/jobs.txt | 17 +++++++++++++++++ source/GameAction.cpp | 8 +++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index a608c5c75926..4cc275f29262 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5111,3 +5111,20 @@ mission "Banned Syndicate Items [4]" on complete payment 40000 170 dialog phrase "generic passenger dropoff payment" + + + +mission "AAA Outfit Give Testing 9" + name "AAA Outfit Give Testing v9" + description "Testing mission v9!" + job + repeat + source + on accept + conversation + `Test text v9` + + on complete + attributes add hull 500 + payment 500 + dialog `v9` diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 3608b5ad12be..82246f2d714d 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -234,15 +234,17 @@ void GameAction::LoadSingle(const DataNode &child) if(child.Token(1) == "add") { double valueChange = static_cast(child.Value(3)); - modifyAttributes[Get(child.Token(2))] = valueChange; + string attributeTarget = child.Token(2); + child.PrintTrace("Error: Test Data output: " + attributeTarget + to_string(valueChange)); + // modifyAttributes[Get(child.Token(2))] = valueChange; } } else if(child.Size() > 4) child.PrintTrace("Error: Skipping \"attributes\" as >4 values is not yet supported:"); else child.PrintTrace("Error: Skipping invalid values for \"attributes\":"); - /*else if(child.Token(1) == "set")*/ - /* < code to put the attributes into the set map, to be done after the add is working > ;*/ + //else if(child.Token(1) == "set") + // < code to put the attributes into the set map, to be done after the add is working > ; } else conditions.Add(child); From e781e06f748b618550c0377af9894ce0c3fcdde1 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sun, 5 Jan 2025 10:24:32 -0500 Subject: [PATCH 06/28] add missing space. --- source/GameAction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 82246f2d714d..5e51e23aa23c 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -243,7 +243,7 @@ void GameAction::LoadSingle(const DataNode &child) child.PrintTrace("Error: Skipping \"attributes\" as >4 values is not yet supported:"); else child.PrintTrace("Error: Skipping invalid values for \"attributes\":"); - //else if(child.Token(1) == "set") + // else if(child.Token(1) == "set") // < code to put the attributes into the set map, to be done after the add is working > ; } else From 2207a2038f5987b3c83cd72f9a48863a14682920 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Mon, 6 Jan 2025 07:06:08 -0500 Subject: [PATCH 07/28] This looks like it creates the map... --- source/GameAction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 5e51e23aa23c..409832fa169b 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -236,7 +236,7 @@ void GameAction::LoadSingle(const DataNode &child) double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); child.PrintTrace("Error: Test Data output: " + attributeTarget + to_string(valueChange)); - // modifyAttributes[Get(child.Token(2))] = valueChange; + modifyAttributes[child.Token(2)] = valueChange; // giftOutfits[GameData::Outfits().Get(child.Token(1))] = count; } } else if(child.Size() > 4) From e40733aeddf2c40cdeb60ec2594d1209ab6bfc60 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Mon, 6 Jan 2025 08:18:08 -0500 Subject: [PATCH 08/28] Removed comment and added line to GameAction::Save I can't see it doing anything yet, but I think this should in theory write the results to the save file, possibly in the details for the saved job. --- data/human/jobs.txt | 11 ++++++----- source/GameAction.cpp | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 4cc275f29262..bd4a59d01b33 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5114,17 +5114,18 @@ mission "Banned Syndicate Items [4]" -mission "AAA Outfit Give Testing 9" - name "AAA Outfit Give Testing v9" - description "Testing mission v9!" +mission "AAA Outfit Give Testing 11" + name "AAA Outfit Give Testing v11" + description "Testing mission v11!" job repeat source on accept conversation - `Test text v9` + `Test text v11` on complete attributes add hull 500 payment 500 - dialog `v9` + outfit "Supercapacitor" + dialog `Concluding v11` diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 409832fa169b..16293cda96e2 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -236,7 +236,7 @@ void GameAction::LoadSingle(const DataNode &child) double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); child.PrintTrace("Error: Test Data output: " + attributeTarget + to_string(valueChange)); - modifyAttributes[child.Token(2)] = valueChange; // giftOutfits[GameData::Outfits().Get(child.Token(1))] = count; + modifyAttributes[child.Token(2)] = valueChange; } } else if(child.Size() > 4) @@ -321,6 +321,8 @@ void GameAction::Save(DataWriter &out) const else out.Write("music", music.value()); } + for(auto &&it : modifyAttributes) + out.Write("attributes add", it.first, it.second); conditions.Save(out); } From 0ea0d323eb624320b62cf1ce39a9ea331951341c Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:35:31 -0500 Subject: [PATCH 09/28] Progress.... I think. It succesfully reaches L530 in GameAction, but it does not enter the For. I'm not sure why, but the log entries at L533 and L537 never turn up; but the one at L530 does all the time. --- data/human/jobs.txt | 14 +++++++++----- source/GameAction.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- source/Ship.cpp | 39 +++++++++++++++++++++++++++++++++++++++ source/Ship.h | 2 ++ 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index bd4a59d01b33..4778b16d1361 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5114,18 +5114,22 @@ mission "Banned Syndicate Items [4]" -mission "AAA Outfit Give Testing 11" - name "AAA Outfit Give Testing v11" - description "Testing mission v11!" +mission "AAA Outfit Give Testing 12" + name "AAA Outfit Give Testing v12" + description "Testing mission v12!" job repeat source on accept conversation - `Test text v11` + `Test text v12` on complete attributes add hull 500 payment 500 outfit "Supercapacitor" - dialog `Concluding v11` + conversation + action + attributes add hull 1300 + `Concluding v12` + diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 16293cda96e2..93393841f5ae 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -120,10 +120,25 @@ namespace { message += "flagship."; Messages::Add(message, Messages::Importance::High); } + + void DoModify(PlayerInfo &player, string targetAttribute, double modifyAmount) + { + // Get the player's flagship + Ship *flagship = player.Flagship(); + + // Check if the player has a flagship, and if the attribute, and amount exist. + // If the player does not have one of these things, return without doing anything. + if(!flagship || !targetAttribute.empty() || !modifyAmount) + return; + + flagship->ChangeAttribute(targetAttribute, modifyAmount); + } } + + // Construct and Load() at the same time. GameAction::GameAction(const DataNode &node) { @@ -235,7 +250,7 @@ void GameAction::LoadSingle(const DataNode &child) { double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); - child.PrintTrace("Error: Test Data output: " + attributeTarget + to_string(valueChange)); + child.PrintTrace("Trace: Test Data output L267: " + attributeTarget + " " + to_string(valueChange)); modifyAttributes[child.Token(2)] = valueChange; } } @@ -321,8 +336,20 @@ void GameAction::Save(DataWriter &out) const else out.Write("music", music.value()); } + out.Write("log"); + out.BeginChild(); + { + out.Write("l342, right after the attributes add write line."); + } for(auto &&it : modifyAttributes) + { out.Write("attributes add", it.first, it.second); + out.Write("log"); + out.BeginChild(); + { + out.Write("l350, right after the attributes add write line."); + } + } conditions.Save(out); } @@ -499,6 +526,18 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const Audio::PlayMusic(music.value()); } + // Modify attributes. + player.AddLogEntry("GameAction L530"); + for(auto &&it : modifyAttributes) + { + player.AddLogEntry("GameAction L533"); + if(it.second) + { + DoModify(player, it.first, it.second); + player.AddLogEntry("GameAction L537"); + } + } + // Check if applying the conditions changes the player's reputations. conditions.Apply(player.Conditions()); } diff --git a/source/Ship.cpp b/source/Ship.cpp index f31abbf72597..dd78e55f1b60 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3760,6 +3760,45 @@ void Ship::AddOutfit(const Outfit *outfit, int count) +// Add or reduce an attribute. (To reduce, pass a negative number.) +// Ref from ship.h: Get the current attributes of this ship. +// Ref from ship.h: const Outfit &Attributes() const; +// Ref from ship.h: Get the attributes of this ship chassis before any outfits were added. +// Ref from ship.h: const Outfit &BaseAttributes() const; +void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) +{ + Logger::LogError("Ship.cpp L3770"); + if(!targetAttribute.empty()) + { + // If the attribute is hull, then add the modifyAmount. + if(targetAttribute == "hull") + hull += modifyAmount; + + // attributes.Add(*outfit, count); + + if(targetAttribute == "cargo space") + { + cargo.SetSize(attributes.Get("cargo space")); + + // Only the player's ships make use of attraction and deterrence. + if(isYours) + attraction = CalculateAttraction(); + } + + // If the added or removed attribute is hyperdrive, scram drive, or jump drive capability, then + // recalibrate the navigation. + if((targetAttribute == "hyperdrive" || targetAttribute == "scram drive" || targetAttribute == "jump drive")) + navigation.Calibrate(*this); + // Navigation may still need to be recalibrated depending on the drives a ship has. + // Only do this for player ships as to display correct information on the map. + // Non-player ships will recalibrate before they jump. + else if(isYours) + navigation.Recalibrate(*this); + } +} + + + // Get the list of weapons. Armament &Ship::GetArmament() { diff --git a/source/Ship.h b/source/Ship.h index 913e89969289..702b4aa744da 100644 --- a/source/Ship.h +++ b/source/Ship.h @@ -474,6 +474,8 @@ class Ship : public Body, public std::enable_shared_from_this { // Add or remove outfits. (To remove, pass a negative number.) void AddOutfit(const Outfit *outfit, int count); + void ChangeAttribute(std::string targetAttribute, double modifyAmount); + // Get the list of weapons. Armament &GetArmament(); const std::vector &Weapons() const; From ec4b302d2d57e583bd32cc52dfc96720850ad853 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:38:07 -0500 Subject: [PATCH 10/28] It's on L253 now, not L267 --- source/GameAction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 93393841f5ae..219c2c79c68d 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -250,7 +250,7 @@ void GameAction::LoadSingle(const DataNode &child) { double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); - child.PrintTrace("Trace: Test Data output L267: " + attributeTarget + " " + to_string(valueChange)); + child.PrintTrace("Trace: Test Data output L253: " + attributeTarget + " " + to_string(valueChange)); modifyAttributes[child.Token(2)] = valueChange; } } From 491f119e33a15c22f1ef85f1dd82151b82ddad58 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:20:59 -0500 Subject: [PATCH 11/28] Removing the L342 log that gummed up things. --- source/GameAction.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 219c2c79c68d..019cfcf72423 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -250,8 +250,8 @@ void GameAction::LoadSingle(const DataNode &child) { double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); + modifyAttributes[attributeTarget] = valueChange; child.PrintTrace("Trace: Test Data output L253: " + attributeTarget + " " + to_string(valueChange)); - modifyAttributes[child.Token(2)] = valueChange; } } else if(child.Size() > 4) @@ -336,19 +336,9 @@ void GameAction::Save(DataWriter &out) const else out.Write("music", music.value()); } - out.Write("log"); - out.BeginChild(); - { - out.Write("l342, right after the attributes add write line."); - } for(auto &&it : modifyAttributes) { out.Write("attributes add", it.first, it.second); - out.Write("log"); - out.BeginChild(); - { - out.Write("l350, right after the attributes add write line."); - } } conditions.Save(out); @@ -527,7 +517,7 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const } // Modify attributes. - player.AddLogEntry("GameAction L530"); + player.AddLogEntry("GameAction L530 " + to_string(modifyAttributes.size())); for(auto &&it : modifyAttributes) { player.AddLogEntry("GameAction L533"); From df065eac58d0498e6d0aa4feccddead269279218 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Fri, 10 Jan 2025 08:25:33 -0500 Subject: [PATCH 12/28] Progress! Vitalchip had a moment of inspiration that solved why the map kept getting erased, and now the atribute changes are making there way all the way through the code, and at least in the case of hull, temporarily changing the hull value that is stored in the player's save file but outside the "attributes" section of their ship. So it's not entirely solved yet, but massive progress. Co-Authored-By: vitalchip <65342577+vitalchip@users.noreply.github.com> --- data/human/jobs.txt | 13 +++++++------ source/GameAction.cpp | 15 ++++++++++----- source/Ship.cpp | 5 ++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 4778b16d1361..2e55082496bd 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5114,22 +5114,23 @@ mission "Banned Syndicate Items [4]" -mission "AAA Outfit Give Testing 12" - name "AAA Outfit Give Testing v12" - description "Testing mission v12!" +mission "AAA Outfit Give Testing 13" + name "AAA Outfit Give Testing v13" + description "Testing mission v13!" job repeat source on accept conversation - `Test text v12` - + `Test text v13` on complete attributes add hull 500 + attributes add "cargo space" 34 payment 500 outfit "Supercapacitor" conversation action attributes add hull 1300 - `Concluding v12` + attributes add "cargo space" 41 + `Concluding v13` diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 019cfcf72423..b211800e05bd 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -126,9 +126,13 @@ namespace { // Get the player's flagship Ship *flagship = player.Flagship(); + string message; + message = "DoModify Has Been reached: " + targetAttribute + " " + to_string(modifyAmount); + Messages::Add(message, Messages::Importance::High); + // Check if the player has a flagship, and if the attribute, and amount exist. // If the player does not have one of these things, return without doing anything. - if(!flagship || !targetAttribute.empty() || !modifyAmount) + if(!flagship || targetAttribute.empty() || !modifyAmount) return; flagship->ChangeAttribute(targetAttribute, modifyAmount); @@ -338,7 +342,7 @@ void GameAction::Save(DataWriter &out) const } for(auto &&it : modifyAttributes) { - out.Write("attributes add", it.first, it.second); + out.Write("attributes", "add", it.first, it.second); } conditions.Save(out); @@ -517,14 +521,14 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const } // Modify attributes. - player.AddLogEntry("GameAction L530 " + to_string(modifyAttributes.size())); + player.AddLogEntry("GameAction L520 " + to_string(modifyAttributes.size())); for(auto &&it : modifyAttributes) { - player.AddLogEntry("GameAction L533"); + player.AddLogEntry("GameAction L523"); if(it.second) { DoModify(player, it.first, it.second); - player.AddLogEntry("GameAction L537"); + player.AddLogEntry("GameAction L527"); } } @@ -551,6 +555,7 @@ GameAction GameAction::Instantiate(map &subs, int jumps, int pay for(auto &&it : giftShips) result.giftShips.push_back(it.Instantiate(subs)); result.giftOutfits = giftOutfits; + result.modifyAttributes = modifyAttributes; result.music = music; diff --git a/source/Ship.cpp b/source/Ship.cpp index dd78e55f1b60..a613d73875e0 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3767,12 +3767,15 @@ void Ship::AddOutfit(const Outfit *outfit, int count) // Ref from ship.h: const Outfit &BaseAttributes() const; void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) { - Logger::LogError("Ship.cpp L3770"); + Logger::LogError("Ship.cpp L3770" + targetAttribute + " " + to_string(modifyAmount)); if(!targetAttribute.empty()) { // If the attribute is hull, then add the modifyAmount. if(targetAttribute == "hull") + { hull += modifyAmount; + Logger::LogError("Ship.cpp L3777" + targetAttribute + " " + to_string(modifyAmount) + to_string(hull)); + } // attributes.Add(*outfit, count); From d2f31c8cfb21907b6aa92040b874703c66bbffeb Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:32:16 -0500 Subject: [PATCH 13/28] It works! We can now successfully add attributes to the base ship hull! Needs sanity checks and perhaps a clean up and stuff, but in any case, awesome! Many thanks to VitalChip, without whom this would have taken much, much longer. If I even managed it at all. Co-Authored-By: vitalchip <65342577+vitalchip@users.noreply.github.com> --- source/Ship.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/source/Ship.cpp b/source/Ship.cpp index a613d73875e0..a3c655afc734 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3761,27 +3761,22 @@ void Ship::AddOutfit(const Outfit *outfit, int count) // Add or reduce an attribute. (To reduce, pass a negative number.) -// Ref from ship.h: Get the current attributes of this ship. -// Ref from ship.h: const Outfit &Attributes() const; -// Ref from ship.h: Get the attributes of this ship chassis before any outfits were added. -// Ref from ship.h: const Outfit &BaseAttributes() const; void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) { Logger::LogError("Ship.cpp L3770" + targetAttribute + " " + to_string(modifyAmount)); if(!targetAttribute.empty()) { - // If the attribute is hull, then add the modifyAmount. + double originalValue = attributes.Get(targetAttribute); + baseAttributes.Set(targetAttribute.c_str(), originalValue + modifyAmount); + attributes.Set(targetAttribute.c_str(), originalValue + modifyAmount); + + // Adds the mmodifyAmount to the current hull too. if(targetAttribute == "hull") - { hull += modifyAmount; - Logger::LogError("Ship.cpp L3777" + targetAttribute + " " + to_string(modifyAmount) + to_string(hull)); - } - - // attributes.Add(*outfit, count); if(targetAttribute == "cargo space") { - cargo.SetSize(attributes.Get("cargo space")); + cargo.SetSize(attributes.Get("cargo space") + modifyAmount); // Only the player's ships make use of attraction and deterrence. if(isYours) From 1d47ebd6cfd78f0e49d5bdb463b01ef670896f3f Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sat, 11 Jan 2025 08:43:26 -0500 Subject: [PATCH 14/28] safety checks --- data/human/jobs.txt | 6 ++--- source/Ship.cpp | 54 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 2e55082496bd..409689bd8da9 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5124,13 +5124,13 @@ mission "AAA Outfit Give Testing 13" conversation `Test text v13` on complete - attributes add hull 500 + attributes add hull 60 attributes add "cargo space" 34 payment 500 outfit "Supercapacitor" conversation action - attributes add hull 1300 - attributes add "cargo space" 41 + attributes add hull -3300 + attributes add "cargo space" -410 `Concluding v13` diff --git a/source/Ship.cpp b/source/Ship.cpp index a3c655afc734..c591e7dcaf4c 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -901,7 +901,7 @@ void Ship::FinishLoading(bool isNewInstance) // Issue warnings if this ship has is misconfigured, e.g. is missing required values // or has negative outfit, cargo, weapon, or engine capacity. for(auto &&attr : set{"outfit space", "cargo space", "weapon capacity", "engine capacity", - "engine mod space", "reverse thruster slot", "steering slot", "thruster slot"}) + "engine mod space", "reverse thruster slot", "steering slot", "thruster slot", "lateral thruster slot"}) { double val = attributes.Get(attr); if(val < 0) @@ -3766,17 +3766,59 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) Logger::LogError("Ship.cpp L3770" + targetAttribute + " " + to_string(modifyAmount)); if(!targetAttribute.empty()) { + double limiter = 0.; + double minAttributeValue = 0.; + double originalBaseValue = baseAttributes.Get(targetAttribute); double originalValue = attributes.Get(targetAttribute); - baseAttributes.Set(targetAttribute.c_str(), originalValue + modifyAmount); - attributes.Set(targetAttribute.c_str(), originalValue + modifyAmount); + double newBaseValue = originalBaseValue + modifyAmount; + double newValue = originalValue + modifyAmount; - // Adds the mmodifyAmount to the current hull too. + // Safety checks to ensure the new value is within parameters. + if(newBaseValue < 1. && newValue < 1. && targetAttribute == "hull") + { + // This means the minimum value for this attribute is 1.0 + minAttributeValue = 1.; + limiter = minAttributeValue - newBaseValue; + } + else if(newBaseValue < 0.01 && (targetAttribute == "drag" || targetAttribute == "mass")) + { + // This means the minimum value for these attributes is 0.01 + minAttributeValue = 0.01; + limiter = minAttributeValue - newBaseValue; + } + // Special handling for attributes that cannot be less than 0. + // These values can be 0, just they cannot be negative. + else if(newBaseValue < 0. && (targetAttribute == "outfit space" || targetAttribute == "cargo space" || + targetAttribute == "weapon capacity" || targetAttribute == "engine capacity" || + targetAttribute == "engine mod space" || targetAttribute =="shields" || targetAttribute == "reverse thruster slot" || + targetAttribute == "steering slot" || targetAttribute == "thruster slot" || + targetAttribute == "lateral thruster slot" || targetAttribute == "bunks" || targetAttribute == "fuel capacity" || + targetAttribute == "required crew")) + { + if(newBaseValue < 0.) + { + minAttributeValue = 0.; + limiter = minAttributeValue - newBaseValue; + } + } + + //Calculations take place herere + newBaseValue += limiter; + newValue += limiter; + baseAttributes.Set(targetAttribute.c_str(), newBaseValue); + attributes.Set(targetAttribute.c_str(), newValue); + + + // Ensuring the current hull value is changed as well. if(targetAttribute == "hull") - hull += modifyAmount; + { + // Adds the modifyAmount and the limiter to the current hull too. + hull += modifyAmount + limiter; + } if(targetAttribute == "cargo space") { - cargo.SetSize(attributes.Get("cargo space") + modifyAmount); + cargo.SetSize(attributes.Get("cargo space")); // Only the player's ships make use of attraction and deterrence. if(isYours) From cd3e9eb1ea7ba38d4f8ebc012b2f943b204741e8 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sat, 11 Jan 2025 08:50:16 -0500 Subject: [PATCH 15/28] fixes --- source/Ship.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Ship.cpp b/source/Ship.cpp index c591e7dcaf4c..2d41c057803e 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3790,10 +3790,10 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) // These values can be 0, just they cannot be negative. else if(newBaseValue < 0. && (targetAttribute == "outfit space" || targetAttribute == "cargo space" || targetAttribute == "weapon capacity" || targetAttribute == "engine capacity" || - targetAttribute == "engine mod space" || targetAttribute =="shields" || targetAttribute == "reverse thruster slot" || - targetAttribute == "steering slot" || targetAttribute == "thruster slot" || - targetAttribute == "lateral thruster slot" || targetAttribute == "bunks" || targetAttribute == "fuel capacity" || - targetAttribute == "required crew")) + targetAttribute == "engine mod space" || targetAttribute == "shields" || + targetAttribute == "reverse thruster slot" || targetAttribute == "steering slot" || + targetAttribute == "thruster slot" || targetAttribute == "lateral thruster slot" || + targetAttribute == "bunks" || targetAttribute == "fuel capacity" || targetAttribute == "required crew")) { if(newBaseValue < 0.) { @@ -3802,7 +3802,7 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) } } - //Calculations take place herere + // Calculations take place here newBaseValue += limiter; newValue += limiter; baseAttributes.Set(targetAttribute.c_str(), newBaseValue); From b0cd869a1f6dc15ba7da1dff80ce49fd646fafe5 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sat, 11 Jan 2025 23:03:45 -0500 Subject: [PATCH 16/28] Adding "set" --- data/human/jobs.txt | 33 ++++++++++++++---- source/GameAction.cpp | 52 ++++++++++++++++++++++++++-- source/GameAction.h | 2 ++ source/Ship.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++- source/Ship.h | 1 + 5 files changed, 156 insertions(+), 11 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 409689bd8da9..55001ce57ea7 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5114,15 +5114,15 @@ mission "Banned Syndicate Items [4]" -mission "AAA Outfit Give Testing 13" - name "AAA Outfit Give Testing v13" - description "Testing mission v13!" +mission "AAA modify Attribute Testing 14" + name "AAA modify Attribute Testing v14" + description "Testing mission v14! This will add 1300 hull, then 500." job repeat source on accept conversation - `Test text v13` + `Test text v14.` on complete attributes add hull 60 attributes add "cargo space" 34 @@ -5130,7 +5130,26 @@ mission "AAA Outfit Give Testing 13" outfit "Supercapacitor" conversation action - attributes add hull -3300 - attributes add "cargo space" -410 - `Concluding v13` + attributes add hull 1300 + `Concluding v14. Flagship should have received 1300 hull, then 500. Cargo space increased by 34.` + + + +mission "AAA set Attribute Testing 15" + name "AAA set Attribute Testing v15" + description "Testing mission v15! This will add 1300 hull, then 500." + job + repeat + source + on accept + conversation + `Test text v15.` + on complete + attributes set shields 586 + payment 500 + outfit "Supercapacitor" + conversation + action + attributes set "bunks" 31 + `Concluding v15. Flagship should have shields set to 586, and bunks set to 31.` diff --git a/source/GameAction.cpp b/source/GameAction.cpp index b211800e05bd..3df4714de9e2 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -137,6 +137,23 @@ namespace { flagship->ChangeAttribute(targetAttribute, modifyAmount); } + + void DoSet(PlayerInfo &player, string targetAttribute, double setAmount) + { + // Get the player's flagship + Ship *flagship = player.Flagship(); + + string message; + message = "DoSet Has Been reached: " + targetAttribute + " " + to_string(setAmount); + Messages::Add(message, Messages::Importance::High); + + // Check if the player has a flagship, and if the attribute, and amount exist. + // If the player does not have one of these things, return without doing anything. + if(!flagship || targetAttribute.empty() || !setAmount) + return; + + flagship->SetAttribute(targetAttribute, setAmount); + } } @@ -255,15 +272,20 @@ void GameAction::LoadSingle(const DataNode &child) double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); modifyAttributes[attributeTarget] = valueChange; - child.PrintTrace("Trace: Test Data output L253: " + attributeTarget + " " + to_string(valueChange)); + child.PrintTrace("Trace: Test Data output L275: " + attributeTarget + " " + to_string(valueChange)); + } + else if(child.Token(1) == "set") + { + double valueChange = static_cast(child.Value(3)); + string attributeTarget = child.Token(2); + setAttributes[attributeTarget] = valueChange; + child.PrintTrace("Trace: Test Data output L282 (set): " + attributeTarget + " " + to_string(valueChange)); } } else if(child.Size() > 4) child.PrintTrace("Error: Skipping \"attributes\" as >4 values is not yet supported:"); else child.PrintTrace("Error: Skipping invalid values for \"attributes\":"); - // else if(child.Token(1) == "set") - // < code to put the attributes into the set map, to be done after the add is working > ; } else conditions.Add(child); @@ -344,6 +366,10 @@ void GameAction::Save(DataWriter &out) const { out.Write("attributes", "add", it.first, it.second); } + for(auto &&it : setAttributes) + { + out.Write("attributes", "set", it.first, it.second); + } conditions.Save(out); } @@ -427,6 +453,13 @@ const map &GameAction::ModifyAttributes() const noexcept +const map &GameAction::SetAttributes() const noexcept +{ + return setAttributes; +} + + + // Perform the specified tasks. void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const { @@ -532,6 +565,18 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const } } + // Set attributes. + player.AddLogEntry("GameAction L569 " + to_string(setAttributes.size())); + for(auto &&it : setAttributes) + { + player.AddLogEntry("GameAction L572"); + if(it.second) + { + DoSet(player, it.first, it.second); + player.AddLogEntry("GameAction L576"); + } + } + // Check if applying the conditions changes the player's reputations. conditions.Apply(player.Conditions()); } @@ -556,6 +601,7 @@ GameAction GameAction::Instantiate(map &subs, int jumps, int pay result.giftShips.push_back(it.Instantiate(subs)); result.giftOutfits = giftOutfits; result.modifyAttributes = modifyAttributes; + result.setAttributes = setAttributes; result.music = music; diff --git a/source/GameAction.h b/source/GameAction.h index 41425a041d7e..99545272316d 100644 --- a/source/GameAction.h +++ b/source/GameAction.h @@ -69,6 +69,7 @@ class GameAction { // references the map of attributes to be changed. const std::map &ModifyAttributes() const noexcept; + const std::map &SetAttributes() const noexcept; // Perform this action. void Do(PlayerInfo &player, UI *ui, const Mission *caller) const; @@ -98,6 +99,7 @@ class GameAction { std::vector giftShips; std::map giftOutfits; std::map modifyAttributes; + std::map setAttributes; int64_t payment = 0; int64_t paymentMultiplier = 0; diff --git a/source/Ship.cpp b/source/Ship.cpp index 2d41c057803e..9bf2b24f6493 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3763,7 +3763,6 @@ void Ship::AddOutfit(const Outfit *outfit, int count) // Add or reduce an attribute. (To reduce, pass a negative number.) void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) { - Logger::LogError("Ship.cpp L3770" + targetAttribute + " " + to_string(modifyAmount)); if(!targetAttribute.empty()) { double limiter = 0.; @@ -3839,6 +3838,84 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) +// Add or reduce an attribute. (To reduce, pass a negative number.) +void Ship::SetAttribute(string targetAttribute, double setAmount) +{ + Logger::LogError("Ship.cpp L3770" + targetAttribute + " " + to_string(setAmount)); + if(!targetAttribute.empty()) + { + double limiter = 0.; + double minAttributeValue = 0.; + double originalBaseValue = baseAttributes.Get(targetAttribute); + double originalValue = attributes.Get(targetAttribute); + double newBaseValue = originalBaseValue + setAmount; + double newValue = originalValue + setAmount; + + // Safety checks to ensure the new value is within parameters. + if(newBaseValue < 1. && newValue < 1. && targetAttribute == "hull") + { + // This means the minimum value for this attribute is 1.0 + minAttributeValue = 1.; + limiter = minAttributeValue - newBaseValue; + } + else if(newBaseValue < 0.01 && (targetAttribute == "drag" || targetAttribute == "mass")) + { + // This means the minimum value for these attributes is 0.01 + minAttributeValue = 0.01; + limiter = minAttributeValue - newBaseValue; + } + // Special handling for attributes that cannot be less than 0. + // These values can be 0, just they cannot be negative. + else if(newBaseValue < 0. && (targetAttribute == "outfit space" || targetAttribute == "cargo space" || + targetAttribute == "weapon capacity" || targetAttribute == "engine capacity" || + targetAttribute == "engine mod space" || targetAttribute == "shields" || + targetAttribute == "reverse thruster slot" || targetAttribute == "steering slot" || + targetAttribute == "thruster slot" || targetAttribute == "lateral thruster slot" || + targetAttribute == "bunks" || targetAttribute == "fuel capacity" || targetAttribute == "required crew")) + { + if(newBaseValue < 0.) + { + minAttributeValue = 0.; + limiter = minAttributeValue - newBaseValue; + } + } + + // Calculations take place here + newBaseValue += limiter; + newValue += limiter; + baseAttributes.Set(targetAttribute.c_str(), newBaseValue); + attributes.Set(targetAttribute.c_str(), newValue); + + // Ensuring the current hull value is changed as well. + if(targetAttribute == "hull") + { + // Adds the setAmount and the limiter to the current hull too. + hull += setAmount + limiter; + } + + if(targetAttribute == "cargo space") + { + cargo.SetSize(attributes.Get("cargo space")); + + // Only the player's ships make use of attraction and deterrence. + if(isYours) + attraction = CalculateAttraction(); + } + + // If the added or removed attribute is hyperdrive, scram drive, or jump drive capability, then + // recalibrate the navigation. + if((targetAttribute == "hyperdrive" || targetAttribute == "scram drive" || targetAttribute == "jump drive")) + navigation.Calibrate(*this); + // Navigation may still need to be recalibrated depending on the drives a ship has. + // Only do this for player ships as to display correct information on the map. + // Non-player ships will recalibrate before they jump. + else if(isYours) + navigation.Recalibrate(*this); + } +} + + + // Get the list of weapons. Armament &Ship::GetArmament() { diff --git a/source/Ship.h b/source/Ship.h index 702b4aa744da..9857d7d2ae7e 100644 --- a/source/Ship.h +++ b/source/Ship.h @@ -475,6 +475,7 @@ class Ship : public Body, public std::enable_shared_from_this { void AddOutfit(const Outfit *outfit, int count); void ChangeAttribute(std::string targetAttribute, double modifyAmount); + void SetAttribute(std::string targetAttribute, double setAmount); // Get the list of weapons. Armament &GetArmament(); From 3561e4b1dedb48b89e45499bad6679098c5243f1 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sat, 11 Jan 2025 23:50:59 -0500 Subject: [PATCH 17/28] Part 2. --- data/human/jobs.txt | 2 +- source/Ship.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 55001ce57ea7..fa6036d636bd 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5137,7 +5137,7 @@ mission "AAA modify Attribute Testing 14" mission "AAA set Attribute Testing 15" name "AAA set Attribute Testing v15" - description "Testing mission v15! This will add 1300 hull, then 500." + description "Testing mission v15! This will set shields to 586, and bunks to 31." job repeat source diff --git a/source/Ship.cpp b/source/Ship.cpp index 9bf2b24f6493..9f79c5277ae3 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3848,8 +3848,9 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) double minAttributeValue = 0.; double originalBaseValue = baseAttributes.Get(targetAttribute); double originalValue = attributes.Get(targetAttribute); - double newBaseValue = originalBaseValue + setAmount; - double newValue = originalValue + setAmount; + double newBaseValue = setAmount; + // double intermediaryValue = originalBaseValue - originalValue; + double newValue = setAmount; // Just need to incorporate a change to ensure it stays even with base. // Safety checks to ensure the new value is within parameters. if(newBaseValue < 1. && newValue < 1. && targetAttribute == "hull") From c473b6ed5289a774ede7c5c856f455ed36f5cf7f Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Sun, 12 Jan 2025 08:33:51 -0500 Subject: [PATCH 18/28] Additional testing jobs, and work on safeties In testing found that there's a slight problem when mass is set to negative. It displays wrong in-game, but then appears correctly at 0.01 after reloading. --- data/human/jobs.txt | 85 +++++++++++++++++++++++++++++++++++++++++++++ source/Ship.cpp | 27 ++++++++++++-- 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index fa6036d636bd..daaabeaeb6fe 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5152,4 +5152,89 @@ mission "AAA set Attribute Testing 15" action attributes set "bunks" 31 `Concluding v15. Flagship should have shields set to 586, and bunks set to 31.` + + + +mission "AAA set Attribute Testing 16" + name "AAA set Attribute Testing v16" + description "Testing mission v16! This will REDUCE hull by 200, shields by 300, and cargo space by 400. It will also try to set mass to -3, which should be caught and bumped up to 0.01 instead." + job + repeat + source + on accept + conversation + `Test text v15.` + on complete + attributes add "cargo space" -400 + payment 500 + outfit "Supercapacitor" + conversation + action + attributes set "mass" -3 + attributes add "hull" -200 + attributes add "shields" -300 + `Concluding v16. Flagship should have hull REDUCED by 200, shields by 300, and cargo space by 400. It will also try to set mass to -3, which should be caught and bumped up to 0.01 instead.` + + + +mission "AAA set Attribute Testing 17" + name "AAA set Attribute Testing v17" + description "Testing mission v17! This will set hull, shields, cargo space, and bunks to 100." + job + repeat + source + on accept + conversation + `Test text v15. Hull, shields, cargo space, and bunks will be set to 100 after you take off and land.` + on complete + attributes set hull 100 + attributes set shields 100 + payment 500 + outfit "Supercapacitor" + conversation + action + attributes set "bunks" 100 + attributes set "cargo space" 100 + `Concluding v17. Flagship should have bunks and cargo space set to 100; followed by hull and shields being set to 100.` + + + + +mission "AAA set Attribute Testing 18" + name "AAA set Attribute Testing v18" + description "Testing mission v18! This will set hmass to 123 and drag to 2.36." + job + repeat + source + on accept + conversation + `Test text v18. Sets drag to 2.36, and mass to 123. after you take off and land.` + on complete + attributes set mass 123 + payment 500 + outfit "Supercapacitor" + conversation + action + attributes set "drag" 2.36 + + + + +mission "AAA set Attribute Testing 19" + name "AAA set Attribute Testing v19" + description "Testing mission v18! This will set hmass to -45 and drag to 5.11." + job + repeat + source + on accept + conversation + `Test text v18. Sets drag to 5.11 and mass to -45. after you take off and land.` + on complete + attributes set mass -45 + payment 500 + outfit "Supercapacitor" + conversation + action + attributes set "drag" 5.11 + `Concluding v19. Sets drag to 5.11 and mass to -45.` diff --git a/source/Ship.cpp b/source/Ship.cpp index 9f79c5277ae3..24341e031d93 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3848,23 +3848,38 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) double minAttributeValue = 0.; double originalBaseValue = baseAttributes.Get(targetAttribute); double originalValue = attributes.Get(targetAttribute); + // This is to account for potential differences between the value in baseAttributes & Attributes. + double originalDifference = originalValue - originalBaseValue; double newBaseValue = setAmount; + double newValue = setAmount + originalDifference; + // double intermediaryValue = originalBaseValue - originalValue; - double newValue = setAmount; // Just need to incorporate a change to ensure it stays even with base. // Safety checks to ensure the new value is within parameters. - if(newBaseValue < 1. && newValue < 1. && targetAttribute == "hull") + if(newBaseValue < 1. && targetAttribute == "hull") { // This means the minimum value for this attribute is 1.0 minAttributeValue = 1.; limiter = minAttributeValue - newBaseValue; } + else if(newValue < 1. && targetAttribute == "hull") + { + // This means the minimum value for this attribute is 1.0 + minAttributeValue = 1.; + limiter = minAttributeValue - newValue; + } else if(newBaseValue < 0.01 && (targetAttribute == "drag" || targetAttribute == "mass")) { // This means the minimum value for these attributes is 0.01 minAttributeValue = 0.01; limiter = minAttributeValue - newBaseValue; } + else if(newValue < 0.01 && (targetAttribute == "drag" || targetAttribute == "mass")) + { + // This means the minimum value for these attributes is 0.01 + minAttributeValue = 0.01; + limiter = minAttributeValue - newValue; + } // Special handling for attributes that cannot be less than 0. // These values can be 0, just they cannot be negative. else if(newBaseValue < 0. && (targetAttribute == "outfit space" || targetAttribute == "cargo space" || @@ -3881,9 +3896,14 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) } } - // Calculations take place here + // This increases the value that baseAttributes and attributes are set to if they were below the + // minimum value. The way the if/else if statements are setup, if for some reason the player's + // current value is lower than the base value, then the amount they are reduced is itself reduced + // sufficiently that it does not drop it below the minimum value. + // If they are not special values with restrictions, this limiter should just be 0 and thus no effect. newBaseValue += limiter; newValue += limiter; + // These two lines are what actually sets the attributes. baseAttributes.Set(targetAttribute.c_str(), newBaseValue); attributes.Set(targetAttribute.c_str(), newValue); @@ -3894,6 +3914,7 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) hull += setAmount + limiter; } + // This just ensures the cargo is refreshed to be equal to the new attribute value. if(targetAttribute == "cargo space") { cargo.SetSize(attributes.Get("cargo space")); From 3e592fcc19cf695ac8da00aea3874cbe7a7e19ca Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Mon, 13 Jan 2025 07:36:13 -0500 Subject: [PATCH 19/28] Update to the job., --- data/human/jobs.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index daaabeaeb6fe..e2b957178d8f 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5216,6 +5216,7 @@ mission "AAA set Attribute Testing 18" conversation action attributes set "drag" 2.36 + `Concluding V18. Drag should be 2.36 and mass 123` From ab78bbaabc6ceb9ff85ed837825aeed90e169d5e Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:53:43 -0500 Subject: [PATCH 20/28] More test, and working except for certain safeties Mass and shields seem to have problems. --- data/human/jobs.txt | 244 +++++++++++++++++++++++++++++++++++++++++--- source/Ship.cpp | 7 ++ 2 files changed, 239 insertions(+), 12 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index e2b957178d8f..2e172dc24007 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5114,24 +5114,223 @@ mission "Banned Syndicate Items [4]" -mission "AAA modify Attribute Testing 14" - name "AAA modify Attribute Testing v14" - description "Testing mission v14! This will add 1300 hull, then 500." +mission "AAA 25 add hull 50" + name "AAA 25 add hull 50" + description "Testing mission 25! This will add 50 hull." job repeat source on accept + dialog + `Test text v25.` + on complete + attributes add hull 50 + payment 500000 + outfit "Supercapacitor" conversation - `Test text v14.` + `Concluding v25. Adds 50 hull.` + + + +mission "AAA 25 add hull -50" + name "AAA 25 add mass -50" + description "Testing mission v14! This will add -50 hull." + job + repeat + source + on accept + dialog + `Test text v25.` on complete - attributes add hull 60 - attributes add "cargo space" 34 - payment 500 + attributes add hull -50 + payment 500000 outfit "Supercapacitor" conversation - action - attributes add hull 1300 - `Concluding v14. Flagship should have received 1300 hull, then 500. Cargo space increased by 34.` + `Concluding v25. Adds -50 hull.` + + + +mission "AAA 25 add mass 50" + name "AAA 25 add mass 50" + description "Testing mission 25! This will add 50 hull." + job + repeat + source + on accept + dialog + `Test text v25.` + on complete + attributes add mass 50 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v25. Adds 50 mass.` + + + +mission "AAA 25 add mass -50" + name "AAA 25 add mass -50" + description "Testing mission v14! This will add -50 mass." + job + repeat + source + on accept + dialog + `Test text v25.` + on complete + attributes add mass -50 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v25. Adds -50 mass.` + + + +mission "AAA 25 add fuel capacity 50" + name "AAA 25 add fuel capacity 50" + description "Testing mission 25! This will add 50 fuel capacity." + job + repeat + source + on accept + dialog + `Test text v25.` + on complete + attributes add "fuel capacity" 50 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v25. Adds 50 fuel capacity.` + + + +mission "AAA 25 add fuel capacity -50" + name "AAA 25 add fuel capacity -50" + description "Testing mission 25! This will add -50 fuel capacity." + job + repeat + source + on accept + dialog + `Test text v25.` + on complete + attributes add "fuel capacity" -50 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v25. Adds -50 fuel capacity.` + + + +mission "AAA 75 add various 75" + name "AAA 75 add various 75" + description "Testing mission 25! This will add 75 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space." + job + repeat + source + on accept + dialog + `Test text v75.` + on complete + attributes add "fuel capacity" 75 + attributes add cost 75 + attributes add mass 75 + attributes add drag 75 + attributes add "engine capacity" 75 + attributes add "weapon capacity" 75 + attributes add "outfit space" 75 + attributes add "heat dissipation" 75 + attributes add hull 75 + attributes add bunks 75 + attributes add "cargo space" 75 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v75. This adds 75 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space."` + + + +mission "AAA 75 add various -75" + name "AAA 75 add various -75" + description "Testing mission 25! This will add 75 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space." + job + repeat + source + on accept + dialog + `Test text v75.` + on complete + attributes add "fuel capacity" -75 + attributes add cost -75 + attributes add mass -75 + attributes add drag -75 + attributes add "engine capacity" -75 + attributes add "weapon capacity" -75 + attributes add "outfit space" -75 + attributes add "heat dissipation" -75 + attributes add hull -75 + attributes add bunks -75 + attributes add "cargo space" -75 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v75. This adds 75 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space."` + + + +mission "AAA 75 set various 100" + name "AAA 75 set various 100" + description "Testing mission 25! This will set 100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space." + job + repeat + source + on accept + dialog + `Test text v75. set 100` + on complete + attributes set "fuel capacity" 100 + attributes set cost 100 + attributes set mass 100 + attributes set drag 100 + attributes set "engine capacity" 100 + attributes set "weapon capacity" 100 + attributes set "outfit space" 100 + attributes set "heat dissipation" 100 + attributes set hull 100 + attributes set bunks 100 + attributes set "cargo space" 100 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v75. This sets 100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space."` + + + +mission "AAA 75 set various -100" + name "AAA 75 set various -100" + description "Testing mission 25! This will set -100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space." + job + repeat + source + on accept + dialog + `Test text v75. set -100` + on complete + attributes set "fuel capacity" -100 + attributes set cost -100 + attributes set mass -100 + attributes set drag -100 + attributes set "engine capacity" -100 + attributes set "weapon capacity" -100 + attributes set "outfit space" -100 + attributes set "heat dissipation" -100 + attributes set hull -100 + attributes set bunks -100 + attributes set "cargo space" -100 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v75. This sets -100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space."` @@ -5223,13 +5422,13 @@ mission "AAA set Attribute Testing 18" mission "AAA set Attribute Testing 19" name "AAA set Attribute Testing v19" - description "Testing mission v18! This will set hmass to -45 and drag to 5.11." + description "Testing mission v18! This will set mass to -45 and drag to 5.11." job repeat source on accept conversation - `Test text v18. Sets drag to 5.11 and mass to -45. after you take off and land.` + `Test text v19. Sets drag to 5.11 and mass to -45. after you take off and land.` on complete attributes set mass -45 payment 500 @@ -5239,3 +5438,24 @@ mission "AAA set Attribute Testing 19" attributes set "drag" 5.11 `Concluding v19. Sets drag to 5.11 and mass to -45.` + + + +mission "AAA set Attribute Testing 20" + name "AAA set Attribute Testing v20" + description "Testing mission v20! This will ADD mass -45 and drag to 5.11." + job + repeat + source + on accept + conversation + `Test text v18. adds drag to -5.11 and mass to -45. after you take off and land.` + on complete + attributes add mass -45 + payment 500 + outfit "Supercapacitor" + conversation + action + attributes add "drag" -5.11 + `Concluding v19. Adds drag -5.11 and mass to -45.` + diff --git a/source/Ship.cpp b/source/Ship.cpp index 24341e031d93..ca3a95076e0d 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3814,6 +3814,13 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) // Adds the modifyAmount and the limiter to the current hull too. hull += modifyAmount + limiter; } + // Ensuring the current hull value is changed as well. + if(targetAttribute == "shields") + { + // Adds the modifyAmount and the limiter to the current shields too. + shields += modifyAmount + limiter; + } + // Ensuring the current shield value is changed as well. if(targetAttribute == "cargo space") { From e2f32062e415fb6030fb78be791b062921672c87 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:17:18 -0500 Subject: [PATCH 21/28] Need to add shields to these bulk tests. --- data/human/jobs.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 2e172dc24007..21996ca789bf 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5252,7 +5252,7 @@ mission "AAA 75 add various 75" mission "AAA 75 add various -75" name "AAA 75 add various -75" - description "Testing mission 25! This will add 75 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space." + description "Testing mission 25! This will add 75 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, shields, bunks, and cargo space." job repeat source @@ -5269,6 +5269,7 @@ mission "AAA 75 add various -75" attributes add "outfit space" -75 attributes add "heat dissipation" -75 attributes add hull -75 + attributes set shields -75 attributes add bunks -75 attributes add "cargo space" -75 payment 500000 @@ -5280,7 +5281,7 @@ mission "AAA 75 add various -75" mission "AAA 75 set various 100" name "AAA 75 set various 100" - description "Testing mission 25! This will set 100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space." + description "Testing mission 25! This will set 100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, shields, bunks, and cargo space." job repeat source @@ -5297,18 +5298,19 @@ mission "AAA 75 set various 100" attributes set "outfit space" 100 attributes set "heat dissipation" 100 attributes set hull 100 + attributes set shields 100 attributes set bunks 100 attributes set "cargo space" 100 payment 500000 outfit "Supercapacitor" conversation - `Concluding v75. This sets 100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space."` + `Concluding v75. This sets 100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, shields, and cargo space."` mission "AAA 75 set various -100" name "AAA 75 set various -100" - description "Testing mission 25! This will set -100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, bunks, and cargo space." + description "Testing mission 25! This will set -100 to fuel capacity, cost, mass, drag, engine capacity, weapon capacity, outfit space, heat dissipation, hull, shields, bunks, and cargo space." job repeat source @@ -5325,6 +5327,7 @@ mission "AAA 75 set various -100" attributes set "outfit space" -100 attributes set "heat dissipation" -100 attributes set hull -100 + attributes set shields -100 attributes set bunks -100 attributes set "cargo space" -100 payment 500000 From 715198b25bb2eaa6786da8e2f08d322549638f6a Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:19:17 -0500 Subject: [PATCH 22/28] ensuring shields are changed too. --- source/Ship.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/Ship.cpp b/source/Ship.cpp index ca3a95076e0d..bf59b3071b79 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3814,13 +3814,13 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) // Adds the modifyAmount and the limiter to the current hull too. hull += modifyAmount + limiter; } - // Ensuring the current hull value is changed as well. + + // Ensuring the current shields value is changed as well. if(targetAttribute == "shields") { // Adds the modifyAmount and the limiter to the current shields too. shields += modifyAmount + limiter; } - // Ensuring the current shield value is changed as well. if(targetAttribute == "cargo space") { @@ -3921,6 +3921,13 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) hull += setAmount + limiter; } + // Ensuring the current shields value is changed as well. + if(targetAttribute == "shields") + { + // Adds the setAmount and the limiter to the current hull too. + shields += setAmount + limiter; + } + // This just ensures the cargo is refreshed to be equal to the new attribute value. if(targetAttribute == "cargo space") { From daedf7bc5c3cdb0891677c2e4dcc0bb36cbd8aaf Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:41:46 -0500 Subject: [PATCH 23/28] Everything's working except Mass and Cost. Those only take effect after reloading --- data/human/jobs.txt | 35 +++++++++++++++++++++++++++++++++++ source/Ship.cpp | 4 ++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 21996ca789bf..53ae362fb174 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5204,6 +5204,24 @@ mission "AAA 25 add fuel capacity 50" +mission "AAA 25 set mass 75" + name "AAA 25 set mass 75" + description "Testing mission 25! This will set mass 75" + job + repeat + source + on accept + dialog + `Test text v25.` + on complete + attributes set mass 75 + payment 500000 + outfit "Supercapacitor" + conversation + `Concluding v25. Set mass 75.` + + + mission "AAA 25 add fuel capacity -50" name "AAA 25 add fuel capacity -50" description "Testing mission 25! This will add -50 fuel capacity." @@ -5461,4 +5479,21 @@ mission "AAA set Attribute Testing 20" action attributes add "drag" -5.11 `Concluding v19. Adds drag -5.11 and mass to -45.` + + + +mission "AAA 30 set drag 1" + name "AAA 25 set drag 1" + description "Testing mission 25! This will set drag 1" + job + repeat + source + on accept + dialog + `Test text v30.` + on complete + attributes set drag 1 + payment 500000 + conversation + `Concluding v30. Set drag 1.` diff --git a/source/Ship.cpp b/source/Ship.cpp index bf59b3071b79..d7eaf9bd94de 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3805,7 +3805,7 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) newBaseValue += limiter; newValue += limiter; baseAttributes.Set(targetAttribute.c_str(), newBaseValue); - attributes.Set(targetAttribute.c_str(), newValue); + // attributes.Set(targetAttribute.c_str(), newValue); // Ensuring the current hull value is changed as well. @@ -3912,7 +3912,7 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) newValue += limiter; // These two lines are what actually sets the attributes. baseAttributes.Set(targetAttribute.c_str(), newBaseValue); - attributes.Set(targetAttribute.c_str(), newValue); + // attributes.Set(targetAttribute.c_str(), newValue); // Ensuring the current hull value is changed as well. if(targetAttribute == "hull") From 4255ad89a19a0997deebb156d15783cee5e19b00 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 16 Jan 2025 08:53:56 -0500 Subject: [PATCH 24/28] Special handling for Modify Mass, works nicely. --- data/human/jobs.txt | 4 ++-- source/Outfit.cpp | 10 ++++++++++ source/Outfit.h | 2 ++ source/Ship.cpp | 13 +++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/data/human/jobs.txt b/data/human/jobs.txt index 53ae362fb174..ad2581b92c1a 100644 --- a/data/human/jobs.txt +++ b/data/human/jobs.txt @@ -5133,7 +5133,7 @@ mission "AAA 25 add hull 50" mission "AAA 25 add hull -50" - name "AAA 25 add mass -50" + name "AAA 25 add hull -50" description "Testing mission v14! This will add -50 hull." job repeat @@ -5152,7 +5152,7 @@ mission "AAA 25 add hull -50" mission "AAA 25 add mass 50" name "AAA 25 add mass 50" - description "Testing mission 25! This will add 50 hull." + description "Testing mission 25! This will add 50 mass." job repeat source diff --git a/source/Outfit.cpp b/source/Outfit.cpp index 416a28f051eb..6fbdabf3e513 100644 --- a/source/Outfit.cpp +++ b/source/Outfit.cpp @@ -747,3 +747,13 @@ void Outfit::AddLicense(const string &name) if(it == licenses.end()) licenses.push_back(name); } + + + +// Modify this outfit's attributes. +void Outfit::ModifyMass(double value) +{ + mass += value; + // Don't allow mass to go to zero or less. + mass = (mass <= 0 ? 0.01 : mass); +} diff --git a/source/Outfit.h b/source/Outfit.h index efa2052b6e77..b7f9e8ab3a57 100644 --- a/source/Outfit.h +++ b/source/Outfit.h @@ -85,6 +85,8 @@ class Outfit : public Weapon { // Modify this outfit's attributes. Note that this cannot be used to change // special attributes, like cost and mass. void Set(const char *attribute, double value); + // Modify or set this outfit's mass. + void ModifyMass(double value); // Get this outfit's engine flare sprites, if any. const std::vector> &FlareSprites() const; diff --git a/source/Ship.cpp b/source/Ship.cpp index d7eaf9bd94de..a9bcee524246 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3804,9 +3804,18 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) // Calculations take place here newBaseValue += limiter; newValue += limiter; - baseAttributes.Set(targetAttribute.c_str(), newBaseValue); - // attributes.Set(targetAttribute.c_str(), newValue); + if(targetAttribute == "mass") + { + // Call the special method just for mass. + baseAttributes.ModifyMass(newBaseValue); + attributes.ModifyMass(newValue); + } + else + { + baseAttributes.Set(targetAttribute.c_str(), newBaseValue); + attributes.Set(targetAttribute.c_str(), newValue); + } // Ensuring the current hull value is changed as well. if(targetAttribute == "hull") From d5effdbfb416121e5d077cdcd3368fbcd4487da0 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 16 Jan 2025 09:01:47 -0500 Subject: [PATCH 25/28] SetMass (and GetMass) now appear to be working!) SetMass and ModifyMass can probably be condensced at this point, but one thing at a time. --- source/Outfit.cpp | 18 ++++++++++++++++++ source/Outfit.h | 3 +++ source/Ship.cpp | 28 +++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/source/Outfit.cpp b/source/Outfit.cpp index 6fbdabf3e513..0cbcdf937eac 100644 --- a/source/Outfit.cpp +++ b/source/Outfit.cpp @@ -750,6 +750,14 @@ void Outfit::AddLicense(const string &name) +// Modify this outfit's attributes. +const double Outfit::GetMass() const +{ + return mass; +} + + + // Modify this outfit's attributes. void Outfit::ModifyMass(double value) { @@ -757,3 +765,13 @@ void Outfit::ModifyMass(double value) // Don't allow mass to go to zero or less. mass = (mass <= 0 ? 0.01 : mass); } + + + +// Set this outfit's attributes. +void Outfit::SetMass(double MassDif) +{ + mass += MassDif; + // Don't allow mass to go to zero or less. + mass = (mass <= 0 ? 0.01 : mass); +} diff --git a/source/Outfit.h b/source/Outfit.h index b7f9e8ab3a57..1cc5bfc762fa 100644 --- a/source/Outfit.h +++ b/source/Outfit.h @@ -85,8 +85,11 @@ class Outfit : public Weapon { // Modify this outfit's attributes. Note that this cannot be used to change // special attributes, like cost and mass. void Set(const char *attribute, double value); + // Get this things's mass. + const double GetMass() const; // Modify or set this outfit's mass. void ModifyMass(double value); + void SetMass(double value); // Get this outfit's engine flare sprites, if any. const std::vector> &FlareSprites() const; diff --git a/source/Ship.cpp b/source/Ship.cpp index a9bcee524246..6a7a714bbb66 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3864,6 +3864,8 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) double minAttributeValue = 0.; double originalBaseValue = baseAttributes.Get(targetAttribute); double originalValue = attributes.Get(targetAttribute); + Logger::LogError("Ship.cpp L3867 originalBaseValue is " + targetAttribute + " " + to_string(originalBaseValue)); + Logger::LogError("Ship.cpp L3868 originalValue is " + targetAttribute + " " + to_string(originalValue)); // This is to account for potential differences between the value in baseAttributes & Attributes. double originalDifference = originalValue - originalBaseValue; double newBaseValue = setAmount; @@ -3884,13 +3886,13 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) minAttributeValue = 1.; limiter = minAttributeValue - newValue; } - else if(newBaseValue < 0.01 && (targetAttribute == "drag" || targetAttribute == "mass")) + else if(newBaseValue < 0.01 && targetAttribute == "drag") { // This means the minimum value for these attributes is 0.01 minAttributeValue = 0.01; limiter = minAttributeValue - newBaseValue; } - else if(newValue < 0.01 && (targetAttribute == "drag" || targetAttribute == "mass")) + else if(newValue < 0.01 && targetAttribute == "drag") { // This means the minimum value for these attributes is 0.01 minAttributeValue = 0.01; @@ -3919,9 +3921,25 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) // If they are not special values with restrictions, this limiter should just be 0 and thus no effect. newBaseValue += limiter; newValue += limiter; - // These two lines are what actually sets the attributes. - baseAttributes.Set(targetAttribute.c_str(), newBaseValue); - // attributes.Set(targetAttribute.c_str(), newValue); + + if(targetAttribute == "mass") + { + // Call the special method just for mass. + // double dummyValue = 0.; + double OriginalBaseMass = baseAttributes.GetMass(); + double OriginalMass = attributes.GetMass(); + double MassDif = setAmount - OriginalBaseMass; + Logger::LogError("Ship.cpp L3926 OriginalBaseMass is " + targetAttribute + " " + to_string(OriginalBaseMass)); + Logger::LogError("Ship.cpp L3927 OriginalMass is " + targetAttribute + " " + to_string(OriginalMass)); + baseAttributes.SetMass(MassDif); + attributes.SetMass(MassDif); + } + else + { + // These two lines are what actually sets the attributes. + baseAttributes.Set(targetAttribute.c_str(), newBaseValue); + attributes.Set(targetAttribute.c_str(), newValue); + } // Ensuring the current hull value is changed as well. if(targetAttribute == "hull") From d4df6722beabe42eb5db4c5d519d1d65d02cfa18 Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:53:33 -0500 Subject: [PATCH 26/28] Set mass now works. --- source/Outfit.cpp | 8 -------- source/Ship.cpp | 32 ++++++++++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/source/Outfit.cpp b/source/Outfit.cpp index 0cbcdf937eac..0ea6d3016c2d 100644 --- a/source/Outfit.cpp +++ b/source/Outfit.cpp @@ -750,14 +750,6 @@ void Outfit::AddLicense(const string &name) -// Modify this outfit's attributes. -const double Outfit::GetMass() const -{ - return mass; -} - - - // Modify this outfit's attributes. void Outfit::ModifyMass(double value) { diff --git a/source/Ship.cpp b/source/Ship.cpp index 6a7a714bbb66..400cb8384b75 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3812,10 +3812,10 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) attributes.ModifyMass(newValue); } else - { - baseAttributes.Set(targetAttribute.c_str(), newBaseValue); - attributes.Set(targetAttribute.c_str(), newValue); - } + { + baseAttributes.Set(targetAttribute.c_str(), newBaseValue); + attributes.Set(targetAttribute.c_str(), newValue); + } // Ensuring the current hull value is changed as well. if(targetAttribute == "hull") @@ -3925,14 +3925,22 @@ void Ship::SetAttribute(string targetAttribute, double setAmount) if(targetAttribute == "mass") { // Call the special method just for mass. - // double dummyValue = 0.; - double OriginalBaseMass = baseAttributes.GetMass(); - double OriginalMass = attributes.GetMass(); - double MassDif = setAmount - OriginalBaseMass; - Logger::LogError("Ship.cpp L3926 OriginalBaseMass is " + targetAttribute + " " + to_string(OriginalBaseMass)); - Logger::LogError("Ship.cpp L3927 OriginalMass is " + targetAttribute + " " + to_string(OriginalMass)); - baseAttributes.SetMass(MassDif); - attributes.SetMass(MassDif); + double OriginalBaseMass = baseAttributes.Mass(); + double OriginalMass = attributes.Mass(); + double MassDif = OriginalMass - OriginalBaseMass; + if(setAmount < 0.01) + { + setAmount = 0.01; + } + double NewBaseMass = setAmount; + double NewMass = setAmount + MassDif; + if(NewMass < 0.01) + { + NewMass = 0.01; + NewBaseMass = NewMass - MassDif; + } + baseAttributes.SetMass(NewBaseMass); + attributes.SetMass(NewMass); } else { From 399f38e8a704a9430b8f1e29fdf0cf1795e328ed Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:42:18 -0500 Subject: [PATCH 27/28] Remove unneeded error tracing & logging code --- source/GameAction.cpp | 16 ---------------- source/Ship.cpp | 5 +---- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/source/GameAction.cpp b/source/GameAction.cpp index 3df4714de9e2..89394ebdd434 100644 --- a/source/GameAction.cpp +++ b/source/GameAction.cpp @@ -126,10 +126,6 @@ namespace { // Get the player's flagship Ship *flagship = player.Flagship(); - string message; - message = "DoModify Has Been reached: " + targetAttribute + " " + to_string(modifyAmount); - Messages::Add(message, Messages::Importance::High); - // Check if the player has a flagship, and if the attribute, and amount exist. // If the player does not have one of these things, return without doing anything. if(!flagship || targetAttribute.empty() || !modifyAmount) @@ -143,10 +139,6 @@ namespace { // Get the player's flagship Ship *flagship = player.Flagship(); - string message; - message = "DoSet Has Been reached: " + targetAttribute + " " + to_string(setAmount); - Messages::Add(message, Messages::Importance::High); - // Check if the player has a flagship, and if the attribute, and amount exist. // If the player does not have one of these things, return without doing anything. if(!flagship || targetAttribute.empty() || !setAmount) @@ -272,14 +264,12 @@ void GameAction::LoadSingle(const DataNode &child) double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); modifyAttributes[attributeTarget] = valueChange; - child.PrintTrace("Trace: Test Data output L275: " + attributeTarget + " " + to_string(valueChange)); } else if(child.Token(1) == "set") { double valueChange = static_cast(child.Value(3)); string attributeTarget = child.Token(2); setAttributes[attributeTarget] = valueChange; - child.PrintTrace("Trace: Test Data output L282 (set): " + attributeTarget + " " + to_string(valueChange)); } } else if(child.Size() > 4) @@ -554,26 +544,20 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const } // Modify attributes. - player.AddLogEntry("GameAction L520 " + to_string(modifyAttributes.size())); for(auto &&it : modifyAttributes) { - player.AddLogEntry("GameAction L523"); if(it.second) { DoModify(player, it.first, it.second); - player.AddLogEntry("GameAction L527"); } } // Set attributes. - player.AddLogEntry("GameAction L569 " + to_string(setAttributes.size())); for(auto &&it : setAttributes) { - player.AddLogEntry("GameAction L572"); if(it.second) { DoSet(player, it.first, it.second); - player.AddLogEntry("GameAction L576"); } } diff --git a/source/Ship.cpp b/source/Ship.cpp index 400cb8384b75..ec25196e432d 100644 --- a/source/Ship.cpp +++ b/source/Ship.cpp @@ -3854,18 +3854,15 @@ void Ship::ChangeAttribute(string targetAttribute, double modifyAmount) -// Add or reduce an attribute. (To reduce, pass a negative number.) +// Sets an attribute to a specific value. Certain values (mass, drag, space, etc.) have limits. void Ship::SetAttribute(string targetAttribute, double setAmount) { - Logger::LogError("Ship.cpp L3770" + targetAttribute + " " + to_string(setAmount)); if(!targetAttribute.empty()) { double limiter = 0.; double minAttributeValue = 0.; double originalBaseValue = baseAttributes.Get(targetAttribute); double originalValue = attributes.Get(targetAttribute); - Logger::LogError("Ship.cpp L3867 originalBaseValue is " + targetAttribute + " " + to_string(originalBaseValue)); - Logger::LogError("Ship.cpp L3868 originalValue is " + targetAttribute + " " + to_string(originalValue)); // This is to account for potential differences between the value in baseAttributes & Attributes. double originalDifference = originalValue - originalBaseValue; double newBaseValue = setAmount; From ae41198ca40ca2817766bf73cf869560846b4aac Mon Sep 17 00:00:00 2001 From: Zitchas <32169904+Zitchas@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:37:38 -0500 Subject: [PATCH 28/28] Fixes --- data/korath/korath ships.txt | 3 ++- data/korath/korath variants.txt | 1 - data/persons.txt | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data/korath/korath ships.txt b/data/korath/korath ships.txt index 72b995cdb714..b253d2c3bcea 100644 --- a/data/korath/korath ships.txt +++ b/data/korath/korath ships.txt @@ -1183,6 +1183,7 @@ ship "Korsmanath A'awoj" "outfit space" 3279 "weapon capacity" 1148 "engine capacity" 579 + "lateral thruster slot" 2 "reverse thruster slot" 2 "steering slot" 2 "thruster slot" 2 @@ -1213,8 +1214,8 @@ ship "Korsmanath A'awoj" "Afterburner (Stellar Class)" "Reverser (Stellar Class)" "Thruster (Stellar Class)" - "Lateral (Stellar Class)" "Thruster (Planetary Class)" + "Lateral (Stellar Class)" "Lateral (Planetary Class)" "Steering (Stellar Class)" "Steering (Planetary Class)" diff --git a/data/korath/korath variants.txt b/data/korath/korath variants.txt index 7c8959ff638d..94f08f11a3b2 100644 --- a/data/korath/korath variants.txt +++ b/data/korath/korath variants.txt @@ -455,7 +455,6 @@ ship "'nra'ret" "'nra'ret (Crippler)" "Steering (Planetary Class)" "Thruster (Lunar Class)" "Lateral (Lunar Class)" - "Lateral (Lunar Class)" "Jump Drive" gun "Korath Detainer" diff --git a/data/persons.txt b/data/persons.txt index 40768b710922..84ad378659d3 100644 --- a/data/persons.txt +++ b/data/persons.txt @@ -1472,6 +1472,7 @@ ship "Modified Boxwing" "outfit space" 350 "weapon capacity" 130 "engine capacity" 100 + "lateral thruster slot" 1 "reverse thruster slot" 1 "steering slot" 2 "thruster slot" 2 @@ -2048,6 +2049,7 @@ ship "Waverider" "outfit space" 362 "weapon capacity" 120 "engine capacity" 75 + "lateral thruster slot" 1 "reverse thruster slot" 1 "steering slot" 2 "thruster slot" 1