2015-01-05 18:52:37 +01:00
|
|
|
#include "summoning.hpp"
|
|
|
|
|
2018-08-14 23:05:43 +04:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2022-10-18 09:26:55 +02:00
|
|
|
#include <components/esm/refid.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadmgef.hpp>
|
|
|
|
#include <components/esm3/loadstat.hpp>
|
2022-06-29 00:32:11 +02:00
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
2015-12-18 02:58:38 +01:00
|
|
|
|
2015-01-05 18:52:37 +01:00
|
|
|
#include "../mwbase/environment.hpp"
|
2016-06-12 02:43:33 +02:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2015-01-05 18:52:37 +01:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
#include "../mwworld/manualref.hpp"
|
|
|
|
|
2015-05-30 01:00:24 +02:00
|
|
|
#include "../mwrender/animation.hpp"
|
2015-01-05 18:52:37 +01:00
|
|
|
|
|
|
|
#include "aifollow.hpp"
|
|
|
|
#include "creaturestats.hpp"
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
|
2020-04-04 17:45:03 +03:00
|
|
|
bool isSummoningEffect(int effectId)
|
|
|
|
{
|
|
|
|
return ((effectId >= ESM::MagicEffect::SummonScamp && effectId <= ESM::MagicEffect::SummonStormAtronach)
|
|
|
|
|| (effectId == ESM::MagicEffect::SummonCenturionSphere)
|
|
|
|
|| (effectId >= ESM::MagicEffect::SummonFabricant && effectId <= ESM::MagicEffect::SummonCreature05));
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:09:30 +01:00
|
|
|
static const std::map<int, ESM::RefId>& getSummonMap()
|
2015-01-05 18:52:37 +01:00
|
|
|
{
|
2022-12-01 22:09:30 +01:00
|
|
|
static std::map<int, ESM::RefId> summonMap;
|
|
|
|
|
|
|
|
if (summonMap.size() > 0)
|
|
|
|
return summonMap;
|
|
|
|
|
|
|
|
const std::map<int, std::string_view> summonMapToGameSetting{
|
2020-04-04 16:27:00 +03:00
|
|
|
{ ESM::MagicEffect::SummonAncestralGhost, "sMagicAncestralGhostID" },
|
|
|
|
{ ESM::MagicEffect::SummonBonelord, "sMagicBonelordID" },
|
|
|
|
{ ESM::MagicEffect::SummonBonewalker, "sMagicLeastBonewalkerID" },
|
|
|
|
{ ESM::MagicEffect::SummonCenturionSphere, "sMagicCenturionSphereID" },
|
|
|
|
{ ESM::MagicEffect::SummonClannfear, "sMagicClannfearID" },
|
|
|
|
{ ESM::MagicEffect::SummonDaedroth, "sMagicDaedrothID" },
|
|
|
|
{ ESM::MagicEffect::SummonDremora, "sMagicDremoraID" },
|
|
|
|
{ ESM::MagicEffect::SummonFabricant, "sMagicFabricantID" },
|
|
|
|
{ ESM::MagicEffect::SummonFlameAtronach, "sMagicFlameAtronachID" },
|
|
|
|
{ ESM::MagicEffect::SummonFrostAtronach, "sMagicFrostAtronachID" },
|
|
|
|
{ ESM::MagicEffect::SummonGoldenSaint, "sMagicGoldenSaintID" },
|
|
|
|
{ ESM::MagicEffect::SummonGreaterBonewalker, "sMagicGreaterBonewalkerID" },
|
|
|
|
{ ESM::MagicEffect::SummonHunger, "sMagicHungerID" },
|
|
|
|
{ ESM::MagicEffect::SummonScamp, "sMagicScampID" },
|
|
|
|
{ ESM::MagicEffect::SummonSkeletalMinion, "sMagicSkeletalMinionID" },
|
|
|
|
{ ESM::MagicEffect::SummonStormAtronach, "sMagicStormAtronachID" },
|
|
|
|
{ ESM::MagicEffect::SummonWingedTwilight, "sMagicWingedTwilightID" },
|
|
|
|
{ ESM::MagicEffect::SummonWolf, "sMagicCreature01ID" },
|
|
|
|
{ ESM::MagicEffect::SummonBear, "sMagicCreature02ID" },
|
|
|
|
{ ESM::MagicEffect::SummonBonewolf, "sMagicCreature03ID" },
|
|
|
|
{ ESM::MagicEffect::SummonCreature04, "sMagicCreature04ID" },
|
2022-09-14 00:08:19 +02:00
|
|
|
{ ESM::MagicEffect::SummonCreature05, "sMagicCreature05ID" },
|
2020-04-04 16:27:00 +03:00
|
|
|
};
|
2015-01-05 18:52:37 +01:00
|
|
|
|
2022-12-01 22:09:30 +01:00
|
|
|
for (const auto& it : summonMapToGameSetting)
|
|
|
|
{
|
2023-04-20 21:07:53 +02:00
|
|
|
summonMap[it.first] = ESM::RefId::stringRefId(
|
|
|
|
MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>().find(it.second)->mValue.getString());
|
2022-12-01 22:09:30 +01:00
|
|
|
}
|
|
|
|
return summonMap;
|
|
|
|
}
|
|
|
|
|
2023-02-20 23:18:05 +01:00
|
|
|
ESM::RefId getSummonedCreature(int effectId)
|
2022-12-01 22:09:30 +01:00
|
|
|
{
|
|
|
|
const auto& summonMap = getSummonMap();
|
2020-04-04 16:27:00 +03:00
|
|
|
auto it = summonMap.find(effectId);
|
|
|
|
if (it != summonMap.end())
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
{
|
2022-12-01 22:09:30 +01:00
|
|
|
return it->second;
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
}
|
2023-02-20 23:18:05 +01:00
|
|
|
return ESM::RefId();
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
int summonCreature(int effectId, const MWWorld::Ptr& summoner)
|
2015-02-16 16:41:53 +11:00
|
|
|
{
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
const ESM::RefId& creatureID = getSummonedCreature(effectId);
|
2021-08-27 20:07:50 +02:00
|
|
|
int creatureActorId = -1;
|
|
|
|
if (!creatureID.empty())
|
2015-01-05 18:52:37 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
auto world = MWBase::Environment::get().getWorld();
|
|
|
|
MWWorld::ManualRef ref(world->getStore(), creatureID, 1);
|
2015-01-05 18:52:37 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
MWMechanics::CreatureStats& summonedCreatureStats
|
|
|
|
= ref.getPtr().getClass().getCreatureStats(ref.getPtr());
|
2015-01-05 18:52:37 +01:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
// Make the summoned creature follow its master and help in fights
|
|
|
|
AiFollow package(summoner);
|
|
|
|
summonedCreatureStats.getAiSequence().stack(package, ref.getPtr());
|
|
|
|
creatureActorId = summonedCreatureStats.getActorId();
|
|
|
|
|
|
|
|
MWWorld::Ptr placed = world->safePlaceObject(ref.getPtr(), summoner, summoner.getCell(), 0, 120.f);
|
|
|
|
|
|
|
|
MWRender::Animation* anim = world->getAnimation(placed);
|
|
|
|
if (anim)
|
2015-01-05 18:52:37 +01:00
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
const ESM::Static* fx
|
|
|
|
= world->getStore().get<ESM::Static>().search(ESM::RefId::stringRefId("VFX_Summon_Start"));
|
2021-08-27 20:07:50 +02:00
|
|
|
if (fx)
|
2022-06-29 00:32:11 +02:00
|
|
|
{
|
|
|
|
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
|
|
|
anim->addEffect(Misc::ResourceHelpers::correctMeshPath(fx->mModel, vfs), -1, false);
|
|
|
|
}
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
catch (std::exception& e)
|
2015-01-05 18:52:37 +01:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
Log(Debug::Error) << "Failed to spawn summoned creature: " << e.what();
|
|
|
|
// still insert into creatureMap so we don't try to spawn again every frame, that would spam the warning
|
|
|
|
// log
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
summoner.getClass().getCreatureStats(summoner).getSummonedCreatureMap().emplace(effectId, creatureActorId);
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
return creatureActorId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateSummons(const MWWorld::Ptr& summoner, bool cleanup)
|
|
|
|
{
|
|
|
|
MWMechanics::CreatureStats& creatureStats = summoner.getClass().getCreatureStats(summoner);
|
|
|
|
auto& creatureMap = creatureStats.getSummonedCreatureMap();
|
2015-01-05 18:52:37 +01:00
|
|
|
|
2019-11-12 17:50:06 +03:00
|
|
|
std::vector<int> graveyard = creatureStats.getSummonedCreatureGraveyard();
|
|
|
|
creatureStats.getSummonedCreatureGraveyard().clear();
|
2015-01-05 18:52:37 +01:00
|
|
|
|
2019-11-12 17:50:06 +03:00
|
|
|
for (const int creature : graveyard)
|
2021-08-27 20:07:50 +02:00
|
|
|
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(summoner, creature);
|
2017-08-18 11:58:28 +04:00
|
|
|
|
|
|
|
if (!cleanup)
|
|
|
|
return;
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
for (auto it = creatureMap.begin(); it != creatureMap.end();)
|
2017-08-18 11:58:28 +04:00
|
|
|
{
|
2021-03-22 20:43:34 +01:00
|
|
|
if (it->second == -1)
|
|
|
|
{
|
|
|
|
// Keep the spell effect active if we failed to spawn anything
|
|
|
|
it++;
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-18 11:58:28 +04:00
|
|
|
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(it->second);
|
2021-06-02 20:33:29 +02:00
|
|
|
if (!ptr.isEmpty() && ptr.getClass().getCreatureStats(ptr).isDead()
|
|
|
|
&& ptr.getClass().getCreatureStats(ptr).isDeathAnimationFinished())
|
2017-08-18 11:58:28 +04:00
|
|
|
{
|
|
|
|
// Purge the magic effect so a new creature can be summoned if desired
|
2021-08-28 11:06:47 +02:00
|
|
|
auto summon = *it;
|
2017-08-18 11:58:28 +04:00
|
|
|
creatureMap.erase(it++);
|
2021-08-28 11:06:47 +02:00
|
|
|
purgeSummonEffect(summoner, summon);
|
2017-08-18 11:58:28 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
void purgeSummonEffect(const MWWorld::Ptr& summoner, const std::pair<int, int>& summon)
|
2021-06-06 12:45:42 +02:00
|
|
|
{
|
|
|
|
auto& creatureStats = summoner.getClass().getCreatureStats(summoner);
|
2021-08-27 20:07:50 +02:00
|
|
|
creatureStats.getActiveSpells().purge(
|
|
|
|
[summon](const auto& spell, const auto& effect) {
|
|
|
|
return effect.mEffectId == summon.first && effect.mArg == summon.second;
|
|
|
|
},
|
|
|
|
summoner);
|
2021-06-06 12:45:42 +02:00
|
|
|
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(summoner, summon.second);
|
|
|
|
}
|
2015-01-05 18:52:37 +01:00
|
|
|
}
|