Skip to content

Commit

Permalink
Merge pull request #405 from anatoliy-savchak/work
Browse files Browse the repository at this point in the history
dispatch_stat and create_history_dc_roll
  • Loading branch information
doug1234 authored Jul 5, 2020
2 parents 24b6a13 + 50da702 commit e090ed0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions TemplePlus/bonus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "bonus.h"
#include "tig/tig_mes.h"
#include "util/fixes.h"
#include <infrastructure/elfhash.h>

int(__cdecl *OrgBonusInit)();

Expand Down Expand Up @@ -195,6 +196,16 @@ uint32_t BonusSystem::bonusSetOverallCap(uint32_t bonFlags, BonusList* bonList,
return bonList->SetOverallCap(bonFlags, newCap, newCapType, bonMesLineNum, capDescr);
}

char* BonusSystem::CacheCustomText(std::string& text)
{
auto textId = ElfHash::Hash(text);
auto textCache = customBonusStrings.find(textId);
if (textCache == customBonusStrings.end()) {
bonusSys.customBonusStrings[textId] = text;
}
return (char*)customBonusStrings[textId].c_str();
}

BonusSystem::BonusSystem()
{
rebase(_bonusPrintString,0x100E6740);
Expand Down
2 changes: 2 additions & 0 deletions TemplePlus/bonus.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct BonusSystem : temple::AddressTable
void (__cdecl *_bonusPrintString)(BonusList *bonlist, uint32_t bonIdx, int32_t *bonValueOut, char *strBonusOut, char *strCapOut);
int32_t(__cdecl * _getOverallBonus)(BonusList* bonList);

char* CacheCustomText(std::string& text);

MesHandle * bonusMesHandle; //102E45A8
MesHandle bonusMesNew;
BonusSystem();
Expand Down
19 changes: 18 additions & 1 deletion TemplePlus/python/python_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "rng.h"
#include "float_line.h"
#include "history.h"
#include "bonus.h"

namespace py = pybind11;

Expand Down Expand Up @@ -165,6 +166,15 @@ PYBIND11_EMBEDDED_MODULE(tpdp, m) {
return skillLevel;
});

m.def("dispatch_stat", [](objHndl obj, uint32_t stat, BonusList& bonList)-> int {
DispIoBonusList evtObjAbScore;
evtObjAbScore.flags |= 1; // effect unknown??
evtObjAbScore.bonlist = bonList;
auto result = dispatch.Dispatch10AbilityScoreLevelGet(obj, (Stat)stat, &evtObjAbScore);
bonList = evtObjAbScore.bonlist;
return result;
});

m.def("create_history_type6_opposed_check", [](objHndl performer, objHndl defender, int performerRoll, int defenderRoll
, BonusList& performerBonList, BonusList& defenderBonList, uint32_t combatMesLineTitle, uint32_t combatMesLineResult, uint32_t flag)-> int
{
Expand All @@ -173,7 +183,14 @@ PYBIND11_EMBEDDED_MODULE(tpdp, m) {
return rollHistId;
});

#pragma region Basic Dispatcher stuff
m.def("create_history_dc_roll", [](objHndl performer, int dc, Dice& dice, int roll, std::string& text, BonusList& bonlist)-> int
{
auto ptext = bonusSys.CacheCustomText(text);
auto rollHistId = histSys.RollHistoryType4Add(performer, dc, ptext, dice.ToPacked(), roll, (BonusList*)&bonlist);
return rollHistId;
});

#pragma region Basic Dispatcher stuff

py::class_<CondStructNew>(m, "ModifierSpec")
.def(py::init())
Expand Down

0 comments on commit e090ed0

Please sign in to comment.