changeset 1361:b3ac17fd12de

Moved condition checking to a separate class, extracted it from player::SetCondition
author Grumpy7
date Sun, 14 Jul 2013 23:22:43 +0200
parents a47d9282ea7c
children d6cf8ead9242
files CastSpellInfo.cpp Conditions.cpp Conditions.h Party.cpp Player.cpp Player.h Spells.cpp UI/UIRest.cpp mm7_4.cpp mm7_5.cpp
diffstat 10 files changed, 364 insertions(+), 187 deletions(-) [+]
line wrap: on
line diff
--- a/CastSpellInfo.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/CastSpellInfo.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -2503,7 +2503,7 @@
 						v726->sHealth = v726->GetMaxHealth();
 					if ( v726->sHealth > 0 )
 					{
-						v726->pConditions[Player::Condition_Unconcious] = 0;
+						v726->SetUnconcious(0);
 					}
 					v388 = _v733;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Conditions.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -0,0 +1,63 @@
+#pragma once
+#include "Conditions.h"
+#include "Party.h"
+std::array<ConditionProcessor, 18> conditionArray =
+{
+  // hint: condname, protfrommagic, gmprot, enchantment, ...
+  ConditionProcessor(Condition_Cursed,    false, false,  0),
+  ConditionProcessor(Condition_Weak,       true, false,  0),
+  ConditionProcessor(Condition_Sleep,     false, false, 22, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR),
+  ConditionProcessor(Condition_Fear,      false, false,  0),
+  ConditionProcessor(Condition_Drunk,     false, false,  0),
+  ConditionProcessor(Condition_Insane,    false, false, 19, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
+  ConditionProcessor(Condition_Poison1,    true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
+  ConditionProcessor(Condition_Disease1,   true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
+  ConditionProcessor(Condition_Poison2,    true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
+  ConditionProcessor(Condition_Disease2,   true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
+  ConditionProcessor(Condition_Poison3,    true, false, 21, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
+  ConditionProcessor(Condition_Disease3,   true, false, 18, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK),
+  ConditionProcessor(Condition_Paralyzed, false, false, 20, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK, ITEM_ARTIFACT_GHOULSBANE, EQIUP_ANY),
+  ConditionProcessor(Condition_Unconcious,false, false,  0),
+  ConditionProcessor(Condition_Dead,       true,  true,  0),
+  ConditionProcessor(Condition_Pertified,  true, false, 23, ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR, ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK, ITEM_RELIC_KELEBRIM, EQIUP_ANY),
+  ConditionProcessor(Condition_Eradicated, true,  true,  0),
+  ConditionProcessor(Condition_Zombie,    false, false,  0)
+};
+
+bool ConditionProcessor::IsPlayerAffected( Player* inPlayer, int condToCheck, int blockable)
+{
+  if ( !blockable )
+  {
+    return true;
+  }
+  ConditionProcessor* thisProc = &conditionArray[condToCheck];
+  if (thisProc->m_IsBlockedByProtFromMagic && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0)
+  {
+    if (!(thisProc->m_DoesNeedGmProtFromMagic && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uSkill < 4))
+    {
+      --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
+      if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
+        pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
+      return false;
+    }
+  }
+  if (thisProc->m_WorkingEnchantment != 0)
+  {
+    if (inPlayer->HasEnchantedItemEquipped(thisProc->m_WorkingEnchantment))
+      return false;
+  }
+  for (unsigned int i = 0; i < thisProc->m_equipmentPairs.size() / 2; i++)
+  {
+    if (thisProc->m_equipmentPairs[i * 2].m_ItemId == (ITEM_TYPE)0)
+    {
+      return true;
+    }
+    ITEM_TYPE itemId = thisProc->m_equipmentPairs[i * 2].m_ItemId;
+    ITEM_EQUIP_TYPE slot = thisProc->m_equipmentPairs[i * 2 + 1].m_EquipSlot;
+    if (inPlayer->WearsItem(itemId, slot))
+    {
+      return false;
+    }
+  }
+  return true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Conditions.h	Sun Jul 14 23:22:43 2013 +0200
@@ -0,0 +1,73 @@
+#pragma once
+#include "Items.h"
+#include <array>
+enum Condition: unsigned __int32
+{
+  Condition_Cursed = 0,
+  Condition_Weak = 1,
+  Condition_Sleep = 2,
+  Condition_Fear = 3,
+  Condition_Drunk = 4,
+  Condition_Insane = 5,
+  Condition_Poison1 = 6,
+  Condition_Disease1 = 7,
+  Condition_Poison2 = 8,
+  Condition_Disease2 = 9,
+  Condition_Poison3 = 10,
+  Condition_Disease3 = 11,
+  Condition_Paralyzed = 12,
+  Condition_Unconcious = 13,
+  Condition_Dead = 14,
+  Condition_Pertified = 15,
+  Condition_Eradicated = 16,
+  Condition_Zombie = 17,
+  Condition_Good = 18
+};
+
+
+class EquipemntPair
+{
+public:
+  ITEM_TYPE m_ItemId;
+  ITEM_EQUIP_TYPE  m_EquipSlot;
+  EquipemntPair(ITEM_TYPE type, ITEM_EQUIP_TYPE slot)
+  {
+    m_ItemId = type;
+    m_EquipSlot = slot;
+  }
+  EquipemntPair()
+  {
+    m_ItemId = (ITEM_TYPE)0;
+    m_EquipSlot = (ITEM_EQUIP_TYPE)0;
+  }
+};
+
+struct Player;
+
+class ConditionProcessor
+{
+public:
+  bool m_IsBlockedByProtFromMagic;
+  bool m_DoesNeedGmProtFromMagic;
+  int m_WorkingEnchantment;
+  std::array<EquipemntPair, 3> m_equipmentPairs;
+  ConditionProcessor(int, bool isblocked, bool needsGm, int enchantment, 
+    ITEM_TYPE itemtype1 = (ITEM_TYPE)0, ITEM_EQUIP_TYPE itemslot1 = (ITEM_EQUIP_TYPE)0, 
+    ITEM_TYPE itemtype2 = (ITEM_TYPE)0, ITEM_EQUIP_TYPE itemslot2 = (ITEM_EQUIP_TYPE)0, 
+    ITEM_TYPE itemtype3 = (ITEM_TYPE)0, ITEM_EQUIP_TYPE itemslot3 = (ITEM_EQUIP_TYPE)0)
+  {
+    m_IsBlockedByProtFromMagic = isblocked;
+    m_DoesNeedGmProtFromMagic = needsGm;
+    m_WorkingEnchantment = enchantment;
+    m_equipmentPairs[0].m_ItemId = itemtype1;
+    m_equipmentPairs[0].m_EquipSlot = itemslot1;
+    m_equipmentPairs[1].m_ItemId = itemtype2;
+    m_equipmentPairs[1].m_EquipSlot = itemslot2;
+    m_equipmentPairs[2].m_ItemId = itemtype3;
+    m_equipmentPairs[2].m_EquipSlot = itemslot3;
+  }
+
+  static bool IsPlayerAffected(Player*, int, int);
+};
+
+extern std::array<ConditionProcessor, 18> conditionArray;
\ No newline at end of file
--- a/Party.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/Party.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -26,6 +26,7 @@
 #include "Sprites.h"
 #include "SpriteObject.h"
 #include "ObjectList.h"
+#include "Conditions.h"
 
 Party *pParty; // idb
 
@@ -949,7 +950,7 @@
 
 
     auto condition = player->GetMajorConditionIdx();
-    if (condition == Player::Condition_Good || condition == Player::Condition_Zombie)
+    if (condition == Condition_Good || condition == Condition_Zombie)
     {
       if (player->uExpressionTimePassed < player->uExpressionTimeLength)
         continue;
@@ -999,23 +1000,23 @@
 
       switch (condition)
       {
-        case Player::Condition_Dead:        player->expression = CHARACTER_EXPRESSION_DEAD;      break;
-        case Player::Condition_Pertified:   player->expression = CHARACTER_EXPRESSION_PERTIFIED; break;
-        case Player::Condition_Eradicated:  player->expression = CHARACTER_EXPRESSION_ERADICATED; break;
-        case Player::Condition_Cursed:      player->expression = CHARACTER_EXPRESSION_CURSED; break;
-        case Player::Condition_Weak:        player->expression = CHARACTER_EXPRESSION_WEAK; break;
-        case Player::Condition_Sleep:       player->expression = CHARACTER_EXPRESSION_SLEEP; break;
-        case Player::Condition_Fear:        player->expression = CHARACTER_EXPRESSION_FEAR; break;
-        case Player::Condition_Drunk:       player->expression = CHARACTER_EXPRESSION_DRUNK; break;
-        case Player::Condition_Insane:      player->expression = CHARACTER_EXPRESSION_INSANE; break;
-        case Player::Condition_Poison1:
-        case Player::Condition_Poison2:
-        case Player::Condition_Poison3:     player->expression = CHARACTER_EXPRESSION_POISONED; break;
-        case Player::Condition_Disease1:
-        case Player::Condition_Disease2:
-        case Player::Condition_Disease3:    player->expression = CHARACTER_EXPRESSION_DISEASED; break;
-        case Player::Condition_Paralyzed:   player->expression = CHARACTER_EXPRESSION_PARALYZED; break;
-        case Player::Condition_Unconcious:  player->expression = CHARACTER_EXPRESSION_UNCONCIOUS; break;
+        case Condition_Dead:        player->expression = CHARACTER_EXPRESSION_DEAD;      break;
+        case Condition_Pertified:   player->expression = CHARACTER_EXPRESSION_PERTIFIED; break;
+        case Condition_Eradicated:  player->expression = CHARACTER_EXPRESSION_ERADICATED; break;
+        case Condition_Cursed:      player->expression = CHARACTER_EXPRESSION_CURSED; break;
+        case Condition_Weak:        player->expression = CHARACTER_EXPRESSION_WEAK; break;
+        case Condition_Sleep:       player->expression = CHARACTER_EXPRESSION_SLEEP; break;
+        case Condition_Fear:        player->expression = CHARACTER_EXPRESSION_FEAR; break;
+        case Condition_Drunk:       player->expression = CHARACTER_EXPRESSION_DRUNK; break;
+        case Condition_Insane:      player->expression = CHARACTER_EXPRESSION_INSANE; break;
+        case Condition_Poison1:
+        case Condition_Poison2:
+        case Condition_Poison3:     player->expression = CHARACTER_EXPRESSION_POISONED; break;
+        case Condition_Disease1:
+        case Condition_Disease2:
+        case Condition_Disease3:    player->expression = CHARACTER_EXPRESSION_DISEASED; break;
+        case Condition_Paralyzed:   player->expression = CHARACTER_EXPRESSION_PARALYZED; break;
+        case Condition_Unconcious:  player->expression = CHARACTER_EXPRESSION_UNCONCIOUS; break;
         default:
           assert(false);
       }
--- a/Player.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/Player.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -698,18 +698,16 @@
   }
 }
 
-
 //----- (00492D65) --------------------------------------------------------
-int Player::SetCondition(unsigned int uConditionIdx, int a3)
+void Player::SetCondition( unsigned int uConditionIdx, int a3 )
 {
   signed int player_sex; // ecx@77
-  char zombi_face; // al@80
   signed int remainig_player; // ebx@82
   int players_before; // [sp+10h] [bp-4h]@2
   int players_after; // [sp+20h] [bp+Ch]@82
 
   if ( pConditions[uConditionIdx] )
-      return 0;
+      return;
 
   players_before = 0;
 
@@ -718,128 +716,43 @@
       if ( pPlayers[i]->CanAct() )
           ++players_before;
   }
+  
+  if (!ConditionProcessor::IsPlayerAffected(this, uConditionIdx, a3))
+  {
+    return;
+  }
 
   switch ( uConditionIdx )
   {
-    case Condition_Cursed:
-      PlaySound((PlayerSpeech)30, 0);
-    break;
-    case Condition_Weak:
-      if ( a3 == 1 && (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0 )
-      {
-        --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
-          pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
-        return 0;
-      }
-      PlaySound((PlayerSpeech)25, 0);
-    break;
-    case Condition_Sleep:
-      if ( a3 == 1 && (HasEnchantedItemEquipped(22) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR))) 
-        return 0;
-    break;
-
-    case Condition_Fear:
-      PlaySound((PlayerSpeech)26, 0);
-    break;
-    case Condition_Drunk:
-      PlaySound((PlayerSpeech)31, 0);
-    break;
-    case Condition_Insane:
-      if ( a3 == 1 && (HasEnchantedItemEquipped(19) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK)) )
-        return 0;
-      PlaySound((PlayerSpeech)29, 0);
-    break;
+    case Condition_Cursed: PlaySound(SPEECH_30, 0); break;
+    case Condition_Weak: PlaySound(SPEECH_25, 0); break;
+    case Condition_Sleep: break; //nosound
+    case Condition_Fear: PlaySound(SPEECH_26, 0); break;
+    case Condition_Drunk: PlaySound(SPEECH_31, 0); break;
+    case Condition_Insane: PlaySound(SPEECH_29, 0); break;
     case Condition_Poison1:
     case Condition_Poison2:
-    case Condition_Poison3:
-      if ( a3 == 1 )
-      {
-        if ( (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
-          if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
-            pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
-          return 0;
-        }
-        if ( HasEnchantedItemEquipped(21) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK) )
-            return 0;
-      }
-      PlaySound((PlayerSpeech)27, 0);
-    break;
+    case Condition_Poison3: PlaySound(SPEECH_27, 0); break;
     case Condition_Disease1:
     case Condition_Disease2:
-    case Condition_Disease3:
-      if ( a3 == 1 )
-      {            
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
-          if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
-            pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
-          return 0;
-        }
-        if ( HasEnchantedItemEquipped(18) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK) )
-          return 0;
-      }
-      PlaySound((PlayerSpeech)28, 0);
-    break;
-    case Condition_Paralyzed:
-      if ( a3 == 1 )
-      {
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
-          if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
-            pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
-          return 0;
-        }
-        if ( HasEnchantedItemEquipped(20) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_GHOULSBANE, EQIUP_ANY) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK))
-          return 0;
-      }
-    break;
+    case Condition_Disease3: PlaySound(SPEECH_28, 0);break;
+    case Condition_Paralyzed: break;  //nosound
     case Condition_Unconcious:
       PlaySound(SPEECH_32, 0);
       if ( sHealth > 0 )
         sHealth = 0;
     break;
     case Condition_Dead:
-      if ( a3 == 1 && (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 && pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uSkill >= 4u )
-      {
-        --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
-          pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
-        return 0;
-      }
-      PlaySound((PlayerSpeech)33, 0);
+      PlaySound(SPEECH_33, 0);
       if ( sHealth > 0 )
         sHealth = 0;
       if ( sMana > 0 )
         sMana = 0;
     break;
     case Condition_Pertified:
-      if ( a3 == 1 )
-      {            
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0i64 )
-        {
-          --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
-          if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
-            pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
-          return 0;
-        }
-        if ( HasEnchantedItemEquipped(23) || WearsItem(ITEM_RELIC_KELEBRIM, EQIUP_ANY) || WearsItem(ITEM_ARTIFACT_YORUBA, EQUIP_ARMOUR) || WearsItem(ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP, EQUIP_CLOAK) )
-          return 0;
-      }
       PlaySound((PlayerSpeech)34, 0);
     break;
     case Condition_Eradicated:
-      if ( a3 == 1 && ((signed __int64)pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uExpireTime > 0 ) &&( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uSkill >= 4u ))
-      {
-        --pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower;
-        if ( pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].uPower < 1u )
-          pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Reset();
-        return 0;
-      }
       PlaySound(SPEECH_35, 0);
       if (sHealth > 0 )
         sHealth = 0;
