[Scummvm-git-logs] scummvm master -> ddc1a485b75fe492e4aad6b0e61a8fc20214ede0

dreammaster noreply at scummvm.org
Sun Nov 5 08:17:52 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ddc1a485b7 MM: MM1: Split _age into _age and _ageDayCtr


Commit: ddc1a485b75fe492e4aad6b0e61a8fc20214ede0
    https://github.com/scummvm/scummvm/commit/ddc1a485b75fe492e4aad6b0e61a8fc20214ede0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-11-04T22:14:26-10:00

Commit Message:
MM: MM1: Split _age into _age and _ageDayCtr

I originally thought _age was an attribute pair, but the second
field is actually a counter that's incremented during rest,
and when it overflows increases the character's age by a year.
As such they are distinct fields. And in fact, separating it
revealed multiple places the "current" field was being changed
when the base _age was intended. These are all fixed now.

Changed paths:
    engines/mm/mm1/data/character.cpp
    engines/mm/mm1/data/character.h
    engines/mm/mm1/game/arrested.cpp
    engines/mm/mm1/game/equip_remove.cpp
    engines/mm/mm1/game/monster_touch.cpp
    engines/mm/mm1/game/spells_party.cpp
    engines/mm/mm1/game/use_item.cpp
    engines/mm/mm1/maps/map30.cpp
    engines/mm/mm1/views/locations/temple.cpp
    engines/mm/mm1/views_enh/character_info.cpp
    engines/mm/mm1/views_enh/locations/temple.cpp


