diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 086d89c4e..cf1fb884a 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -68,27 +68,56 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid) LOG_APPEND(Log::LOG_INFO, "- Setting up character info"); MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); - ESM::NPC npc = *player.get()->mBase; DedicatedPlayer *dedicPlayer = players[guid]; - // To avoid freezes caused by invalid races, only set race if we find it - // on our client - if (world->getStore().get().search(dedicPlayer->npc.mRace) != 0) - npc.mRace = dedicPlayer->npc.mRace; + ESM::Creature creature; + ESM::NPC npc; + if (!dedicPlayer->creatureModel.empty()) + { + const ESM::Creature *tmpCreature = world->getStore().get().search(dedicPlayer->creatureModel); + if(tmpCreature == 0) + { + dedicPlayer->creatureModel = ""; + createPlayer(guid); + return; + } + creature = *tmpCreature; + creature.mScript = ""; + if(!dedicPlayer->useCreatureName) + creature.mName = dedicPlayer->npc.mName; + } + else + { + MWWorld::Ptr player = world->getPlayerPtr(); - npc.mHead = dedicPlayer->npc.mHead; - npc.mHair = dedicPlayer->npc.mHair; - npc.mClass = dedicPlayer->npc.mClass; - npc.mName = dedicPlayer->npc.mName; - npc.mFlags = dedicPlayer->npc.mFlags; + npc = *player.get()->mBase; + + // To avoid freezes caused by invalid races, only set race if we find it + // on our client + if (world->getStore().get().search(dedicPlayer->npc.mRace) != 0) + npc.mRace = dedicPlayer->npc.mRace; + + npc.mHead = dedicPlayer->npc.mHead; + npc.mHair = dedicPlayer->npc.mHair; + npc.mClass = dedicPlayer->npc.mClass; + npc.mName = dedicPlayer->npc.mName; + npc.mFlags = dedicPlayer->npc.mFlags; + } if (dedicPlayer->state == 0) { - npc.mId = "Dedicated Player"; - - std::string recid = world->createRecord(npc)->mId; + string recid; + if (!dedicPlayer->creatureModel.empty()) + { + creature.mId = "Dedicated Player"; + recid = world->createRecord(npc)->mId; + } + else + { + npc.mId = "Dedicated Player"; + recid = world->createRecord(creature)->mId; + } dedicPlayer->reference = new MWWorld::ManualRef(world->getStore(), recid, 1); } @@ -115,12 +144,21 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid) { LOG_APPEND(Log::LOG_INFO, "- Updating reference pointer for %s", dedicPlayer->npc.mName.c_str()); - npc.mId = players[guid]->ptr.get()->mBase->mId; - MWWorld::ESMStore *store = const_cast(&world->getStore()); - MWWorld::Store *esm_store = const_cast *> (&store->get()); - esm_store->insert(npc); + if (!dedicPlayer->creatureModel.empty()) + { + creature.mId = players[guid]->ptr.get()->mBase->mId; + MWWorld::Store *esm_store = const_cast *> (&store->get()); + esm_store->insert(creature); + + } + else + { + npc.mId = players[guid]->ptr.get()->mBase->mId; + MWWorld::Store *esm_store = const_cast *> (&store->get()); + esm_store->insert(npc); + } // Disable Ptr to avoid graphical glitches caused by race changes world->disable(players[guid]->ptr); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 6c35e47d1..4a8923a8a 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -138,6 +138,7 @@ namespace mwmp inventoryChanges.count = 0; spellbookChanges.action = 0; spellbookChanges.count = 0; + useCreatureName = false; } BasePlayer() @@ -179,6 +180,8 @@ namespace mwmp std::string chatMessage; CGStage charGenStage; std::string passw; + std::string creatureModel; + bool useCreatureName; }; }