Skip to content

Commit

Permalink
Externals: Moved Mdl_*-Externals as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ataulien committed Jul 1, 2018
1 parent 7c9e92d commit 5faf297
Showing 1 changed file with 0 additions and 132 deletions.
132 changes: 0 additions & 132 deletions src/logic/scriptExternals/Externals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,113 +73,6 @@ void ::Logic::ScriptExternals::registerEngineExternals(World::WorldInstance& wor

};

auto getItemByInstance = [vm, engine](size_t instance) {
auto& parSymbol = vm->getDATFile().getSymbolByIndex(instance);
Daedalus::GameState::ItemHandle hitem = ZMemory::handleCast<Daedalus::GameState::ItemHandle>(parSymbol.instanceDataHandle);

if (hitem.isValid())
{
// Get data of npc this belongs to
Daedalus::GEngineClasses::C_Item& itemData = vm->getGameState().getItem(hitem);
VobTypes::ScriptInstanceUserData* userData = reinterpret_cast<VobTypes::ScriptInstanceUserData*>(itemData.userPtr);

if (userData)
{
World::WorldInstance& world = engine->getWorldInstance(userData->world);
Vob::VobInformation vob = Vob::asVob(world, userData->vobEntity);

return vob;
}
else
{
LogWarn() << "No userptr on item: " << itemData.name;
}
}
else
{
LogWarn() << "could not get item handle from ParSymbol: " << parSymbol.name;
}
Vob::VobInformation vob;
vob.entity.invalidate();
return vob;
};

/**
* Mdl_SetVisual
*/
vm->registerExternalFunction("Mdl_SetVisual", [=](Daedalus::DaedalusVM& vm) {
std::string visual = vm.popString();

uint32_t arr_self;
int32_t self = vm.popVar(arr_self);
if (verbose) LogInfo() << "self: " << self;

// TODO: Need a better API for this
NpcHandle hnpc = ZMemory::handleCast<NpcHandle>(vm.getDATFile().getSymbolByIndex(self).instanceDataHandle);
Daedalus::GEngineClasses::C_Npc& npcData = vm.getGameState().getNpc(hnpc);

if (npcData.userPtr && vm.getDATFile().getSymbolByIndex(self).instanceDataHandle.isValid())
{
VobTypes::ScriptInstanceUserData* userData = reinterpret_cast<VobTypes::ScriptInstanceUserData*>(npcData.userPtr);

//LogInfo() << "Setting MDL visual to: " << visual;

World::WorldInstance& world = engine->getWorldInstance(userData->world);
VobTypes::NpcVobInformation vob = VobTypes::asNpcVob(world, userData->vobEntity);
VobTypes::NPC_SetModelVisual(vob, visual);
}
});

/**
* Mdl_SetVisualBody
*/
vm->registerExternalFunction("Mdl_SetVisualBody", [=](Daedalus::DaedalusVM& vm) {

int32_t armorInstance = vm.popDataValue();
int teethTexNr = static_cast<int>(vm.popDataValue());
int headTexNr = static_cast<int>(vm.popDataValue());
std::string head = vm.popString();
int32_t bodyTexColor = vm.popDataValue();
int32_t bodyTexNr = vm.popDataValue();
std::string body = vm.popString();

uint32_t arr_self;
int32_t self = vm.popVar(arr_self);
if (verbose) LogInfo() << "self: " << self;

// TODO: Need a better API for this
NpcHandle hnpc = ZMemory::handleCast<NpcHandle>(vm.getDATFile().getSymbolByIndex(self).instanceDataHandle);
Daedalus::GEngineClasses::C_Npc& npcData = vm.getGameState().getNpc(hnpc);

//LogInfo() << "Self hdl idx:" << vm.getDATFile().getSymbolByIndex(self).instanceDataHandle.index << ", Valid: " << vm.getDATFile().getSymbolByIndex(self).instanceDataHandle.isValid();
//LogInfo() << " - Userdata: " << npcData.userPtr;

// TODO: Implement the other visuals
if (npcData.userPtr && vm.getDATFile().getSymbolByIndex(self).instanceDataHandle.isValid())
{
VobTypes::ScriptInstanceUserData* userData = reinterpret_cast<VobTypes::ScriptInstanceUserData*>(npcData.userPtr);

if (verbose) LogInfo() << "Setting visual to: " << body;

World::WorldInstance& world = engine->getWorldInstance(userData->world);
VobTypes::NpcVobInformation vob = VobTypes::asNpcVob(world, userData->vobEntity);

// Set main visual
VobTypes::NPC_SetBodyMesh(vob, body, bodyTexNr, bodyTexColor);

// Set head-mesh
VobTypes::NPC_SetHeadMesh(vob, head, headTexNr, teethTexNr);
}

// TODO: Wrap this up
// Set armor visual
if (armorInstance != -1)
{
// TODO: Right now, this equips the item automatically. When this is done properly, call the equip-method here
vm.getGameState().createInventoryItem(static_cast<size_t>(armorInstance), hnpc);
}
});

/**
* ta_min
*/
Expand Down Expand Up @@ -290,31 +183,6 @@ void ::Logic::ScriptExternals::registerEngineExternals(World::WorldInstance& wor
vm.setReturn(pWorld->getDialogManager().isDialogActive() ? 0 : 1);
});

vm->registerExternalFunction("mdl_applyoverlaymds", [=](Daedalus::DaedalusVM& vm) {
std::string overlayname = vm.popString();
uint32_t self = vm.popVar();

VobTypes::NpcVobInformation npc = getNPCByInstance(self);

if (npc.isValid())
{
npc.playerController->getModelVisual()->applyOverlay(overlayname);
}
});

vm->registerExternalFunction("mdl_removeoverlaymds", [=](Daedalus::DaedalusVM& vm) {
std::string overlayname = vm.popString();
uint32_t self = vm.popVar();

VobTypes::NpcVobInformation npc = getNPCByInstance(self);

if (npc.isValid())
{
// TODO: Implement using of multiple overlays!
npc.playerController->getModelVisual()->applyOverlay("");
}
});


vm->registerExternalFunction("info_addchoice", [=](Daedalus::DaedalusVM& vm) {
uint32_t func = vm.popVar();
Expand Down

0 comments on commit 5faf297

Please sign in to comment.