@@ -848,7 +761,7 @@
     break;
     case Condition_Zombie:
       if ( classType == PLAYER_CLASS_LICH || Eradicated() || Zombie() || !Dead())
-        return 0;
+        return;
       memset(&pConditions[0], 0, sizeof(pConditions));
       sHealth = GetMaxHealth();
       sMana = 0;
@@ -865,12 +778,12 @@
         uCurrentFace = 24;
         uVoiceID = 24;
       }
-      PlaySound((PlayerSpeech)SPEECH_99, 0);
+      PlaySound(SPEECH_99, 0);
     break;
   }
 
   remainig_player = 0;
-  pConditions[uConditionIdx] = pParty->uTimePlayed;
+  pConditions[uConditionIdx] = 1;
   players_after = 0;
   for (int i = 1; i < 5; ++i)
   {
@@ -884,7 +797,7 @@
   {
     pPlayers[remainig_player]->PlaySound(SPEECH_107, 0);
   }
-  return 1;
+  return;
 }
 
 //----- (00492528) --------------------------------------------------------
@@ -9060,6 +8973,8 @@
     }
   }
 }
+
+
 //----- (0049387A) --------------------------------------------------------
 int CycleCharacter(unsigned int _this)
 {
@@ -9862,4 +9777,145 @@
       }
     }
   }
