Nothing entered.
==== Related links ====
=====
Bug #5543 =====
* Found that this bug was already reported after I encountered it myself
* Originally responded there including the suggested patch but I've transferred that response below
===== https://ufoai.org/wiki/Talk:Mapping/Entities/misc_mission =====
> ===== Known problems =====
>
> ...
>
> * It was reported that winning a mission this way resulted in an overall loss in nation happyness. We need to look into this and make sure mission targets are a valid way to win a mission. --ShipIt (talk) 06:47, 9 February 2017 (CET)
===== Patch #5640 =====
* Just noticed patch #5640 in preparation for this patch submission
* Unfortunately, that patch doesn't achieve its intended goal -- will provide more details on that page
* If there is any interest, this patch can easily be extended to provide the functionality that is desired by that patch
==== Response (with improvements) transferred from
Bug #5543 ====
===== Discussion =====
I recently ran into the same problem as
@anonymissimus
. Disposed of 3 out of 8 aliens before completing the mission (all 8 civilians saved) but got hit by a substantial happiness reduction across the nations. Noticed this due to a little modification I had running on the stats page, which informed me that the happiness had gone from 58.7% down to 53.6%. Since both values are still `Pleased`, could have easily missed this loss otherwise. Without any change in rating, the only way to tell from the standard UI would be to click through to the graph, to see the major drop in funding.
Did some code perusal and came up with the following patch as an example of how this could be handled. An overview of what it entails:
* Essentially, the main check is that the mission is both `won` and has a newly-introduced `victoryBonusPerAlien` value set in the map definition
** If this is the case, any remaining aliens will not be considered when calculating `performanceAlien`
** Furthermore, this is a step towards the comment directly above the calculation: "In a mission that has a special objective, the amount of killed aliens should only serve to increase the score, not reduce the penalty."
* Calculations will remain standard wherever `victoryBonusPerAlien` hasn't been set (or is 0 or less)
** It is envisaged that `victoryBonusPerAlien` would only need to be provided when the `victoryCondition` is being specified
* This patch isn't limited to the `mansion` map -- `victoryBonusPerAlien` can be set in any map definition
** With my relatively brief perusal, couldn't identify any further maps which suffer from this bug as of yet
* In the longer-term, utilising a method similar to this could allow for more nuanced calculations; e.g. beyond alien bonuses, could even differentiate between maps where civilian casualties carry greater/lesser ramifications
** I.e. Saving 8-10 civilians on some maps is a great deal easier than other maps -- that could be a factor set in the map definitions, to be used in the calculations
To give an idea of the results obtained (using the `0.05` value set for `victoryBonusPerAlien` in the map definition), pushed some output to the console after auto-mission testing (8 aliens killed but also all civilians dead):
<source lang="">
Calculated `performanceCivilian` value of [-0.500]
Calculated `performanceAlien` value of [0.400]
Calculated `performance` value of [-0.100]
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Revolutionary Countries
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: United America
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: The Greater European Union
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: The Asian Republic
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Middle-Eastern Alliance
[STATS] 0.617 + (-0.100 * 0.013) = 0.617 + -0.001 = 0.616 -- Pleased [0.617] => Pleased [0.616] (rounded: [0.616]) -- Nation: New Africa
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: Russia
[STATS] 0.587 + (-0.100 * 0.013) = 0.587 + -0.001 = 0.586 -- Pleased [0.587] => Pleased [0.586] (rounded: [0.586]) -- Nation: The Commonwealth of Oceania
</source>
And if the auto-mission is lost:
<source lang="">
Calculated `performanceCivilian` value of [-0.500]
Calculated `performanceAlien` value of [-8.000]
Calculated `performance` value of [-8.500]
[STATS] 0.587 + (-8.500 * 0.013) = 0.587 + -0.109 = 0.479 -- Pleased [0.587] => Content [0.479] (rounded: [0.479]) -- Nation: The Revolutionary Countries
[STATS] 0.587 + (-8.500 * 0.013) = 0.587 + -0.109 = 0.479 -- Pleased [0.587] => Content [0.479] (rounded: [0.479]) -- Nation: United America
[STATS] 0.617 + (-8.500 * 0.013) = 0.617 + -0.109 = 0.509 -- Pleased [0.617] => Pleased [0.509] (rounded: [0.509]) -- Nation: The Greater European Union
[STATS] 0.617 + (-8.500 * 0.013) = 0.617 + -0.109 = 0.509 -- Pleased [0.617] => Pleased [0.509] (rounded: [0.509]) -- Nation: The Asian Republic
[STATS] 0.587 + (-8.500 * 0.013) = 0.587 + -0.109 = 0.479 -- Pleased [0.587] => Content [0.479] (rounded: [0.479]) -- Nation: The Middle-Eastern Alliance
[STATS] 0.617 + (-8.500 * 0.013) = 0.617 + -0.109 = 0.509 -- Pleased [0.617] => Pleased [0.509] (rounded: [0.509]) -- Nation: New Africa
[STATS] 0.587 + (-8.500 * 0.013) = 0.587 + -0.109 = 0.479 -- Pleased [0.587] => Content [0.479] (rounded: [0.479]) -- Nation: Russia
[STATS] 0.587 + (-8.500 * 0.013) = 0.587 + -0.109 = 0.479 -- Pleased [0.587] => Content [0.479] (rounded: [0.479]) -- Nation: The Commonwealth of Oceania
</source>
===== Patch =====
<source lang="diff">
Subject: [PATCH 1/1] * Fix {{bug|5543}} mansion won via target zone reduces
nation happiness
---
base/ufos/maps.ufo | 3 +++
eclipse/net.sourceforge.ufoai.dsl/resources/rules.properties | 1 +
src/client/cgame/campaign/cp_missions.cpp | 2 +-
src/client/cgame/campaign/cp_nation.cpp | 10 ++++++++--
src/client/cgame/campaign/cp_nation.h | 2 +-
src/common/scripts.cpp | 1 +
src/game/q_shared.h | 1 +
7 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/base/ufos/maps.ufo b/base/ufos/maps.ufo
index 751e236431..8667f0a10b 100644
--- a/base/ufos/maps.ufo
+++ b/base/ufos/maps.ufo
@@ -2495,6 +2495,7 @@ mapdef mansion_huge
missionbriefing "*msgid:mission_briefing_mansion"
victorycondition "*msgid:victory_condition_mansion"
+ victorybonusperalien 0.05
multiplayer true
teams 4
@@ -2551,6 +2552,7 @@ mapdef mansion_medium
missionbriefing "*msgid:mission_briefing_mansion"
victorycondition "*msgid:victory_condition_mansion"
+ victorybonusperalien 0.05
multiplayer true
teams 2
@@ -2601,6 +2603,7 @@ mapdef mansion_small
missionbriefing "*msgid:mission_briefing_mansion"
victorycondition "*msgid:victory_condition_mansion"
+ victorybonusperalien 0.05
multiplayer true
teams 2
diff --git a/eclipse/net.sourceforge.ufoai.dsl/resources/rules.properties b/eclipse/net.sourceforge.ufoai.dsl/resources/rules.properties
index 44109e0052..177695fdbe 100644
--- a/eclipse/net.sourceforge.ufoai.dsl/resources/rules.properties
+++ b/eclipse/net.sourceforge.ufoai.dsl/resources/rules.properties
@@ -480,6 +480,7 @@ mapdef.teams = INT
mapdef.gametypes = LIST
mapdef.description = TRANSLATED_STRING
mapdef.victorycondition = TRANSLATED_STRING
+mapdef.victorybonusperalien = REAL
mapdef.missionbriefing = TRANSLATED_STRING
mapdef.maxaliens = INT
mapdef.civilianteam = ID
diff --git a/src/client/cgame/campaign/cp_missions.cpp b/src/client/cgame/campaign/cp_missions.cpp
index 7fbdf5b44e..3f12bb1c4f 100644
--- a/src/client/cgame/campaign/cp_missions.cpp
+++ b/src/client/cgame/campaign/cp_missions.cpp
@@ -1266,7 +1266,7 @@ void CP_MissionEnd (const campaign_t* campaign, mission_t* mission, const battle
won ? ccs.campaignStats.missionsWon++ : ccs.campaignStats.missionsLost++;
- CP_HandleNationData(campaign->minhappiness, mission, battleParameters->nation, &(mission->missionResults));
+ CP_HandleNationData(campaign->minhappiness, mission, battleParameters->nation, &(mission->missionResults), won);
CP_CheckLostCondition(campaign);
/* update the character stats */
diff --git a/src/client/cgame/campaign/cp_nation.cpp b/src/client/cgame/campaign/cp_nation.cpp
index 11249c8b84..8601465661 100644
--- a/src/client/cgame/campaign/cp_nation.cpp
+++ b/src/client/cgame/campaign/cp_nation.cpp
@@ -243,12 +243,14 @@ bool NAT_SaveXML (xmlNode_t* p)
* surrounding nations will be less affected.
* @todo Scoring should eventually be expanded to include such elements as
* infected humans and mission objectives other than xenocide.
+ * @param[in] won if PHALANX won
*/
-void CP_HandleNationData (float minHappiness, mission_t* mis, const nation_t* affectedNation, const missionResults_t* results)
+void CP_HandleNationData (float minHappiness, mission_t* mis, const nation_t* affectedNation, const missionResults_t* results, bool won)
{
const float civilianSum = (float) (results->civiliansSurvived + results->civiliansKilled + results->civiliansKilledFriendlyFire);
const float alienSum = (float) (results->aliensSurvived + results->aliensKilled + results->aliensStunned);
float performance;
+ float performanceAlien;
float deltaHappiness = 0.0f;
float happinessDivisor = 5.0f;
@@ -265,7 +267,11 @@ void CP_HandleNationData (float minHappiness, mission_t* mis, const nation_t* af
* should be dependent on the mission objective.
* In a mission that has a special objective, the amount of killed aliens should
* only serve to increase the score, not reduce the penalty. */
- float performanceAlien = results->aliensKilled + results->aliensStunned - alienSum;
+ if (won && mis->mapDef->victoryBonusPerAlien > 0) {
+ performanceAlien = (results->aliensKilled + results->aliensStunned) * mis->mapDef->victoryBonusPerAlien;
+ } else {
+ performanceAlien = results->aliensKilled + results->aliensStunned - alienSum;
+ }
performance = performanceCivilian + performanceAlien;
}
diff --git a/src/client/cgame/campaign/cp_nation.h b/src/client/cgame/campaign/cp_nation.h
index 1b24ff72ae..c93d6ab4be 100644
--- a/src/client/cgame/campaign/cp_nation.h
+++ b/src/client/cgame/campaign/cp_nation.h
@@ -80,7 +80,7 @@ void NAT_SetHappiness(const float minhappiness, nation_t* nation, const float ha
int NAT_GetFunding(const nation_t* const nation, int month);
const nationInfo_t* NAT_GetCurrentMonthInfo(const nation_t* const nation);
const char* NAT_GetHappinessString(const nation_t* nation);
-void CP_HandleNationData(float minHappiness, struct mission_s* mis, const nation_t* nation, const struct missionResults_s* results);
+void CP_HandleNationData(float minHappiness, struct mission_s* mis, const nation_t* nation, const struct missionResults_s* results, bool won);
void CL_ParseNations(const char* name, const char** text);
diff --git a/src/common/scripts.cpp b/src/common/scripts.cpp
index 9a229e872b..3c406ddfb0 100644
--- a/src/common/scripts.cpp
+++ b/src/common/scripts.cpp
@@ -3465,6 +3465,7 @@ static void Com_AddObjectLinks (void)
static const value_t mapdef_vals[] = {
{"description", V_TRANSLATION_STRING, offsetof(mapDef_t, description), 0},
{"victorycondition", V_TRANSLATION_STRING, offsetof(mapDef_t, victoryCondition), 0},
+ {"victorybonusperalien", V_FLOAT, offsetof(mapDef_t, victoryBonusPerAlien), MEMBER_SIZEOF(mapDef_t, victoryBonusPerAlien)},
{"missionbriefing", V_TRANSLATION_STRING, offsetof(mapDef_t, missionBriefing), 0},
{"map", V_HUNK_STRING, offsetof(mapDef_t, mapTheme), 0},
{"size", V_HUNK_STRING, offsetof(mapDef_t, size), 0},
diff --git a/src/game/q_shared.h b/src/game/q_shared.h
index 2ecd489690..43b030e5fc 100644
--- a/src/game/q_shared.h
+++ b/src/game/q_shared.h
@@ -465,6 +465,7 @@ typedef struct mapDef_s {
linkedList_t* params; /**< in case of ump file, the assembly to use */
char* description; /**< the description to show in the menus */
char* victoryCondition; /**< the mission briefing victory condition */
+ float victoryBonusPerAlien; /**< for missions other than "kill all aliens", the bonus value to use for each alien killed and stunned */
char* missionBriefing; /**< the mission briefing description */
char* size; /**< small, medium, big */
char* civTeam; /**< the civilian team to use for this map - this can also be nullptr */
--
2.14.1
</source>