diff --git a/engines/mm/mm1/data/character.cpp b/engines/mm/mm1/data/character.cpp
index 4911cc337ec..79bb7b78980 100644
--- a/engines/mm/mm1/data/character.cpp
+++ b/engines/mm/mm1/data/character.cpp
@@ -189,7 +189,8 @@ void Character::synchronize(Common::Serializer &s, int portraitNum) {
 	_accuracy.synchronize(s);
 	_luck.synchronize(s);
 	_level.synchronize(s);
-	_age.synchronize(s);
+	s.syncAsByte(_age);
+	s.syncAsByte(_ageDayCtr);
 
 	s.syncAsUint32LE(_exp);
 	s.syncAsUint16LE(_sp._current);
@@ -259,7 +260,7 @@ void Character::clear() {
 	_intelligence = _might = _personality = _endurance = 0;
 	_speed = _accuracy = _luck = 0;
 	_level = 1;
-	_age = 0;
+	_age = _ageDayCtr = 0;
 	_exp = 0;
 	_sp = 0;
 	_spellLevel = 0;
@@ -315,8 +316,8 @@ Character::TradeResult Character::trade(int whoTo, int itemIndex) {
 Character::LevelIncrease Character::increaseLevel() {
 	++_level;
 	++_age;
-	if (_age._base > 220)
-		_age._base = 220;
+	if (_age > 220)
+		_age = 220;
 	_trapCtr += 2;
 
 	int classNum = _class == NONE ? ROBBER : _class;
@@ -571,15 +572,21 @@ void Character::rest() {
 	if (_hpCurrent == 0)
 		_hpCurrent = 1;
 
-	if (_age._current++ == 255) {
-		_age._base = MIN((int)_age._base + 1, 255);
+	// Increment the day counter. When it overflows,
+	// it's time to increment the character's age by a year
+	if (_ageDayCtr++ > 255) {
+		_ageDayCtr = 0;
+		if (_age < 255)
+			++_age;
 	}
-	if ((g_engine->getRandomNumber(70) + 80) < _age._base) {
+
+	if ((g_engine->getRandomNumber(70) + 80) < _age) {
+		// Older characters have a chance of falling unconscious
 		_condition = UNCONSCIOUS | BAD_CONDITION;
 		return;
 	}
 
-	if (_age._base >= 60) {
+	if (_age >= 60) {
 		// Fun fact: in the original if any of the attributes
 		// reach zero, then it jumps to an instruction that
 		// jumps to itself, freezing the game.
@@ -588,14 +595,14 @@ void Character::rest() {
 			--_speed._current == 0)
 			error("Attributes bottomed out during rest");
 
-		if (_age._base >= 70) {
+		if (_age >= 70) {
 			if (--_might._current == 0 ||
 				--_endurance._current == 0 ||
 				--_speed._current == 0)
 				error("Attributes bottomed out during rest");
 		}
 
-		if (_age._base >= 80) {
+		if (_age >= 80) {
 			if (_might._current <= 2)
 				error("Attributes bottomed out during rest");
 			_might._current -= 2;
@@ -645,7 +652,7 @@ size_t Character::getPerformanceTotal() const {
 		+ _accuracy.getPerformanceTotal()
 		+ _luck.getPerformanceTotal()
 		+ _level.getPerformanceTotal()
-		+ _age.getPerformanceTotal()
+		+ (int)_age + (int)_ageDayCtr
 		+ PERF32(_exp)
 		+ _sp.getPerformanceTotal()
 		+ _spellLevel.getPerformanceTotal()
diff --git a/engines/mm/mm1/data/character.h b/engines/mm/mm1/data/character.h
index 768201a1de1..176542402eb 100644
--- a/engines/mm/mm1/data/character.h
+++ b/engines/mm/mm1/data/character.h
@@ -437,7 +437,8 @@ struct Character : public PrimaryAttributes {
 	Race _race = HUMAN;
 	CharacterClass _class = NONE;
 
-	AttributePair _age;
+	byte _age = 0;
+	int _ageDayCtr = 0;
 	AttributePair16 _sp;
 	AttributePair _spellLevel;
 	AttributePair _ac;
diff --git a/engines/mm/mm1/game/arrested.cpp b/engines/mm/mm1/game/arrested.cpp
index 21756ebdd8f..d30ac82cf81 100644
--- a/engines/mm/mm1/game/arrested.cpp
+++ b/engines/mm/mm1/game/arrested.cpp
@@ -69,8 +69,8 @@ void Arrested::surrender(int numYears) {
 	for (uint i = 0; i < g_globals->_party.size(); ++i) {
 		Character &c = g_globals->_party[i];
 
-		if ((int)c._age._base + numYears < 256)
-			c._age._base += numYears;
+		if ((int)c._age + numYears < 256)
+			c._age += numYears;
 		c._gold /= 2;
 	}
 
diff --git a/engines/mm/mm1/game/equip_remove.cpp b/engines/mm/mm1/game/equip_remove.cpp
index 4907b77f1a8..016bec30385 100644
--- a/engines/mm/mm1/game/equip_remove.cpp
+++ b/engines/mm/mm1/game/equip_remove.cpp
@@ -239,7 +239,7 @@ void EquipRemove::applyEquipBonus(int id, int value){
 		case 29: c._speed._base += value; break;
 		case 31: c._accuracy._base += value; break;
 		case 33: c._luck._base += value; break;
-		case 37: c._age._current += value; break;
+		case 37: c._age += value; break;
 		case 60: c._ac._base += value; break;
 		case 88: c._resistances._s._magic._base += value; break; 
 		case 90: c._resistances._s._fire._base += value; break;
diff --git a/engines/mm/mm1/game/monster_touch.cpp b/engines/mm/mm1/game/monster_touch.cpp
index 9e9088bf7ae..aca4460fa0b 100644
--- a/engines/mm/mm1/game/monster_touch.cpp
+++ b/engines/mm/mm1/game/monster_touch.cpp
@@ -242,11 +242,11 @@ bool MonsterTouch::action15(Common::String &line) {
 	Character &c = *g_globals->_currCharacter;
 
 	if (isCharAffected()) {
-		int age = c._age._base + 10;
-		c._age._base = age;
+		int age = c._age + 10;
+		c._age = age;
 
 		if (age > 255) {
-			c._age._base = 200;
+			c._age = 200;
 			setCondition(ERADICATED);
 		}
 
diff --git a/engines/mm/mm1/game/spells_party.cpp b/engines/mm/mm1/game/spells_party.cpp
index 842444d526c..8164c15b180 100644
--- a/engines/mm/mm1/game/spells_party.cpp
+++ b/engines/mm/mm1/game/spells_party.cpp
@@ -512,12 +512,12 @@ SpellResult SpellsParty::cleric62_raiseDead() {
 
 SpellResult SpellsParty::cleric63_rejuvinate() {
 	if (g_engine->getRandomNumber(100) < 75) {
-		_destChar->_age._base = MIN(_destChar->_age._base - g_engine->getRandomNumber(10),
+		_destChar->_age = MIN(_destChar->_age - g_engine->getRandomNumber(10),
 			200);
 		return SR_FAILED;
 	} else {
 		// Failed, increase the user's age
-		_destChar->_age._base = MIN(_destChar->_age._base + 10, 200);
+		_destChar->_age = MIN(_destChar->_age + 10, 200);
 		return SR_FAILED;
 	}
 }
@@ -602,8 +602,8 @@ SpellResult SpellsParty::cleric74_resurrection() {
 	if (_destChar->_condition == ERADICATED)
 		return SR_FAILED;
 
-	if (_destChar->_age._base < 10 || _destChar->_age._base > 200)
-		_destChar->_age._base = 200;
+	if (_destChar->_age < 10 || _destChar->_age > 200)
+		_destChar->_age = 200;
 
 	if (g_engine->getRandomNumber(100) > 75)
 		return SR_FAILED;
diff --git a/engines/mm/mm1/game/use_item.cpp b/engines/mm/mm1/game/use_item.cpp
index 3f3b3652eba..e1ad80b3d3a 100644
--- a/engines/mm/mm1/game/use_item.cpp
+++ b/engines/mm/mm1/game/use_item.cpp
@@ -129,7 +129,7 @@ void UseItem::applyItemBonus(int id, int value){
 		case 32: c._accuracy._current += value; break;
 		case 34: c._luck._current += value; break;
 		case 36: c._level._current += value; break;
-		case 37: c._age._current += value; break;
+		case 37: c._age += value; break;
 		case 43: c._sp._current += value; break;
 		case 48: c._spellLevel._current += value; break;
 		case 49: c._gems += value; break;
diff --git a/engines/mm/mm1/maps/map30.cpp b/engines/mm/mm1/maps/map30.cpp
index 2c6fbcffe76..b0edcb25408 100644
--- a/engines/mm/mm1/maps/map30.cpp
+++ b/engines/mm/mm1/maps/map30.cpp
@@ -106,8 +106,7 @@ void Map30::special03() {
 
 			for (uint i = 0; i < g_globals->_party.size(); ++i) {
 				Character &c = g_globals->_party[i];
-				c._age._current = c._age._base =
-					MAX((int)c._age._base - 20, 18);
+				c._age = MAX((int)c._age - 20, 18);
 			}
 
 			g_maps->_currentMap->none160();
diff --git a/engines/mm/mm1/views/locations/temple.cpp b/engines/mm/mm1/views/locations/temple.cpp
index f493d9bc216..3fd274bf61d 100644
--- a/engines/mm/mm1/views/locations/temple.cpp
+++ b/engines/mm/mm1/views/locations/temple.cpp
@@ -171,7 +171,7 @@ void Temple::restoreHealth() {
 		c._hpCurrent = c._hp;
 
 		if (_isEradicated) {
-			c._age._current += 10;
+			c._age += 10;
 			--c._endurance;
 		}
 
diff --git a/engines/mm/mm1/views_enh/character_info.cpp b/engines/mm/mm1/views_enh/character_info.cpp
index 1295af1293a..69a638aeed8 100644
--- a/engines/mm/mm1/views_enh/character_info.cpp
+++ b/engines/mm/mm1/views_enh/character_info.cpp
@@ -259,7 +259,7 @@ void CharacterInfo::drawStats() {
 		c._might._current, c._intelligence._current,
 		c._personality._current, c._endurance._current,
 		c._speed._current, c._accuracy._current,
-		c._luck._current, c._age._base, c._level._current,
+		c._luck._current, c._age, c._level._current,
 		c._ac._current, c._hp, c._sp._current, 0,
 		c._exp, c._gold, c._gems
 	};
@@ -267,7 +267,7 @@ void CharacterInfo::drawStats() {
 		c._might._base, c._intelligence._base,
 		c._personality._base, c._endurance._base,
 		c._speed._base, c._accuracy._base,
-		c._luck._base, c._age._base, c._level._base,
+		c._luck._base, c._age, c._level._base,
 		c._ac._current, c._hp, c._sp._base, 0,
 		c._exp, c._gold, c._gems
 	};
@@ -376,14 +376,14 @@ void CharacterInfo::showAttribute(int attrNum) {
 		c._might._current, c._intelligence._current,
 		c._personality._current, c._endurance._current,
 		c._speed._current, c._accuracy._current,
-		c._luck._current, c._age._base, c._level._current,
+		c._luck._current, c._age, c._level._current,
 		c._ac._current, c._hp, c._sp._current
 	};
 	const uint BASE[12] = {
 		c._might._base, c._intelligence._base,
 		c._personality._base, c._endurance._base,
 		c._speed._base, c._accuracy._base,
-		c._luck._base, c._age._base, c._level._base,
+		c._luck._base, c._age, c._level._base,
 		c._ac._current, c._hp, c._sp._base
 	};
 	const char *TITLES[12] = {
diff --git a/engines/mm/mm1/views_enh/locations/temple.cpp b/engines/mm/mm1/views_enh/locations/temple.cpp
index 31bd43f6c08..28ddce5d336 100644
--- a/engines/mm/mm1/views_enh/locations/temple.cpp
+++ b/engines/mm/mm1/views_enh/locations/temple.cpp
@@ -164,7 +164,7 @@ void Temple::restoreHealth() {
 		c._hpCurrent = c._hp;
 
 		if (_isEradicated) {
-			c._age._current += 10;
+			c._age += 10;
 			--c._endurance;
 		}
 




More information about the Scummvm-git-logs mailing list