+}
+
+
+bool Player::Weak()
+{
+  return pConditions[Condition_Weak] != 0;
+}
+
+bool Player::Dead()
+{
+  return pConditions[Condition_Dead] != 0;
+}
+
+bool Player::Eradicated()
+{
+  return pConditions[Condition_Eradicated] != 0;
+}
+
+bool Player::Zombie()
+{
+  return pConditions[Condition_Zombie] != 0;
+}
+
+bool Player::Cursed()
+{
+  return pConditions[Condition_Cursed] != 0;
+}
+
+bool Player::Pertified()
+{
+  return pConditions[Condition_Pertified] != 0;
+}
+
+bool Player::Unconcious()
+{
+  return pConditions[Condition_Unconcious] != 0;
+}
+
+void Player::SetCursed( bool state )
+{
+  pConditions[Condition_Cursed] = state;
+}
+
+void Player::SetWeak( bool state )
+{
+  pConditions[Condition_Weak] = state;
+}
+
+void Player::SetAsleep( bool state )
+{
+  pConditions[Condition_Sleep] = state;
+}
+
+void Player::SetAfraid( bool state )
+{
+  pConditions[Condition_Fear] = state;
+}
+
+void Player::SetDrunk( bool state )
+{
+  pConditions[Condition_Drunk] = state;
+}
+
+void Player::SetInsane( bool state )
+{
+  pConditions[Condition_Insane] = state;
+}
+
+void Player::SetPoison1( bool state )
+{
+  pConditions[Condition_Poison1] = state;
+}
+
+void Player::SetDisease1( bool state )
+{
+  pConditions[Condition_Disease1] = state;
+}
+
+void Player::SetPoison2( bool state )
+{
+  pConditions[Condition_Poison2] = state;
+}
+
+void Player::SetDisease2( bool state )
+{
+  pConditions[Condition_Disease2] = state;
+}
+
+void Player::SetPoison3( bool state )
+{
+  pConditions[Condition_Poison3] = state;
+}
+
+void Player::SetDisease3( bool state )
+{
+  pConditions[Condition_Disease3] = state;
+}
+
+void Player::SetParalyzed( bool state )
+{
+  pConditions[Condition_Paralyzed] = state;
+}
+
+void Player::SetUnconcious( bool state )
+{
+  pConditions[Condition_Unconcious] = state;
+}
+
+void Player::SetDead( bool state )
+{
+  pConditions[Condition_Dead] = state;
+}
+
+void Player::SetPertified( bool state )
+{
+  pConditions[Condition_Pertified] = state;
+}
+
+void Player::SetEradicated( bool state )
+{
+  pConditions[Condition_Eradicated] = state;
+}
+
+void Player::SetZombie( bool state )
+{
+  pConditions[Condition_Zombie] = state;
+}
+
+void Player::SetCondWeakWithBlockCheck( int blockable )
+{
+  SetCondition(Condition_Weak, blockable);
+}
+
+void Player::SetCondInsaneWithBlockCheck( int blockable )
+{
+  SetCondition(Condition_Insane, blockable);
+}
+
+void Player::SetCondDeadWithBlockCheck( int blockable )
+{
+  SetCondition(Condition_Dead, blockable);
 }
