comparison Player.cpp @ 2331:9551756f46c4

Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
author Grumpy7
date Wed, 02 Apr 2014 01:21:05 +0200
parents b0f10ef66e00
children ddb803517a48
comparison
equal deleted inserted replaced
2330:5133eea7a4ca 2331:9551756f46c4
20 #include "Autonotes.h" 20 #include "Autonotes.h"
21 #include "Awards.h" 21 #include "Awards.h"
22 #include "texts.h" 22 #include "texts.h"
23 23
24 #include "stru123.h" 24 #include "stru123.h"
25 #include "stru298.h"
26 #include "ObjectList.h"
25 #include "mm7_data.h" 27 #include "mm7_data.h"
26 #include "MM7.h" 28 #include "MM7.h"
27 #include "SpriteObject.h" 29 #include "SpriteObject.h"
28 #include "DecalBuilder.h" 30 #include "DecalBuilder.h"
29 #include "CastSpellInfo.h" 31 #include "CastSpellInfo.h"
7956 { 7958 {
7957 attNegativeMod = effectiveActorArmor + 15; 7959 attNegativeMod = effectiveActorArmor + 15;
7958 } 7960 }
7959 return (attPositiveMod > attNegativeMod); 7961 return (attPositiveMod > attNegativeMod);
7960 } 7962 }
7963
7964
7965 //----- (0042ECB5) --------------------------------------------------------
7966 void Player::_42ECB5_PlayerAttacksActor()
7967 {
7968 char *v5; // eax@8
7969 unsigned int v9; // ecx@21
7970 char *v11; // eax@26
7971 unsigned int v12; // eax@47
7972 SoundID v24; // [sp-4h] [bp-40h]@58
7973
7974 //result = pParty->pPlayers[uActiveCharacter-1].CanAct();
7975 Player* player = &pParty->pPlayers[uActiveCharacter - 1];
7976 if (!player->CanAct())
7977 return;
7978
7979 CastSpellInfoHelpers::_427D48();
7980 //v3 = 0;
7981 if (pParty->Invisible())
7982 pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
7983
7984 //v31 = player->pEquipment.uBow;
7985 int bow_idx = player->pEquipment.uBow;
7986 if (bow_idx && player->pInventoryItemList[bow_idx - 1].IsBroken())
7987 bow_idx = 0;
7988
7989 //v32 = 0;
7990 int wand_item_id = 0;
7991 //v33 = 0;
7992 //v4 = v1->pEquipment.uMainHand;
7993 int laser_weapon_item_id = 0;
7994
7995 int main_hand_idx = player->pEquipment.uMainHand;
7996 if (main_hand_idx)
7997 {
7998 ItemGen* item = &player->pInventoryItemList[main_hand_idx - 1];
7999 //v5 = (char *)v1 + 36 * v4;
8000 if (!item->IsBroken())
8001 {
8002 //v28b = &v1->pInventoryItems[v4].uItemID;
8003 //v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124);
8004 if (item->GetItemEquipType() == EQUIP_WAND)
8005 {
8006 if (item->uNumCharges <= 0)
8007 player->pEquipment.uMainHand = 0; // wand discharged - unequip
8008 else
8009 wand_item_id = item->uItemID;//*((int *)v5 + 124);
8010 }
8011 else if (item->uItemID == ITEM_BLASTER || item->uItemID == ITEM_LASER_RIFLE)
8012 laser_weapon_item_id = item->uItemID;//*((int *)v5 + 124);
8013 }
8014 }
8015
8016 //v30 = 0;
8017 //v29 = 0;
8018 //v28 = 0;
8019 //v7 = pMouse->uPointingObjectID;
8020
8021 int target_pid = pMouse->uPointingObjectID;
8022 int target_type = PID_TYPE(target_pid),
8023 target_id = PID_ID(target_pid);
8024 if (target_type != OBJECT_Actor || !pActors[target_id].CanAct())
8025 {
8026 target_pid = stru_50C198.FindClosestActor(5120, 0, 0);
8027 target_type = PID_TYPE(target_pid);
8028 target_id = PID_ID(target_pid);
8029 }
8030
8031 Actor* actor = &pActors[target_id];
8032 int actor_distance = 0;
8033 if (target_type == OBJECT_Actor)
8034 {
8035 int distance_x = actor->vPosition.x - pParty->vPosition.x,
8036 distance_y = actor->vPosition.y - pParty->vPosition.y,
8037 distance_z = actor->vPosition.z - pParty->vPosition.z;
8038 actor_distance = integer_sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z) - actor->uActorRadius;
8039 if (actor_distance < 0)
8040 actor_distance = 0;
8041 }
8042
8043 bool shooting_bow = false,
8044 shotting_laser = false,
8045 shooting_wand = false,
8046 melee_attack = false;
8047 if (laser_weapon_item_id)
8048 {
8049 shotting_laser = true;
8050 _42777D_CastSpell_UseWand_ShootArrow(SPELL_LASER_PROJECTILE, uActiveCharacter - 1, 0, 0, uActiveCharacter + 8);
8051 }
8052 else if (wand_item_id)
8053 {
8054 shooting_wand = true;
8055
8056 int main_hand_idx = player->pEquipment.uMainHand;
8057 _42777D_CastSpell_UseWand_ShootArrow(wand_spell_ids[player->pInventoryItemList[main_hand_idx - 1].uItemID - ITEM_WAND_FIRE], uActiveCharacter - 1, 8, 0, uActiveCharacter + 8);
8058
8059 if (!--player->pInventoryItemList[main_hand_idx - 1].uNumCharges)
8060 player->pEquipment.uMainHand = 0;
8061 }
8062 else if (target_type == OBJECT_Actor && actor_distance <= 407.2)
8063 {
8064 melee_attack = true;
8065
8066 Vec3_int_ a3;
8067 a3.x = actor->vPosition.x - pParty->vPosition.x;
8068 a3.y = actor->vPosition.y - pParty->vPosition.y;
8069 a3.z = actor->vPosition.z - pParty->vPosition.z;
8070 Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z);
8071
8072 DamageMonsterFromParty(PID(OBJECT_Player, uActiveCharacter - 1), target_id, &a3);
8073 if (player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_TWO_HANDED) || player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_SINGLE_HANDED))
8074 _42FA66_do_explosive_impact(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z + actor->uActorHeight / 2, 0, 512, uActiveCharacter);
8075 }
8076 else if (bow_idx)
8077 {
8078 shooting_bow = true;
8079 _42777D_CastSpell_UseWand_ShootArrow(SPELL_BOW_ARROW, uActiveCharacter - 1, 0, 0, 0);
8080 }
8081 else
8082 {
8083 melee_attack = true;
8084 ; // actor out of range or no actor; no ranged weapon so melee attacking air
8085 }
8086
8087 if (!pParty->bTurnBasedModeOn && melee_attack) // wands, bows & lasers will add recovery while shooting spell effect
8088 {
8089 int recovery = player->GetAttackRecoveryTime(false);
8090 if (recovery < 30 )
8091 recovery = 30;
8092 player->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * (double)recovery * 2.133333333333333);
8093 }
8094
8095 int v34 = 0;
8096 if (shooting_wand)
8097 return;
8098 else if (shooting_bow)
8099 {
8100 v34 = 5;
8101 player->PlaySound(SPEECH_50, 0);
8102 }
8103 if (shotting_laser)
8104 v34 = 7;
8105 else
8106 {
8107 int main_hand_idx = player->pEquipment.uMainHand;
8108 if (player->HasItemEquipped(EQUIP_TWO_HANDED))
8109 v34 = player->pInventoryItemList[main_hand_idx - 1].GetPlayerSkillType();
8110 pTurnEngine->ApplyPlayerAction();
8111 }
8112
8113 switch (v34)
8114 {
8115 case 0: pAudioPlayer->PlaySound(SOUND_81, 0, 0, -1, 0, 0, 0, 0); break;
8116 case 1: pAudioPlayer->PlaySound(SOUND_84, 0, 0, -1, 0, 0, 0, 0); break;
8117 case 2: pAudioPlayer->PlaySound(SOUND_85, 0, 0, -1, 0, 0, 0, 0); break;
8118 case 3: pAudioPlayer->PlaySound(SOUND_78, 0, 0, -1, 0, 0, 0, 0); break;
8119 case 4: pAudioPlayer->PlaySound(SOUND_80, 0, 0, -1, 0, 0, 0, 0); break;
8120 case 5: pAudioPlayer->PlaySound(SOUND_71, 0, 0, -1, 0, 0, 0, 0); break;
8121 case 6: pAudioPlayer->PlaySound(SOUND_83, 0, 0, -1, 0, 0, 0, 0); break;
8122 case 7: pAudioPlayer->PlaySound(SOUND_67, 0, 0, -1, 0, 0, 0, 0); break;
8123 }
8124 }
8125
8126
8127 //----- (0042FA66) --------------------------------------------------------
8128 void Player::_42FA66_do_explosive_impact(int a1, int a2, int a3, int a4, __int16 a5, signed int a6)
8129 {
8130 unsigned __int16 v9; // ax@5
8131
8132 SpriteObject a1a; // [sp+Ch] [bp-74h]@1
8133 //SpriteObject::SpriteObject(&a1a);
8134 a1a.uType = 600;
8135 a1a.stru_24.Reset();
8136
8137 a1a.spell_id = SPELL_FIRE_FIREBALL;
8138 a1a.spell_level = 8;
8139 a1a.spell_skill = 3;
8140 v9 = 0;
8141 for ( uint i = 0; i < pObjectList->uNumObjects; ++i )
8142 {
8143 if ( a1a.uType == pObjectList->pObjects[i].uObjectID )
8144 v9 = i;
8145 }
8146 a1a.uObjectDescID = v9;
8147 a1a.vPosition.x = a1;
8148 a1a.vPosition.y = a2;
8149 a1a.vPosition.z = a3;
8150 a1a.uAttributes = 0;
8151 a1a.uSectorID = pIndoor->GetSector(a1, a2, a3);
8152 a1a.uSpriteFrameID = 0;
8153 a1a.spell_target_pid = 0;
8154 a1a.field_60_distance_related_prolly_lod = 0;
8155 a1a.uFacing = 0;
8156 a1a.uSoundID = 0;
8157 if ( a6 >= 1 || a6 <= 4 )
8158 a1a.spell_caster_pid = PID(OBJECT_Player, a6 - 1);
8159 else
8160 a1a.spell_caster_pid = 0;
8161
8162 int id = a1a.Create(0, 0, 0, 0);
8163 if (id != -1)
8164 AttackerInfo.Add(PID(OBJECT_Item, id), a5, SLOWORD(a1a.vPosition.x), SLOWORD(a1a.vPosition.y),
8165 SLOWORD(a1a.vPosition.z), 0, 0);
8166 }