diff options
author | Strangerke | 2016-07-25 08:43:19 +0200 |
---|---|---|
committer | Bendegúz Nagy | 2016-08-26 23:02:22 +0200 |
commit | 831eca5c42b375870b1d6063a43c7f9cbf7df3ce (patch) | |
tree | f00f41d1569a13b6a8d598d70a796ce1eef53b28 /engines | |
parent | 710464c5d23f9ef51f0a932ef6c61c1594cbb2c7 (diff) | |
download | scummvm-rg350-831eca5c42b375870b1d6063a43c7f9cbf7df3ce.tar.gz scummvm-rg350-831eca5c42b375870b1d6063a43c7f9cbf7df3ce.tar.bz2 scummvm-rg350-831eca5c42b375870b1d6063a43c7f9cbf7df3ce.zip |
DM: Refactor f304_addSkillExperience, change _g313_gameTime to int32
Diffstat (limited to 'engines')
-rw-r--r-- | engines/dm/champion.cpp | 161 | ||||
-rw-r--r-- | engines/dm/dm.cpp | 2 | ||||
-rw-r--r-- | engines/dm/dm.h | 2 | ||||
-rw-r--r-- | engines/dm/group.cpp | 7 | ||||
-rw-r--r-- | engines/dm/loadsave.cpp | 4 |
5 files changed, 84 insertions, 92 deletions
diff --git a/engines/dm/champion.cpp b/engines/dm/champion.cpp index 297605a282..6c3b33142a 100644 --- a/engines/dm/champion.cpp +++ b/engines/dm/champion.cpp @@ -920,104 +920,97 @@ void ChampionMan::f330_disableAction(uint16 champIndex, uint16 ticks) { }
void ChampionMan::f304_addSkillExperience(uint16 champIndex, uint16 skillIndex, uint16 exp) {
-#define AP0638_ui_SkillLevelAfter exp
-#define AP0638_ui_ChampionColor exp
- uint16 L0915_ui_Multiple;
-#define AL0915_ui_MapDifficulty L0915_ui_Multiple
-#define AL0915_ui_SkillLevelBefore L0915_ui_Multiple
-#define AL0915_ui_VitalityAmount L0915_ui_Multiple
-#define AL0915_ui_StaminaAmount L0915_ui_Multiple
- uint16 L0916_ui_BaseSkillIndex;
- Skill* L0918_ps_Skill;
- Champion* L0919_ps_Champion;
- int16 L0920_i_MinorStatisticIncrease;
- int16 L0921_i_MajorStatisticIncrease;
- int16 L0922_i_BaseSkillLevel;
-
-
- warning(false, "Potentially dangerous cast of uint32 below");
- if ((skillIndex >= k4_ChampionSkillSwing) && (skillIndex <= k11_ChampionSkillShoot) && ((uint32)_vm->_projexpl->_g361_lastCreatureAttackTime < (_vm->_g313_gameTime - 150))) {
+ if ((skillIndex >= k4_ChampionSkillSwing) && (skillIndex <= k11_ChampionSkillShoot) && (_vm->_projexpl->_g361_lastCreatureAttackTime < _vm->_g313_gameTime - 150))
exp >>= 1;
- }
+
if (exp) {
- if (AL0915_ui_MapDifficulty = _vm->_dungeonMan->_g269_currMap->_difficulty) {
- exp *= AL0915_ui_MapDifficulty;
- }
- L0919_ps_Champion = &_gK71_champions[champIndex];
- if (skillIndex >= k4_ChampionSkillSwing) {
- L0916_ui_BaseSkillIndex = (skillIndex - k4_ChampionSkillSwing) >> 2;
- } else {
- L0916_ui_BaseSkillIndex = skillIndex;
- }
- AL0915_ui_SkillLevelBefore = f303_getSkillLevel(champIndex, L0916_ui_BaseSkillIndex | (k0x4000_IgnoreObjectModifiers | k0x8000_IgnoreTemporaryExperience));
- warning(false, "potentially dangerous cast of uint32 below");
- if ((skillIndex >= k4_ChampionSkillSwing) && ((uint32)_vm->_projexpl->_g361_lastCreatureAttackTime > (_vm->_g313_gameTime - 25))) {
+ if (_vm->_dungeonMan->_g269_currMap->_difficulty)
+ exp *= _vm->_dungeonMan->_g269_currMap->_difficulty;
+
+ Champion *curChampion = &_gK71_champions[champIndex];
+ uint16 baseSkillIndex;
+ if (skillIndex >= k4_ChampionSkillSwing)
+ baseSkillIndex = (skillIndex - k4_ChampionSkillSwing) >> 2;
+ else
+ baseSkillIndex = skillIndex;
+
+ uint16 skillLevelBefore = f303_getSkillLevel(champIndex, baseSkillIndex | (k0x4000_IgnoreObjectModifiers | k0x8000_IgnoreTemporaryExperience));
+
+ if ((skillIndex >= k4_ChampionSkillSwing) && (_vm->_projexpl->_g361_lastCreatureAttackTime > _vm->_g313_gameTime - 25))
exp <<= 1;
- }
- L0918_ps_Skill = &L0919_ps_Champion->_skills[skillIndex];
- L0918_ps_Skill->_experience += exp;
- if (L0918_ps_Skill->_temporaryExperience < 32000) {
- L0918_ps_Skill->_temporaryExperience += f26_getBoundedValue(1, exp >> 3, 100);
- }
- L0918_ps_Skill = &L0919_ps_Champion->_skills[L0916_ui_BaseSkillIndex];
- if (skillIndex >= k4_ChampionSkillSwing) {
- L0918_ps_Skill->_experience += exp;
- }
- AP0638_ui_SkillLevelAfter = f303_getSkillLevel(champIndex, L0916_ui_BaseSkillIndex | (k0x4000_IgnoreObjectModifiers | k0x8000_IgnoreTemporaryExperience));
- if (AP0638_ui_SkillLevelAfter > AL0915_ui_SkillLevelBefore) {
- L0922_i_BaseSkillLevel = AP0638_ui_SkillLevelAfter;
- L0920_i_MinorStatisticIncrease = _vm->getRandomNumber(2);
- L0921_i_MajorStatisticIncrease = 1 + _vm->getRandomNumber(2);
- AL0915_ui_VitalityAmount = _vm->getRandomNumber(2); /* For Priest skill, the amount is 0 or 1 for all skill levels */
- if (L0916_ui_BaseSkillIndex != k2_ChampionSkillPriest) {
- AL0915_ui_VitalityAmount &= AP0638_ui_SkillLevelAfter; /* For non Priest skills the amount is 0 for even skill levels. The amount is 0 or 1 for odd skill levels */
+
+ Skill *curSkill = &curChampion->_skills[skillIndex];
+ curSkill->_experience += exp;
+ if (curSkill->_temporaryExperience < 32000)
+ curSkill->_temporaryExperience += f26_getBoundedValue(1, exp >> 3, 100);
+
+ curSkill = &curChampion->_skills[baseSkillIndex];
+ if (skillIndex >= k4_ChampionSkillSwing)
+ curSkill->_experience += exp;
+
+ uint16 skillLevelAfter = f303_getSkillLevel(champIndex, baseSkillIndex | (k0x4000_IgnoreObjectModifiers | k0x8000_IgnoreTemporaryExperience));
+ if (skillLevelAfter > skillLevelBefore) {
+ int16 newBaseSkillLevel = skillLevelAfter;
+ int16 minorStatIncrease = _vm->getRandomNumber(2);
+ int16 majorStatIncrease = 1 + _vm->getRandomNumber(2);
+ uint16 vitalityAmount = _vm->getRandomNumber(2); /* For Priest skill, the amount is 0 or 1 for all skill levels */
+ if (baseSkillIndex != k2_ChampionSkillPriest) {
+ vitalityAmount &= skillLevelAfter; /* For non Priest skills the amount is 0 for even skill levels. The amount is 0 or 1 for odd skill levels */
}
- L0919_ps_Champion->_statistics[k4_ChampionStatVitality][k0_ChampionStatMaximum] += AL0915_ui_VitalityAmount;
- AL0915_ui_StaminaAmount = L0919_ps_Champion->_maxStamina;
- L0919_ps_Champion->_statistics[k6_ChampionStatAntifire][k0_ChampionStatMaximum] += _vm->getRandomNumber(2) & ~AP0638_ui_SkillLevelAfter; /* The amount is 0 for odd skill levels. The amount is 0 or 1 for even skill levels */
- switch (L0916_ui_BaseSkillIndex) {
+ curChampion->_statistics[k4_ChampionStatVitality][k0_ChampionStatMaximum] += vitalityAmount;
+ uint16 staminaAmount = curChampion->_maxStamina;
+ curChampion->_statistics[k6_ChampionStatAntifire][k0_ChampionStatMaximum] += _vm->getRandomNumber(2) & ~skillLevelAfter; /* The amount is 0 for odd skill levels. The amount is 0 or 1 for even skill levels */
+ bool increaseManaFl = false;
+ switch (baseSkillIndex) {
case k0_ChampionSkillFighter:
- AL0915_ui_StaminaAmount >>= 4;
- AP0638_ui_SkillLevelAfter *= 3;
- L0919_ps_Champion->_statistics[k1_ChampionStatStrength][k0_ChampionStatMaximum] += L0921_i_MajorStatisticIncrease;
- L0919_ps_Champion->_statistics[k2_ChampionStatDexterity][k0_ChampionStatMaximum] += L0920_i_MinorStatisticIncrease;
+ staminaAmount >>= 4;
+ skillLevelAfter *= 3;
+ curChampion->_statistics[k1_ChampionStatStrength][k0_ChampionStatMaximum] += majorStatIncrease;
+ curChampion->_statistics[k2_ChampionStatDexterity][k0_ChampionStatMaximum] += minorStatIncrease;
break;
case k1_ChampionSkillNinja:
- AL0915_ui_StaminaAmount /= 21;
- AP0638_ui_SkillLevelAfter <<= 1;
- L0919_ps_Champion->_statistics[k1_ChampionStatStrength][k0_ChampionStatMaximum] += L0920_i_MinorStatisticIncrease;
- L0919_ps_Champion->_statistics[k2_ChampionStatDexterity][k0_ChampionStatMaximum] += L0921_i_MajorStatisticIncrease;
+ staminaAmount /= 21;
+ skillLevelAfter <<= 1;
+ curChampion->_statistics[k1_ChampionStatStrength][k0_ChampionStatMaximum] += minorStatIncrease;
+ curChampion->_statistics[k2_ChampionStatDexterity][k0_ChampionStatMaximum] += majorStatIncrease;
break;
case k3_ChampionSkillWizard:
- AL0915_ui_StaminaAmount >>= 5;
- L0919_ps_Champion->_maxMana += AP0638_ui_SkillLevelAfter + (AP0638_ui_SkillLevelAfter >> 1);
- L0919_ps_Champion->_statistics[k3_ChampionStatWisdom][k0_ChampionStatMaximum] += L0921_i_MajorStatisticIncrease;
- goto T0304016;
+ staminaAmount >>= 5;
+ curChampion->_maxMana += skillLevelAfter + (skillLevelAfter >> 1);
+ curChampion->_statistics[k3_ChampionStatWisdom][k0_ChampionStatMaximum] += majorStatIncrease;
+ increaseManaFl = true;
+ break;
case k2_ChampionSkillPriest:
- AL0915_ui_StaminaAmount /= 25;
- L0919_ps_Champion->_maxMana += AP0638_ui_SkillLevelAfter;
- AP0638_ui_SkillLevelAfter += (AP0638_ui_SkillLevelAfter + 1) >> 1;
- L0919_ps_Champion->_statistics[k3_ChampionStatWisdom][k0_ChampionStatMaximum] += L0920_i_MinorStatisticIncrease;
-T0304016:
- if ((L0919_ps_Champion->_maxMana += MIN(_vm->getRandomNumber(4), (uint16)(L0922_i_BaseSkillLevel - 1))) > 900) {
- L0919_ps_Champion->_maxMana = 900;
- }
- L0919_ps_Champion->_statistics[k5_ChampionStatAntimagic][k0_ChampionStatMaximum] += _vm->getRandomNumber(3);
- }
- if ((L0919_ps_Champion->_maxHealth += AP0638_ui_SkillLevelAfter + _vm->getRandomNumber((AP0638_ui_SkillLevelAfter >> 1) + 1)) > 999) {
- L0919_ps_Champion->_maxHealth = 999;
+ staminaAmount /= 25;
+ curChampion->_maxMana += skillLevelAfter;
+ skillLevelAfter += (skillLevelAfter + 1) >> 1;
+ curChampion->_statistics[k3_ChampionStatWisdom][k0_ChampionStatMaximum] += minorStatIncrease;
+ increaseManaFl = true;
+ break;
+ default:
+ break;
}
- if ((L0919_ps_Champion->_maxStamina += AL0915_ui_StaminaAmount + _vm->getRandomNumber((AL0915_ui_StaminaAmount >> 1) + 1)) > 9999) {
- L0919_ps_Champion->_maxStamina = 9999;
+ if (increaseManaFl) {
+ if ((curChampion->_maxMana += MIN(_vm->getRandomNumber(4), (uint16)(newBaseSkillLevel - 1))) > 900)
+ curChampion->_maxMana = 900;
+ curChampion->_statistics[k5_ChampionStatAntimagic][k0_ChampionStatMaximum] += _vm->getRandomNumber(3);
}
- setFlag(L0919_ps_Champion->_attributes, k0x0100_ChampionAttributeStatistics);
+
+ if ((curChampion->_maxHealth += skillLevelAfter + _vm->getRandomNumber((skillLevelAfter >> 1) + 1)) > 999)
+ curChampion->_maxHealth = 999;
+
+ if ((curChampion->_maxStamina += staminaAmount + _vm->getRandomNumber((staminaAmount >> 1) + 1)) > 9999)
+ curChampion->_maxStamina = 9999;
+
+ setFlag(curChampion->_attributes, k0x0100_ChampionAttributeStatistics);
f292_drawChampionState((ChampionIndex)champIndex);
_vm->_textMan->f51_messageAreaPrintLineFeed();
- _vm->_textMan->f47_messageAreaPrintMessage((Color)(AP0638_ui_ChampionColor = g46_ChampionColor[champIndex]), L0919_ps_Champion->_name);
+ Color curChampionColor = g46_ChampionColor[champIndex];
+ _vm->_textMan->f47_messageAreaPrintMessage(curChampionColor, curChampion->_name);
// TODO: localization
- _vm->_textMan->f47_messageAreaPrintMessage((Color)AP0638_ui_ChampionColor, " JUST GAINED A ");
- _vm->_textMan->f47_messageAreaPrintMessage((Color)AP0638_ui_ChampionColor, g417_baseSkillName[L0916_ui_BaseSkillIndex]);
- _vm->_textMan->f47_messageAreaPrintMessage((Color)AP0638_ui_ChampionColor, " LEVEL!");
+ _vm->_textMan->f47_messageAreaPrintMessage(curChampionColor, " JUST GAINED A ");
+ _vm->_textMan->f47_messageAreaPrintMessage(curChampionColor, g417_baseSkillName[baseSkillIndex]);
+ _vm->_textMan->f47_messageAreaPrintMessage(curChampionColor, " LEVEL!");
}
}
}
@@ -1689,7 +1682,7 @@ void ChampionMan::f331_applyTimeEffects() { }
}
}
- if (!_vm->_championMan->_g300_partyIsSleeping && (L1010_ps_Champion->_dir != _vm->_dungeonMan->_g308_partyDir) && (_vm->_projexpl->_g361_lastCreatureAttackTime + 60 < (int32)_vm->_g313_gameTime)) {
+ if (!_vm->_championMan->_g300_partyIsSleeping && (L1010_ps_Champion->_dir != _vm->_dungeonMan->_g308_partyDir) && (_vm->_projexpl->_g361_lastCreatureAttackTime + 60 < _vm->_g313_gameTime)) {
L1010_ps_Champion->_dir = _vm->_dungeonMan->_g308_partyDir;
L1010_ps_Champion->_maximumDamageReceived = 0;
setFlag(L1010_ps_Champion->_attributes, k0x0400_ChampionAttributeIcon);
diff --git a/engines/dm/dm.cpp b/engines/dm/dm.cpp index 92cb402a3a..55a2b6e055 100644 --- a/engines/dm/dm.cpp +++ b/engines/dm/dm.cpp @@ -380,7 +380,7 @@ T0002002: _menuMan->f390_refreshActionAreaAndSetChampDirMaxDamageReceived(); - if (!((int32)_g313_gameTime & (_championMan->_g300_partyIsSleeping ? 15 : 63))) { + if (!(_g313_gameTime & (_championMan->_g300_partyIsSleeping ? 15 : 63))) { _championMan->f331_applyTimeEffects(); } diff --git a/engines/dm/dm.h b/engines/dm/dm.h index 128dfaf8e4..1b1f8a7af2 100644 --- a/engines/dm/dm.h +++ b/engines/dm/dm.h @@ -266,7 +266,7 @@ public: int8 _dirIntoStepCountEast[4]; // @ G0233_ai_Graphic559_DirectionToStepEastCount int8 _dirIntoStepCountNorth[4]; // @ G0234_ai_Graphic559_DirectionToStepNorthCount - uint32 _g313_gameTime; // @ G0313_ul_GameTime + int32 _g313_gameTime; // @ G0313_ul_GameTime char _g353_stringBuildBuffer[128]; // @ G0353_ac_StringBuildBuffer int16 _g318_waitForInputMaxVerticalBlankCount; // @ G0318_i_WaitForInputMaximumVerticalBlankCount }; diff --git a/engines/dm/group.cpp b/engines/dm/group.cpp index 2bb694816e..235bfe40b6 100644 --- a/engines/dm/group.cpp +++ b/engines/dm/group.cpp @@ -1316,12 +1316,11 @@ int32 GroupMan::f179_getCreatureAspectUpdateTime(ActiveGroup *activeGroup, int16 void GroupMan::f205_setDirection(ActiveGroup *activeGroup, int16 dir, int16 creatureIndex, bool twoHalfSquareSizedCreatures) { uint16 L0435_ui_GroupDirections; - static long G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime; /* These two variables are used to prevent setting direction of half square sized creatures twice at the same game time */ + static int32 G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime; /* These two variables are used to prevent setting direction of half square sized creatures twice at the same game time */ static ActiveGroup *G0396_ps_TwoHalfSquareSizedCreaturesGroupLastDirectionSetActiveGroup; - - warning(false, "potentially dangerous cast to uint32 below"); - if (twoHalfSquareSizedCreatures && (_vm->_g313_gameTime == (uint32)G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime) && (activeGroup == G0396_ps_TwoHalfSquareSizedCreaturesGroupLastDirectionSetActiveGroup)) { + warning(false, "TODO: Move G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime to GroupMan so it's properly initialized"); + if (twoHalfSquareSizedCreatures && (_vm->_g313_gameTime == G0395_l_TwoHalfSquareSizedCreaturesGroupLastDirectionSetTime) && (activeGroup == G0396_ps_TwoHalfSquareSizedCreaturesGroupLastDirectionSetActiveGroup)) { return; } if (M21_normalizeModulo4(_vm->_groupMan->M50_getCreatureValue(L0435_ui_GroupDirections = activeGroup->_directions, creatureIndex) - dir) == 2) { /* If current and new direction are opposites then change direction only one step at a time */ diff --git a/engines/dm/loadsave.cpp b/engines/dm/loadsave.cpp index 9b50351376..19df8bf80f 100644 --- a/engines/dm/loadsave.cpp +++ b/engines/dm/loadsave.cpp @@ -76,7 +76,7 @@ T0435002: warning(false, "MISSING CODE: missing check for matching format and platform in save in f435_loadgame"); - _g313_gameTime = file->readUint32BE(); + _g313_gameTime = file->readSint32BE(); // G0349_ul_LastRandomNumber = L1371_s_GlobalData.LastRandomNumber; _championMan->_g305_partyChampionCount = file->readUint16BE(); _dungeonMan->_g306_partyMapX = file->readSint16BE(); @@ -165,7 +165,7 @@ void DMEngine::f433_processCommand140_saveGame(uint16 slot, const Common::String writeSaveGameHeader(file, desc); // write C0_SAVE_PART_GLOBAL_DATA part - file->writeUint32BE(_g313_gameTime); + file->writeSint32BE(_g313_gameTime); //L1348_s_GlobalData.LastRandomNumber = G0349_ul_LastRandomNumber; file->writeUint16BE(_championMan->_g305_partyChampionCount); file->writeSint16BE(_dungeonMan->_g306_partyMapX); |