2017-04-09 13:32:44 +00:00
|
|
|
#include "ActorList.hpp"
|
|
|
|
#include "Main.hpp"
|
|
|
|
#include "Networking.hpp"
|
|
|
|
#include "LocalPlayer.hpp"
|
2018-07-13 22:00:27 +00:00
|
|
|
#include "MechanicsHelper.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
2017-04-09 13:32:44 +00:00
|
|
|
|
2019-08-19 18:39:33 +00:00
|
|
|
#include <components/openmw-mp/TimedLog.hpp>
|
2017-04-09 13:32:44 +00:00
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
|
|
|
ActorList::ActorList()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ActorList::~ActorList()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Networking *ActorList::getNetworking()
|
|
|
|
{
|
|
|
|
return mwmp::Main::get().getNetworking();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActorList::reset()
|
|
|
|
{
|
|
|
|
cell.blank();
|
|
|
|
baseActors.clear();
|
2017-04-10 14:10:18 +00:00
|
|
|
positionActors.clear();
|
2017-04-15 08:45:20 +00:00
|
|
|
animFlagsActors.clear();
|
2017-04-15 10:42:30 +00:00
|
|
|
animPlayActors.clear();
|
2017-04-16 15:43:13 +00:00
|
|
|
speechActors.clear();
|
2017-04-16 13:42:07 +00:00
|
|
|
statsDynamicActors.clear();
|
2018-06-27 18:47:55 +00:00
|
|
|
deathActors.clear();
|
2017-05-26 01:37:49 +00:00
|
|
|
equipmentActors.clear();
|
2018-08-20 17:54:34 +00:00
|
|
|
aiActors.clear();
|
2017-04-19 19:10:06 +00:00
|
|
|
attackActors.clear();
|
2019-08-25 06:35:23 +00:00
|
|
|
castActors.clear();
|
2017-04-23 10:59:15 +00:00
|
|
|
cellChangeActors.clear();
|
2017-04-09 13:32:44 +00:00
|
|
|
guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActorList::addActor(BaseActor baseActor)
|
|
|
|
{
|
|
|
|
baseActors.push_back(baseActor);
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addPositionActor(BaseActor baseActor)
|
2017-04-09 13:32:44 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
positionActors.push_back(baseActor);
|
2017-04-09 13:32:44 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addAnimFlagsActor(BaseActor baseActor)
|
2017-04-10 14:10:18 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
animFlagsActors.push_back(baseActor);
|
2017-04-10 14:10:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addAnimPlayActor(BaseActor baseActor)
|
2017-04-13 12:26:48 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
animPlayActors.push_back(baseActor);
|
2017-04-13 12:26:48 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addSpeechActor(BaseActor baseActor)
|
2017-04-15 10:42:30 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
speechActors.push_back(baseActor);
|
2017-04-15 10:42:30 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addStatsDynamicActor(BaseActor baseActor)
|
2017-04-16 15:43:13 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
statsDynamicActors.push_back(baseActor);
|
2017-04-16 15:43:13 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addDeathActor(BaseActor baseActor)
|
2017-04-16 13:42:07 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
deathActors.push_back(baseActor);
|
2017-04-16 13:42:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addEquipmentActor(BaseActor baseActor)
|
2018-06-27 18:47:55 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
equipmentActors.push_back(baseActor);
|
2018-06-27 18:47:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 17:48:47 +00:00
|
|
|
void ActorList::addAiActor(BaseActor baseActor)
|
|
|
|
{
|
|
|
|
aiActors.push_back(baseActor);
|
|
|
|
}
|
|
|
|
|
2018-07-13 22:00:27 +00:00
|
|
|
void ActorList::addAiActor(const MWWorld::Ptr& actorPtr, const MWWorld::Ptr& targetPtr, unsigned int aiAction)
|
|
|
|
{
|
|
|
|
mwmp::BaseActor baseActor;
|
|
|
|
baseActor.refNum = actorPtr.getCellRef().getRefNum().mIndex;
|
|
|
|
baseActor.mpNum = actorPtr.getCellRef().getMpNum();
|
|
|
|
baseActor.aiAction = aiAction;
|
|
|
|
baseActor.aiTarget = MechanicsHelper::getTarget(targetPtr);
|
|
|
|
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Preparing to send ID_ACTOR_AI about %s %i-%i\n- action: %i",
|
2018-07-13 22:00:27 +00:00
|
|
|
actorPtr.getCellRef().getRefId().c_str(), baseActor.refNum, baseActor.mpNum, aiAction);
|
|
|
|
|
|
|
|
if (baseActor.aiTarget.isPlayer)
|
|
|
|
{
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "- Has player target %s",
|
2018-07-13 22:00:27 +00:00
|
|
|
targetPtr.getClass().getName(targetPtr).c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "- Has actor target %s %i-%i",
|
2018-07-13 22:00:27 +00:00
|
|
|
targetPtr.getCellRef().getRefId().c_str(), baseActor.aiTarget.refNum, baseActor.aiTarget.mpNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
addAiActor(baseActor);
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addAttackActor(BaseActor baseActor)
|
2017-05-26 01:37:49 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
attackActors.push_back(baseActor);
|
2017-05-26 01:37:49 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 13:50:05 +00:00
|
|
|
void ActorList::addAttackActor(const MWWorld::Ptr& actorPtr, const mwmp::Attack &attack)
|
|
|
|
{
|
|
|
|
mwmp::BaseActor baseActor;
|
|
|
|
baseActor.refNum = actorPtr.getCellRef().getRefNum().mIndex;
|
|
|
|
baseActor.mpNum = actorPtr.getCellRef().getMpNum();
|
|
|
|
baseActor.attack = attack;
|
|
|
|
attackActors.push_back(baseActor);
|
|
|
|
}
|
|
|
|
|
2019-08-25 06:35:23 +00:00
|
|
|
void ActorList::addCastActor(BaseActor baseActor)
|
|
|
|
{
|
|
|
|
castActors.push_back(baseActor);
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:15:04 +00:00
|
|
|
void ActorList::addCellChangeActor(BaseActor baseActor)
|
2017-04-19 19:10:06 +00:00
|
|
|
{
|
2018-07-12 17:15:04 +00:00
|
|
|
cellChangeActors.push_back(baseActor);
|
2017-04-23 10:59:15 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 14:10:18 +00:00
|
|
|
void ActorList::sendPositionActors()
|
|
|
|
{
|
2017-04-13 15:59:22 +00:00
|
|
|
if (positionActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = positionActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_POSITION)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_POSITION)->Send();
|
|
|
|
}
|
2017-04-10 14:10:18 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 08:45:20 +00:00
|
|
|
void ActorList::sendAnimFlagsActors()
|
2017-04-13 12:26:48 +00:00
|
|
|
{
|
2017-04-15 08:45:20 +00:00
|
|
|
if (animFlagsActors.size() > 0)
|
2017-04-13 15:59:22 +00:00
|
|
|
{
|
2017-04-15 08:45:20 +00:00
|
|
|
baseActors = animFlagsActors;
|
2017-04-14 13:00:34 +00:00
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_FLAGS)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_FLAGS)->Send();
|
2017-04-13 15:59:22 +00:00
|
|
|
}
|
2017-04-13 12:26:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 10:42:30 +00:00
|
|
|
void ActorList::sendAnimPlayActors()
|
|
|
|
{
|
|
|
|
if (animPlayActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = animPlayActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_PLAY)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_PLAY)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-16 15:43:13 +00:00
|
|
|
void ActorList::sendSpeechActors()
|
|
|
|
{
|
|
|
|
if (speechActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = speechActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_SPEECH)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_SPEECH)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-16 13:42:07 +00:00
|
|
|
void ActorList::sendStatsDynamicActors()
|
|
|
|
{
|
|
|
|
if (statsDynamicActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = statsDynamicActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_STATS_DYNAMIC)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_STATS_DYNAMIC)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-27 18:47:55 +00:00
|
|
|
void ActorList::sendDeathActors()
|
|
|
|
{
|
|
|
|
if (deathActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = deathActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_DEATH)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_DEATH)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 01:37:49 +00:00
|
|
|
void ActorList::sendEquipmentActors()
|
|
|
|
{
|
|
|
|
if (equipmentActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = equipmentActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_EQUIPMENT)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_EQUIPMENT)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:48:47 +00:00
|
|
|
void ActorList::sendAiActors()
|
|
|
|
{
|
|
|
|
if (aiActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = aiActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_AI)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_AI)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 19:10:06 +00:00
|
|
|
void ActorList::sendAttackActors()
|
|
|
|
{
|
|
|
|
if (attackActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = attackActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ATTACK)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_ATTACK)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 06:35:23 +00:00
|
|
|
void ActorList::sendCastActors()
|
|
|
|
{
|
|
|
|
if (castActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = castActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CAST)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CAST)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 10:59:15 +00:00
|
|
|
void ActorList::sendCellChangeActors()
|
|
|
|
{
|
|
|
|
if (cellChangeActors.size() > 0)
|
|
|
|
{
|
|
|
|
baseActors = cellChangeActors;
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CELL_CHANGE)->setActorList(this);
|
|
|
|
Main::get().getNetworking()->getActorPacket(ID_ACTOR_CELL_CHANGE)->Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 14:10:18 +00:00
|
|
|
void ActorList::sendActorsInCell(MWWorld::CellStore* cellStore)
|
2017-04-09 13:32:44 +00:00
|
|
|
{
|
|
|
|
reset();
|
|
|
|
cell = *cellStore->getCell();
|
|
|
|
action = BaseActorList::SET;
|
|
|
|
|
2017-06-27 14:27:02 +00:00
|
|
|
for (auto &ref : cellStore->getNpcs()->mList)
|
2017-04-09 13:32:44 +00:00
|
|
|
{
|
2017-06-27 13:56:14 +00:00
|
|
|
MWWorld::Ptr ptr(&ref, 0);
|
2017-04-09 13:32:44 +00:00
|
|
|
|
2017-04-28 20:17:23 +00:00
|
|
|
// If this Ptr is lacking a unique index, ignore it
|
|
|
|
if (ptr.getCellRef().getRefNum().mIndex == 0 && ptr.getCellRef().getMpNum() == 0) continue;
|
|
|
|
|
2017-04-09 13:32:44 +00:00
|
|
|
BaseActor actor;
|
|
|
|
actor.refId = ptr.getCellRef().getRefId();
|
2018-07-13 01:12:03 +00:00
|
|
|
actor.refNum = ptr.getCellRef().getRefNum().mIndex;
|
2017-04-09 13:32:44 +00:00
|
|
|
actor.mpNum = ptr.getCellRef().getMpNum();
|
|
|
|
|
|
|
|
addActor(actor);
|
|
|
|
}
|
|
|
|
|
2017-06-27 14:27:02 +00:00
|
|
|
for (auto &ref : cellStore->getCreatures()->mList)
|
2017-04-09 13:32:44 +00:00
|
|
|
{
|
2017-06-27 13:56:14 +00:00
|
|
|
MWWorld::Ptr ptr(&ref, 0);
|
2017-04-09 13:32:44 +00:00
|
|
|
|
2017-04-28 20:17:23 +00:00
|
|
|
// If this Ptr is lacking a unique index, ignore it
|
|
|
|
if (ptr.getCellRef().getRefNum().mIndex == 0 && ptr.getCellRef().getMpNum() == 0) continue;
|
|
|
|
|
2017-04-09 13:32:44 +00:00
|
|
|
BaseActor actor;
|
|
|
|
actor.refId = ptr.getCellRef().getRefId();
|
2018-07-13 01:12:03 +00:00
|
|
|
actor.refNum = ptr.getCellRef().getRefNum().mIndex;
|
2017-04-09 13:32:44 +00:00
|
|
|
actor.mpNum = ptr.getCellRef().getMpNum();
|
|
|
|
|
|
|
|
addActor(actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->setActorList(this);
|
|
|
|
mwmp::Main::get().getNetworking()->getActorPacket(ID_ACTOR_LIST)->Send();
|
|
|
|
}
|