\ No newline at end of file
--- a/Player.h	Sat Jul 13 21:36:35 2013 +0200
+++ b/Player.h	Sun Jul 14 23:22:43 2013 +0200
@@ -1,6 +1,7 @@
 #pragma once
 #include "Items.h"
 #include "Spells.h"
+#include "Conditions.h"
 
 
 
@@ -446,28 +447,6 @@
 #pragma pack(push, 1)
 struct Player
 {
-enum Condition: unsigned __int32
-    {
-    Condition_Cursed = 0,
-    Condition_Weak = 1,
-    Condition_Sleep = 2,
-    Condition_Fear = 3,
-    Condition_Drunk = 4,
-    Condition_Insane = 5,
-    Condition_Poison1 = 6,
-    Condition_Disease1 = 7,
-    Condition_Poison2 = 8,
-    Condition_Disease2 = 9,
-    Condition_Poison3 = 10,
-    Condition_Disease3 = 11,
-    Condition_Paralyzed = 12,
-    Condition_Unconcious = 13,
-    Condition_Dead = 14,
-    Condition_Pertified = 15,
-    Condition_Eradicated = 16,
-    Condition_Zombie = 17,
-    Condition_Good = 18
-    };
 
   Player();
 
@@ -570,7 +549,7 @@
   bool CanAct();
   bool CanSteal();
   bool CanEquip_RaceAndAlignmentCheck(unsigned int uItemID);
-  int SetCondition(unsigned int uConditionIdx, int a3);
+  void SetCondition(unsigned int uConditionIdx, int a3);
   bool ProfessionOrGuildFlagsCorrect(unsigned int uClass, int a3);
   void PlaySound(PlayerSpeech speech, int a3);
   void PlayEmotion(CHARACTER_EXPRESSION_ID expression, int a3);
@@ -595,31 +574,36 @@
   void DrawPlayerBuffAnimBasedOnCondition(int currPlayerId);
   void EquipBody(ITEM_EQUIP_TYPE uEquipType);
 
-  inline bool Weak()       {return pConditions[Condition_Weak] != 0;}
-  inline bool Dead()       {return pConditions[Condition_Dead] != 0;}
-  inline bool Eradicated() {return pConditions[Condition_Eradicated] != 0;}
-  inline bool Zombie()     {return pConditions[Condition_Zombie] != 0;}
-  inline bool Cursed()     {return pConditions[Condition_Cursed] != 0;}
-  inline bool Pertified()  {return pConditions[Condition_Pertified] != 0;}
+  bool Weak();
+  bool Dead();
+  bool Eradicated();
+  bool Zombie();
+  bool Cursed();
+  bool Pertified();
+  bool Unconcious();
 
-  inline void SetCursed(bool state)      {pConditions[Condition_Cursed] = state;}
-  inline void SetWeak(bool state)        {pConditions[Condition_Weak] = state;}
-  inline void SetAsleep(bool state)      {pConditions[Condition_Sleep] = state;}
-  inline void SetAfraid(bool state)      {pConditions[Condition_Fear] = state;}
-  inline void SetDrunk(bool state)       {pConditions[Condition_Drunk] = state;}
-  inline void SetInsane(bool state)      {pConditions[Condition_Insane] = state;}
-  inline void SetPoison1(bool state)     {pConditions[Condition_Poison1] = state;}
-  inline void SetDisease1(bool state)    {pConditions[Condition_Disease1] = state;}
-  inline void SetPoison2(bool state)     {pConditions[Condition_Poison2] = state;}
-  inline void SetDisease2(bool state)    {pConditions[Condition_Disease2] = state;}
-  inline void SetPoison3(bool state)     {pConditions[Condition_Poison3] = state;}
-  inline void SetDisease3(bool state)    {pConditions[Condition_Disease3] = state;}
-  inline void SetParalyzed(bool state)   {pConditions[Condition_Paralyzed] = state;}
-  inline void SetUnconcious(bool state)  {pConditions[Condition_Unconcious] = state;}
-  inline void SetDead(bool state)        {pConditions[Condition_Dead] = state;}
-  inline void SetPertified(bool state)   {pConditions[Condition_Pertified] = state;}
-  inline void SetEradicated(bool state)  {pConditions[Condition_Eradicated] = state;}
-  inline void SetZombie(bool state)      {pConditions[Condition_Zombie] = state;}
+  void SetCursed(bool state);
+  void SetWeak(bool state);
+  void SetAsleep(bool state);
+  void SetAfraid(bool state);
+  void SetDrunk(bool state);
+  void SetInsane(bool state);
+  void SetPoison1(bool state);
+  void SetDisease1(bool state);
+  void SetPoison2(bool state);
+  void SetDisease2(bool state);
+  void SetPoison3(bool state);
+  void SetDisease3(bool state);
+  void SetParalyzed(bool state);
+  void SetUnconcious(bool state);
+  void SetDead(bool state);
+  void SetPertified(bool state);
+  void SetEradicated(bool state);
+  void SetZombie(bool state);
+
+  void SetCondWeakWithBlockCheck (int blockable);
+  void SetCondInsaneWithBlockCheck (int blockable);
+  void SetCondDeadWithBlockCheck (int blockable);
 
   inline bool IsRaceHuman() {return GetRace() == CHARACTER_RACE_HUMAN;}
   inline bool IsRaceDwarf() {return GetRace() == CHARACTER_RACE_DWARF;}
--- a/Spells.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/Spells.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -974,7 +974,7 @@
         //v32 = pParty->pPlayers;//[0].pConditions[1];
         //do
         for (uint i = 0; i < 4; ++i)
-          if (pParty->pPlayers[i].pConditions[Player::Condition_Weak])
+          if (pParty->pPlayers[i].Weak())
             return;
 		//while ( v32 <= &pParty->pPlayers[3] );
         //if ( !levela )
--- a/UI/UIRest.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/UI/UIRest.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -105,7 +105,7 @@
     text_color =   TargetColor(10, 0, 0);
     shadow_color = TargetColor(230, 214, 193);
     for(int i=1; i<5; ++i)
-        if ( !pPlayers[i]->pConditions[Player::Condition_Dead] && !pPlayers[i]->pConditions[Player::Condition_Eradicated] && pPlayers[i]->sHealth > 0 )
+        if ( !pPlayers[i]->Dead() && !pPlayers[i]->Eradicated() && pPlayers[i]->sHealth > 0 )
             ++live_characters;
 
     if ( live_characters )
--- a/mm7_4.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/mm7_4.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -1606,7 +1606,7 @@
     if (pParty->days_played_without_rest > 1)
     {
       for (uint i = 0; i < 4; ++i)
-        pParty->pPlayers[i].SetCondition(Player::Condition_Weak, 0);
+        pParty->pPlayers[i].SetCondWeakWithBlockCheck(0);
 
       if (pParty->uNumFoodRations)
         Party::TakeFood(1);
@@ -1624,9 +1624,9 @@
           if (!player->Pertified() && !player->Eradicated() && !player->Dead())
           {
             if (rand() % 100 < 5 * pParty->days_played_without_rest)
-              player->SetCondition(Player::Condition_Dead, 0);
+              player->SetCondDeadWithBlockCheck(0);
             if (rand() % 100 < 10 * pParty->days_played_without_rest)
-              player->SetCondition(Player::Condition_Insane, 0);
+              player->SetCondInsaneWithBlockCheck(0);
           }
         }
     }
