Mercurial > mm7
diff 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 |
line wrap: on
line diff
--- a/Player.cpp Tue Apr 01 23:44:27 2014 +0200 +++ b/Player.cpp Wed Apr 02 01:21:05 2014 +0200 @@ -22,6 +22,8 @@ #include "texts.h" #include "stru123.h" +#include "stru298.h" +#include "ObjectList.h" #include "mm7_data.h" #include "MM7.h" #include "SpriteObject.h" @@ -7957,4 +7959,208 @@ attNegativeMod = effectiveActorArmor + 15; } return (attPositiveMod > attNegativeMod); +} + + +//----- (0042ECB5) -------------------------------------------------------- +void Player::_42ECB5_PlayerAttacksActor() +{ + char *v5; // eax@8 + unsigned int v9; // ecx@21 + char *v11; // eax@26 + unsigned int v12; // eax@47 + SoundID v24; // [sp-4h] [bp-40h]@58 + + //result = pParty->pPlayers[uActiveCharacter-1].CanAct(); + Player* player = &pParty->pPlayers[uActiveCharacter - 1]; + if (!player->CanAct()) + return; + + CastSpellInfoHelpers::_427D48(); + //v3 = 0; + if (pParty->Invisible()) + pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset(); + + //v31 = player->pEquipment.uBow; + int bow_idx = player->pEquipment.uBow; + if (bow_idx && player->pInventoryItemList[bow_idx - 1].IsBroken()) + bow_idx = 0; + + //v32 = 0; + int wand_item_id = 0; + //v33 = 0; + //v4 = v1->pEquipment.uMainHand; + int laser_weapon_item_id = 0; + + int main_hand_idx = player->pEquipment.uMainHand; + if (main_hand_idx) + { + ItemGen* item = &player->pInventoryItemList[main_hand_idx - 1]; + //v5 = (char *)v1 + 36 * v4; + if (!item->IsBroken()) + { + //v28b = &v1->pInventoryItems[v4].uItemID; + //v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124); + if (item->GetItemEquipType() == EQUIP_WAND) + { + if (item->uNumCharges <= 0) + player->pEquipment.uMainHand = 0; // wand discharged - unequip + else + wand_item_id = item->uItemID;//*((int *)v5 + 124); + } + else if (item->uItemID == ITEM_BLASTER || item->uItemID == ITEM_LASER_RIFLE) + laser_weapon_item_id = item->uItemID;//*((int *)v5 + 124); + } + } + + //v30 = 0; + //v29 = 0; + //v28 = 0; + //v7 = pMouse->uPointingObjectID; + + int target_pid = pMouse->uPointingObjectID; + int target_type = PID_TYPE(target_pid), + target_id = PID_ID(target_pid); + if (target_type != OBJECT_Actor || !pActors[target_id].CanAct()) + { + target_pid = stru_50C198.FindClosestActor(5120, 0, 0); + target_type = PID_TYPE(target_pid); + target_id = PID_ID(target_pid); + } + + Actor* actor = &pActors[target_id]; + int actor_distance = 0; + if (target_type == OBJECT_Actor) + { + int distance_x = actor->vPosition.x - pParty->vPosition.x, + distance_y = actor->vPosition.y - pParty->vPosition.y, + distance_z = actor->vPosition.z - pParty->vPosition.z; + actor_distance = integer_sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z) - actor->uActorRadius; + if (actor_distance < 0) + actor_distance = 0; + } + + bool shooting_bow = false, + shotting_laser = false, + shooting_wand = false, + melee_attack = false; + if (laser_weapon_item_id) + { + shotting_laser = true; + _42777D_CastSpell_UseWand_ShootArrow(SPELL_LASER_PROJECTILE, uActiveCharacter - 1, 0, 0, uActiveCharacter + 8); + } + else if (wand_item_id) + { + shooting_wand = true; + + int main_hand_idx = player->pEquipment.uMainHand; + _42777D_CastSpell_UseWand_ShootArrow(wand_spell_ids[player->pInventoryItemList[main_hand_idx - 1].uItemID - ITEM_WAND_FIRE], uActiveCharacter - 1, 8, 0, uActiveCharacter + 8); + + if (!--player->pInventoryItemList[main_hand_idx - 1].uNumCharges) + player->pEquipment.uMainHand = 0; + } + else if (target_type == OBJECT_Actor && actor_distance <= 407.2) + { + melee_attack = true; + + Vec3_int_ a3; + a3.x = actor->vPosition.x - pParty->vPosition.x; + a3.y = actor->vPosition.y - pParty->vPosition.y; + a3.z = actor->vPosition.z - pParty->vPosition.z; + Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z); + + DamageMonsterFromParty(PID(OBJECT_Player, uActiveCharacter - 1), target_id, &a3); + if (player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_TWO_HANDED) || player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_SINGLE_HANDED)) + _42FA66_do_explosive_impact(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z + actor->uActorHeight / 2, 0, 512, uActiveCharacter); + } + else if (bow_idx) + { + shooting_bow = true; + _42777D_CastSpell_UseWand_ShootArrow(SPELL_BOW_ARROW, uActiveCharacter - 1, 0, 0, 0); + } + else + { + melee_attack = true; + ; // actor out of range or no actor; no ranged weapon so melee attacking air + } + + if (!pParty->bTurnBasedModeOn && melee_attack) // wands, bows & lasers will add recovery while shooting spell effect + { + int recovery = player->GetAttackRecoveryTime(false); + if (recovery < 30 ) + recovery = 30; + player->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * (double)recovery * 2.133333333333333); + } + + int v34 = 0; + if (shooting_wand) + return; + else if (shooting_bow) + { + v34 = 5; + player->PlaySound(SPEECH_50, 0); + } + if (shotting_laser) + v34 = 7; + else + { + int main_hand_idx = player->pEquipment.uMainHand; + if (player->HasItemEquipped(EQUIP_TWO_HANDED)) + v34 = player->pInventoryItemList[main_hand_idx - 1].GetPlayerSkillType(); + pTurnEngine->ApplyPlayerAction(); + } + + switch (v34) + { + case 0: pAudioPlayer->PlaySound(SOUND_81, 0, 0, -1, 0, 0, 0, 0); break; + case 1: pAudioPlayer->PlaySound(SOUND_84, 0, 0, -1, 0, 0, 0, 0); break; + case 2: pAudioPlayer->PlaySound(SOUND_85, 0, 0, -1, 0, 0, 0, 0); break; + case 3: pAudioPlayer->PlaySound(SOUND_78, 0, 0, -1, 0, 0, 0, 0); break; + case 4: pAudioPlayer->PlaySound(SOUND_80, 0, 0, -1, 0, 0, 0, 0); break; + case 5: pAudioPlayer->PlaySound(SOUND_71, 0, 0, -1, 0, 0, 0, 0); break; + case 6: pAudioPlayer->PlaySound(SOUND_83, 0, 0, -1, 0, 0, 0, 0); break; + case 7: pAudioPlayer->PlaySound(SOUND_67, 0, 0, -1, 0, 0, 0, 0); break; + } +} + + +//----- (0042FA66) -------------------------------------------------------- +void Player::_42FA66_do_explosive_impact(int a1, int a2, int a3, int a4, __int16 a5, signed int a6) +{ + unsigned __int16 v9; // ax@5 + + SpriteObject a1a; // [sp+Ch] [bp-74h]@1 + //SpriteObject::SpriteObject(&a1a); + a1a.uType = 600; + a1a.stru_24.Reset(); + + a1a.spell_id = SPELL_FIRE_FIREBALL; + a1a.spell_level = 8; + a1a.spell_skill = 3; + v9 = 0; + for ( uint i = 0; i < pObjectList->uNumObjects; ++i ) + { + if ( a1a.uType == pObjectList->pObjects[i].uObjectID ) + v9 = i; + } + a1a.uObjectDescID = v9; + a1a.vPosition.x = a1; + a1a.vPosition.y = a2; + a1a.vPosition.z = a3; + a1a.uAttributes = 0; + a1a.uSectorID = pIndoor->GetSector(a1, a2, a3); + a1a.uSpriteFrameID = 0; + a1a.spell_target_pid = 0; + a1a.field_60_distance_related_prolly_lod = 0; + a1a.uFacing = 0; + a1a.uSoundID = 0; + if ( a6 >= 1 || a6 <= 4 ) + a1a.spell_caster_pid = PID(OBJECT_Player, a6 - 1); + else + a1a.spell_caster_pid = 0; + + int id = a1a.Create(0, 0, 0, 0); + if (id != -1) + AttackerInfo.Add(PID(OBJECT_Item, id), a5, SLOWORD(a1a.vPosition.x), SLOWORD(a1a.vPosition.y), + SLOWORD(a1a.vPosition.z), 0, 0); } \ No newline at end of file