Skip to content

Commit

Permalink
Assassin completed!
Browse files Browse the repository at this point in the history
  • Loading branch information
DMD authored and DMD committed Sep 24, 2016
1 parent eb87e45 commit 50ffaab
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 27 deletions.
100 changes: 79 additions & 21 deletions TemplePlus/action_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,12 @@ void ActionSequenceSystem::ActSeqGetPicker(){
}

if (tgtClassif == D20TC_CastSpell){

unsigned int spellEnum, spellClass, spellLevel, metaMagicData;
D20SpellDataExtractInfo(&d20Sys.globD20Action->d20SpellData,
&spellEnum, nullptr, &spellClass, &spellLevel,nullptr,&metaMagicData);


auto curSeq = *actSeqSys.actSeqCur;
curSeq->spellPktBody.spellRange *= ((MetaMagicData)metaMagicData).metaMagicEnlargeSpellCount + 1;
SpellEntry spellEntry;
Expand Down Expand Up @@ -1686,31 +1689,82 @@ uint32_t ActionSequenceSystem::TurnBasedStatusUpdate(D20Actn* d20a, TurnBasedSta
*/
}

uint32_t ActionSequenceSystem::SequencePathSthgSub_10096450(ActnSeq* actSeq, uint32_t idx ,TurnBasedStatus * tbStat)
{
uint32_t result = 0;
__asm{
push esi;
push ecx;
push ebx;
mov ecx, this;
uint32_t ActionSequenceSystem::SequencePathSthgSub_10096450(ActnSeq* actSeq, int idx ,TurnBasedStatus * tbStat){

if (idx < 0 || idx >= actSeq->d20ActArrayNum)
return AEC_INVALID_ACTION;

auto d20a = &actSeq->d20ActArray[idx];

auto performer = d20a->d20APerformer;

auto performerLoc = objSystem->GetObject(performer)->GetLocationFull();

auto d20aType = d20a->d20ActType;

mov esi, idx;
push esi;
mov esi, [ecx]._sub_10096450;
mov ebx, tbStat;
mov eax, actSeq;
push eax;
call esi;
add esp, 8;
// check actions
auto result = AEC_OK;

// target
auto tgtChecker = d20Sys.d20Defs[d20aType].tgtCheckFunc;
if (tgtChecker)
result = (ActionErrorCode)tgtChecker(d20a, tbStat);
if (result != AEC_OK)
return result;

// hourglass & action check
result = seqCheckAction(d20a, tbStat);
if (result != AEC_OK)
return result;

// location
auto locChecker = d20Sys.d20Defs[d20aType].locCheckFunc;
if (locChecker)
result = locChecker(d20a, tbStat, &performerLoc);
if (result != AEC_OK)
return result;

auto numActions = actSeq->d20ActArrayNum;
for (auto i=0; i < numActions; i++){

auto flags = d20Sys.GetActionFlags(d20aType);
if (flags & D20ADF_DoLocationCheckAtDestination){
auto p = d20a->path;
if (p != nullptr){
performerLoc = p->to;
}
result = ActionSequenceChecksRegardLoc(&performerLoc, tbStat, idx + 1, actSeq);
return result;
}

mov result, eax;
pop ebx;
pop ecx;
pop esi;
}
return result;

return AEC_OK;


// uint32_t result = 0;
// __asm{
// push esi;
// push ecx;
// push ebx;
// mov ecx, this;
//
//
//mov esi, idx;
//push esi;
//mov esi, [ecx]._sub_10096450;
//mov ebx, tbStat;
//mov eax, actSeq;
//push eax;
//call esi;
//add esp, 8;
//
//mov result, eax;
//pop ebx;
//pop ecx;
//pop esi;
// }
// return result;
}

uint32_t ActionSequenceSystem::seqCheckFuncs(TurnBasedStatus* tbStatus)
Expand Down Expand Up @@ -2204,6 +2258,10 @@ uint32_t ActionSequenceSystem::curSeqNext()
DK_SIG_Action_Recipient,
(int)d20a, 0);
}
if (critterSys.IsMovingSilently(performer)){
critterSys.SetMovingSilently(performer, FALSE);
}

} else
{
d20Sys.d20SendSignal((*actSeqCur)->performer, DK_SIG_Action_Recipient,
Expand Down
2 changes: 1 addition & 1 deletion TemplePlus/action_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct ActionSequenceSystem : temple::AddressTable
*/
void ProcessSequenceForAoOs(ActnSeq*actSeq, D20Actn * d20a); // actSeq@<ebx>
int(CrossBowSthgReload_1008E8A0)(D20Actn *d20a, ActnSeq*actSeq); //, ActnSeq *actSeq@<ebx>
uint32_t SequencePathSthgSub_10096450(ActnSeq * actSeq, uint32_t idx, TurnBasedStatus* tbStat);
uint32_t SequencePathSthgSub_10096450(ActnSeq * actSeq, int idx, TurnBasedStatus* tbStat);
//10097C20

uint32_t seqCheckFuncs(TurnBasedStatus *tbStatus);
Expand Down
5 changes: 4 additions & 1 deletion TemplePlus/bonus.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "common.h"
#include "tig/tig_mes.h"

#include <map>

struct BonusList;

Expand All @@ -27,6 +27,9 @@ struct BonusSystem : temple::AddressTable
MesHandle * bonusMesHandle; //102E45A8
MesHandle bonusMesNew;
BonusSystem();


std::map<int, std::string> customBonusStrings;
};

extern BonusSystem bonusSys;
Expand Down
24 changes: 24 additions & 0 deletions TemplePlus/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "feat.h"
#include "d20.h"
#include <infrastructure/elfhash.h>
#include <map>

static void NormalizeAxis(float& offset, uint32_t &tilePos) {
auto tiles = (int) (offset / INCH_PER_TILE);
Expand Down Expand Up @@ -146,6 +147,14 @@ int BonusList::AddBonusWithDesc(int value, int bonType, int mesline, char* descr
return 0;
}

int BonusList::AddBonusWithDesc(int value, int bonType, std::string & text, char * descr){
if (AddBonus(value, bonType, text)){
this->bonusEntries[this->bonCount - 1].bonusDescr = descr;
return TRUE;
}
return FALSE;
}

int BonusList::AddBonusFromFeat(int value, int bonType, int mesline, feat_enums feat){
auto featName = feats.GetFeatName(feat);
return AddBonusWithDesc(value, bonType, mesline, featName);
Expand Down Expand Up @@ -286,6 +295,21 @@ int BonusList::AddBonus(int value, int bonType, int mesline){
return bonusSys.bonusAddToBonusList(this, value, bonType, mesline);
}

BOOL BonusList::AddBonus(int value, int bonType, std::string & textArg){
auto textId = ElfHash::Hash(textArg);
auto textCache = bonusSys.customBonusStrings.find(textId);
if (textCache == bonusSys.customBonusStrings.end()) {
bonusSys.customBonusStrings[textId] = textArg;
}
if (this->bonCount >= BonusListMax) return FALSE;

this->bonusEntries[this->bonCount].bonValue = value;
this->bonusEntries[this->bonCount].bonType = bonType;
this->bonusEntries[this->bonCount].bonusMesString = (char*)bonusSys.customBonusStrings[textId].c_str();
this->bonusEntries[this->bonCount++].bonusDescr = nullptr;
return TRUE;
}


const char* BonusList::GetBonusMesLine(int lineNum) {
MesLine mesLine(lineNum);
Expand Down
2 changes: 2 additions & 0 deletions TemplePlus/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ struct BonusList
Will register in the D20 roll history using the specified line from bonus.mes
*/
int AddBonus(int value, int bonType, int mesline);
BOOL AddBonus(int value, int bonType, std::string & text);
int AddBonusWithDesc(int value, int bonType, int mesline, char* descr);
int AddBonusWithDesc(int value, int bonType, std::string &text, char* descr);
int AddBonusFromFeat(int value, int bonType, int mesline, feat_enums feat); // same as the above, but it also gets the feat name automatically
int AddBonusFromFeat(int value, int bonType, int mesline, std::string &feat);
int ModifyBonus(int value, int bonType, int meslineIdentifier); // directly modifies a bonus. For non-stacking bonus types that you want to stack anyway. Note: the mesline is used as an identifier here!
Expand Down
8 changes: 8 additions & 0 deletions TemplePlus/critter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ bool LegacyCritterSystem::IsMovingSilently(objHndl critter)
return (flags & OCF_MOVING_SILENTLY) == OCF_MOVING_SILENTLY;
}

void LegacyCritterSystem::SetMovingSilently(objHndl critter, BOOL newMovingSilState){
temple::GetRef<void(__cdecl)(objHndl, BOOL)>(0x100805C0)(critter, newMovingSilState);
}

bool LegacyCritterSystem::IsCombatModeActive(objHndl critter)
{
auto flags = GetCritterFlags(critter);
Expand All @@ -489,6 +493,10 @@ int LegacyCritterSystem::GetLevel(objHndl critter) {
return objects.StatLevelGet(critter, stat_level);
}

int LegacyCritterSystem::SkillLevel(objHndl critter, SkillEnum skill){
return dispatch.dispatch1ESkillLevel(critter, skill, nullptr, critter, 1);
}

Race LegacyCritterSystem::GetRace(objHndl critter) {
return (Race)objects.StatLevelGet(critter, stat_race);
}
Expand Down
4 changes: 4 additions & 0 deletions TemplePlus/critter.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ struct LegacyCritterSystem : temple::AddressTable
CritterFlag GetCritterFlags(objHndl critter);

bool IsMovingSilently(objHndl critter);

void SetMovingSilently(objHndl critter, BOOL newMovingSilState);

bool IsCombatModeActive(objHndl critter);

Expand All @@ -245,6 +247,8 @@ struct LegacyCritterSystem : temple::AddressTable

int GetLevel(objHndl critter);

int SkillLevel(objHndl critter, SkillEnum skill);

Race GetRace(objHndl critter);

Gender GetGender(objHndl critter);
Expand Down
70 changes: 69 additions & 1 deletion TemplePlus/d20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "gamesystems/particlesystems.h"
#include <infrastructure/elfhash.h>
#include "python/python_integration_d20_action.h"
#include <turn_based.h>


static_assert(sizeof(D20SpellData) == (8U), "D20SpellData structure has the wrong size!"); //shut up compiler, this is ok
Expand Down Expand Up @@ -139,6 +140,7 @@ class D20ActionCallbacks {
ActionCheck(EmptyBody);
ActionCheck(Python); // calls python script
ActionCheck(QuiveringPalm);
ActionCheck(Sneak);
ActionCheck(Sunder);
ActionCheck(TripAttack);

Expand All @@ -165,6 +167,7 @@ class D20ActionCallbacks {
PerformFunc(EmptyBody);
PerformFunc(Python);
PerformFunc(QuiveringPalm);
PerformFunc(Sneak);
PerformFunc(StandardAttack);
PerformFunc(TripAttack);
PerformFunc(UseItem);
Expand Down Expand Up @@ -476,6 +479,12 @@ void LegacyD20System::NewD20ActionsInit()
d20Defs[d20Type].flags = (D20ADF)(D20ADF_TargetSingleExcSelf | D20ADF_TriggersCombat | D20ADF_UseCursorForPicking);


d20Type = D20A_SNEAK;
d20Defs[d20Type].actionCheckFunc = d20Callbacks.ActionCheckSneak;
d20Defs[d20Type].locCheckFunc = nullptr;
d20Defs[d20Type].actionCost = d20Callbacks.ActionCostMoveAction;
d20Defs[d20Type].performFunc = d20Callbacks.PerformSneak;


// *(int*)&d20Defs[D20A_USE_POTION].flags |= (int)D20ADF_SimulsCompatible; // need to modify the SimulsEnqueue script because it also checks for san_start_combat being null
// *(int*)&d20Defs[D20A_TRIP].flags -= (int)D20ADF_Unk8000;
Expand Down Expand Up @@ -1110,10 +1119,12 @@ int LegacyD20System::TargetCheck(D20Actn* d20a)
return 0;
case D20TC_CallLightning:
return (*addresses.actSeqTargetsIdx) >= 0;

case D20TC_CastSpell:
curSeq->d20Action = d20a;
if (curSeq->spellPktBody.caster || curSeq->spellPktBody.spellEnum)
return 1;
return TRUE;

unsigned spellEnum, spellEnumOrg, spellClassCode, spellSlotLevel, itemSpellData, spellMetaMagicData;
D20SpellDataExtractInfo(&d20a->d20SpellData, &spellEnum, &spellEnumOrg, &spellClassCode, &spellSlotLevel, &itemSpellData, &spellMetaMagicData);
spellSys.spellPacketBodyReset(&curSeq->spellPktBody);
Expand All @@ -1134,7 +1145,9 @@ int LegacyD20System::TargetCheck(D20Actn* d20a)
spellSys.SpellPacketSetCasterLevel(&curSeq->spellPktBody);
else
curSeq->spellPktBody.casterLevel = max(1, 2 * static_cast<int>(spellSlotLevel) - 1);

curSeq->spellPktBody.spellRange = spellSys.GetSpellRange(&spellEntry, curSeq->spellPktBody.casterLevel, curSeq->spellPktBody.caster);

if ((spellEntry.modeTargetSemiBitmask & 0xFF) != static_cast<unsigned>(UiPickerType::Personal)
|| spellEntry.radiusTarget < 0
|| (spellEntry.flagsTargetBitmask & UiPickerFlagsTarget::Radius))
Expand Down Expand Up @@ -1545,6 +1558,54 @@ ActionErrorCode D20ActionCallbacks::PerformQuiveringPalm(D20Actn* d20a){

}

ActionErrorCode D20ActionCallbacks::PerformSneak(D20Actn* d20a){
auto performer = d20a->d20APerformer;

auto newSneakState = 1 - critterSys.IsMovingSilently(performer);
animationGoals.Interrupt(performer, AnimGoalPriority::AGP_5);

if (newSneakState && combatSys.isCombatActive()){ // entering sneak while in combat

auto hasHideInPlainSight = d20Sys.D20QueryPython(performer, "Can Hide In Plain Sight");

auto N = combatSys.GetInitiativeListLength();

BonusList sneakerBon;
sneakerBon.AddBonus(-20, 0, 349); // Hiding in Combat
auto sneakerHide = dispatch.dispatch1ESkillLevel(performer, SkillEnum::skill_hide, &sneakerBon, performer, 1);
auto hideRoll = Dice(1, 20, 0).Roll();

for (auto i = 0; i < N; i++){
auto combatant = combatSys.GetInitiativeListMember(i);
if (!combatant || combatant == performer)
continue;

if (critterSys.IsFriendly(combatant, performer) || critterSys.AllegianceShared(combatant, performer))
continue;

if (critterSys.HasLineOfSight(combatant, performer) == 0) { // note: the function actually returns obstacles

if (!hasHideInPlainSight)
return AEC_INVALID_ACTION;

BonusList spotterBon;
auto combatantSpot = dispatch.dispatch1ESkillLevel(combatant, SkillEnum::skill_spot, &spotterBon, combatant, 1);
auto spotRoll = Dice(1, 20, 0).Roll();
if (combatantSpot + spotRoll > hideRoll + sneakerHide){
auto rollHistId = histSys.RollHistoryAddType6OpposedCheck(performer, combatant, hideRoll, spotRoll, &sneakerBon, &spotterBon, 5123, 103, 1);
histSys.CreateRollHistoryString(rollHistId);
return AEC_INVALID_ACTION;
}

}

}
}

critterSys.SetMovingSilently(performer, newSneakState);
return AEC_OK;
}

ActionErrorCode D20ActionCallbacks::ActionFrameQuiveringPalm(D20Actn* d20a){

objHndl performer = d20a->d20APerformer;
Expand Down Expand Up @@ -1657,6 +1718,13 @@ ActionErrorCode D20ActionCallbacks::ActionCheckQuiveringPalm(D20Actn* d20a, Turn
return AEC_OK;
}

ActionErrorCode D20ActionCallbacks::ActionCheckSneak(D20Actn* d20a, TurnBasedStatus* tbStat){
if (critterSys.IsMovingSilently(d20a->d20APerformer)) // will cause to stop sneaking
return AEC_OK;

return AEC_OK; // used to be possible only outside of combat, but now you can attempt it in combat too
}

ActionErrorCode D20ActionCallbacks::PerformCharge(D20Actn* d20a){

int crit = 0, isSecondary = 0;
Expand Down
2 changes: 1 addition & 1 deletion TemplePlus/d20.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ enum D20ADF : int{
D20ADF_TargetContainer = 0x10000,
D20ADF_SimulsCompatible = 0x20000,
D20ADF_DrawPathByDefault = 0x40000, // will draw path even without holding ALT
D20ADF_PathSthg = 0x80000,
D20ADF_DoLocationCheckAtDestination = 0x80000,
D20ADF_Breaks_Concentration = 0x100000,

D20ADF_Python = 0x1000000
Expand Down
Loading

0 comments on commit 50ffaab

Please sign in to comment.