--- a/mm7_5.cpp	Sat Jul 13 21:36:35 2013 +0200
+++ b/mm7_5.cpp	Sun Jul 14 23:22:43 2013 +0200
@@ -2488,10 +2488,10 @@
           dword_506F14 = 2;
           pParty->RestAndHeal();
           pParty->days_played_without_rest = 0;
-          pParty->pPlayers[3].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
-          pParty->pPlayers[2].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
-          pParty->pPlayers[1].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
-          pParty->pPlayers[0].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+          pParty->pPlayers[3].SetAsleep(1);
+          pParty->pPlayers[2].SetAsleep(1);
+          pParty->pPlayers[1].SetAsleep(1);
+          pParty->pPlayers[0].SetAsleep(1);
           continue;
         case UIMSG_RestWindow:
           if ( pMessageQueue_50CBD0->uNumMessages )
@@ -2598,10 +2598,10 @@
             dword_506F14 = 2;
             pParty->RestAndHeal();
             pParty->days_played_without_rest = 0;
-            pParty->pPlayers[3].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
-            pParty->pPlayers[2].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
-            pParty->pPlayers[1].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
-            pParty->pPlayers[0].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+            pParty->pPlayers[3].SetAsleep(1);
+            pParty->pPlayers[2].SetAsleep(1);
+            pParty->pPlayers[1].SetAsleep(1);
+            pParty->pPlayers[0].SetAsleep(1);
           }
           continue;
         case UIMSG_AlreadyResting: