Merge pull request #406 from TES3MP/0.6.3 while resolving conflicts

Conflicts:
	apps/openmw-mp/Script/Functions/Mechanics.cpp
	apps/openmw-mp/Script/Functions/Mechanics.hpp
	components/openmw-mp/Base/BasePlayer.hpp
sol2-server-rewrite
David Cernat 7 years ago
commit ed15d9ebf5

@ -8,10 +8,10 @@ https://bugs.openmw.org/
Currently, we are focused on completing the MW game experience and general polishing. Features out of this scope may be approved in some cases, but you should probably start a discussion first.
Note:
- Tasks set to 'openmw-future' are usually out of the current scope of the project and can't be started yet.
- Bugs that are not 'Confirmed' should be confirmed first.
- Larger Features should have a discussion before you start implementing.
- In many cases, it's best to have a discussion about possible solutions before you jump into coding.
* Tasks set to 'openmw-future' are usually out of the current scope of the project and can't be started yet.
* Bugs that are not 'Confirmed' should be confirmed first.
* Larger Features should have a discussion before you start implementing.
* In many cases, it's best to have a discussion about possible solutions before you jump into coding.
Aside from coding, you can also help by triaging the issues list. Check for bugs that are 'Unconfirmed' and try to confirm them on your end, working out any details that may be necessary. Check for bugs that do not conform to [Bug reporting guidelines](https://wiki.openmw.org/index.php?title=Bug_Reporting_Guidelines) and improve them to do so!
@ -20,7 +20,7 @@ There are various [Tools](https://wiki.openmw.org/index.php?title=Tools) to faci
Pull Request Guidelines
=======================
Thought of a change? Great! To facilitate the review process, your pull request description should include the following (if applicable):
To facilitate the review process, your pull request description should include the following, if applicable:
* A link back to the bug report or forum discussion that prompted the change
* Summary of the changes made
@ -29,11 +29,12 @@ Thought of a change? Great! To facilitate the review process, your pull request
Furthermore, we advise to:
* Separate your work into multiple pull requests whenever possible. As a rule of thumb, each feature and each bugfix should go into a separate PR, unless they are closely related or dependent upon each other. Small pull requests are easier to review, and are less likely to require further changes before we can merge them. A "mega" pull request with lots of unrelated commits in it is likely to get held up in review for a long time.
* Avoid stuffing unrelated commits into one pull request. As a rule of thumb, each feature and each bugfix should go into a separate PR, unless they are closely related or dependent upon each other. Small pull requests are easier to review, and are less likely to require further changes before we can merge them. A "mega" pull request with lots of unrelated commits in it is likely to get held up in review for a long time.
* Feel free to submit incomplete pull requests. Even if the work can not be merged yet, pull requests are a great place to collect early feedback. Just make sure to mark it as *[Incomplete]* or *[Do not merge yet]* in the title.
* If you plan on contributing often, please read the [Developer Reference](https://wiki.openmw.org/index.php?title=Developer_Reference) on our wiki, especially the [Policies and Standards](https://wiki.openmw.org/index.php?title=Policies_and_Standards).
* Make sure each of your changes has a clear objective. Unnecessary changes may lead to merge conflicts, clutter the commit history and slow down review. Code formatting 'fixes' should be avoided, unless you were already changing that particular line anyway.
* Reference the bug / feature ticket(s) in your commit message (e.g. 'Bug #123') to make it easier to keep track of what we changed for what reason. Our bugtracker will show those commits next to the ticket. If your commit message includes 'Fixes #123', that bug/feature will automatically be set to 'Closed' when your commit is merged.
* When pulling changes from master, prefer rebase over merge. Consider using a merge if there are conflicts or for long-running PRs.
Guidelines for original engine "fixes"
=================================
@ -62,10 +63,50 @@ We get it, you have waited so long for feature XYZ to be available in Morrowind
Unfortunately, since maintaining features comes at a cost and our resources are limited, we have to be a little selective in what features we allow into the main repository. Generally:
- Features should be as generic and non-redundant as possible.
- Any feature that is also possible with modding should be done as a mod instead.
- In the future, OpenMW plans to expand the scope of what is possible with modding, e.g. by moving certain game logic into editable scripts.
- Currently, modders can edit OpenMW's GUI skins and layout XML files, although there are still a few missing hooks (e.g. scripting support) in order to make this into a powerful way of modding.
- If a feature introduces new game UI strings, that reduces its chance of being accepted because we do not currently have any way of localizing these to the user's Morrowind installation language.
* Features should be as generic and non-redundant as possible.
* Any feature that is also possible with modding should be done as a mod instead.
* In the future, OpenMW plans to expand the scope of what is possible with modding, e.g. by moving certain game logic into editable scripts.
* Currently, modders can edit OpenMW's GUI skins and layout XML files, although there are still a few missing hooks (e.g. scripting support) in order to make this into a powerful way of modding.
* If a feature introduces new game UI strings, that reduces its chance of being accepted because we do not currently have any way of localizing these to the user's Morrowind installation language.
If you are in doubt of your feature being within our scope, it is probably best to start a forum discussion first. See the [settings documentation](https://openmw.readthedocs.io/en/stable/reference/modding/settings/index.html) and [Features list](https://wiki.openmw.org/index.php?title=Features) for some examples of features that were deemed acceptable.
Reviewing pull requests
=======================
We welcome any help in reviewing open PRs. You don't need to be a developer to comment on new features. We also encourage ["junior" developers to review senior's work](https://pagefault.blog/2018/04/08/why-junior-devs-should-review-seniors-commits/).
This review process is divided into two sections because complaining about code or style issues hardly makes sense until the functionality of the PR is deemed OK. Anyone can help with the Functionality Review while most parts of the Code Review require you to have programming experience.
In addition to the checklist below, make sure to check that the Pull Request Guidelines (first half of this document) were followed.
First review
============
1. Ask for missing information or clarifications. Compare against the project's design goals and roadmap.
2. Check if the automated tests are passing. If they are not, make the PR author aware of the issue and potentially link to the error line on Travis CI or Appveyor. If the error appears unrelated to the PR and/or the master branch is failing with the same error, our CI has broken and needs to be fixed independently of any open PRs. Raise this issue on the forums, bug tracker or with the relevant maintainer. The PR can be merged in this case as long as you've built it yourself to make sure it does build.
3. Make sure that the new code has been tested thoroughly, either by asking the author or, preferably, testing yourself. In a complex project like OpenMW, it is easy to make mistakes, typos, etc. Therefore, prefer testing all code changes, no matter how trivial they look. When you have tested a PR that no one has tested so far, post a comment letting us know.
4. On long running PRs, request the author to update its description with the current state or a checklist of things left to do.
Code Review
===========
1. Carefully review each line for issues the author may not have thought of, paying special attention to 'special' cases. Often, people build their code with a particular mindset and forget about other configurations or unexpected interactions.
2. If any changes are workarounds for an issue in an upstream library, make sure the issue was reported upstream so we can eventually drop the workaround when the issue is fixed and the new version of that library is a build dependency.
3. Make sure PRs do not turn into arguments about hardly related issues. If the PR author disagrees with an established part of the project (e.g. supported build environments), they should open a forum discussion or bug report and in the meantime adjust the PR to adhere to the established way, rather than leaving the PR hanging on a dispute.
4. Check if the code matches our style guidelines.
5. Check to make sure the commit history is clean. Squashing should be considered if the review process has made the commit history particularly long. Commits that don't build should be avoided because they are a nuisance for ```git bisect```.
Merging
=======
To be able to merge PRs, commit priviledges are required. If you do not have the priviledges, just ping someone that does have them with a short comment like "Looks good to me @user".
The person to merge the PR may either use github's Merge button or if using the command line, use the ```--no-ff``` flag and include the pull request number in the commit description.
Other resources
===============
[GitHub blog - how to write the perfect pull request](https://blog.github.com/2015-01-21-how-to-write-the-perfect-pull-request/)

@ -98,7 +98,7 @@ add_openmw_dir (mwbase
)
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList WorldEvent
Cell CellController MechanicsHelper GUIController
Cell CellController MechanicsHelper RecordHelper GUIController
)
add_openmw_dir (mwmp/GUI GUIChat GUILogin PlayerMarkerCollection GUIDialogList TextInputDialog GUICustomWindow

@ -870,7 +870,16 @@ namespace MWMechanics
mUpdatePlayer = true;
mClassSelected = true;
mRaceSelected = true;
mAI = true;
/*
Start of tes3mp change (major)
Avoid enabling AI in multiplayer
*/
mAI = false;
/*
End of tes3mp change (major)
*/
}
bool MechanicsManager::isBoundItem(const MWWorld::Ptr& item)

@ -34,6 +34,7 @@
#include "GUIController.hpp"
#include "CellController.hpp"
#include "MechanicsHelper.hpp"
#include "RecordHelper.hpp"
using namespace mwmp;
@ -43,13 +44,23 @@ DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid)
{
reference = 0;
attack.pressed = 0;
creatureStats.mDead = false;
// Give this new character a temporary high fatigue so it doesn't spawn on
// the ground
creatureStats.mDynamic[2].mBase = 1000;
movementFlags = 0;
attack.instant = false;
cell.blank();
position.pos[0] = position.pos[1] = Main::get().getCellController()->getCellSize() / 2;
position.pos[2] = 0;
MWBase::World *world = MWBase::Environment::get().getWorld();
npc = *world->getPlayerPtr().get<ESM::NPC>()->mBase;
npc.mId = "Dedicated Player";
previousRace = npc.mRace;
}
DedicatedPlayer::~DedicatedPlayer()
{
@ -132,48 +143,94 @@ void DedicatedPlayer::move(float dt)
void DedicatedPlayer::setBaseInfo()
{
MWBase::World *world = MWBase::Environment::get().getWorld();
// Use the previous race if the new one doesn't exist
if (!RecordHelper::doesRaceExist(npc.mRace))
npc.mRace = previousRace;
if (reference)
if (!reference)
{
npc.mId = RecordHelper::createNpcRecord(npc);
createReference(npc.mId);
}
else
{
deleteReference();
RecordHelper::updateNpcRecord(npc);
reloadPtr();
}
std::string recId = getNpcRecordId();
createReference(recId);
// Only set equipment if the player isn't disguised as a creature
if (ptr.getTypeName() == typeid(ESM::NPC).name())
setEquipment();
// Give this new character a temporary high fatigue of at least 1 so it doesn't
// spawn on the ground
creatureStats.mDynamic[2].mBase = 1000;
previousRace = npc.mRace;
}
void DedicatedPlayer::setShapeshift()
{
MWBase::World *world = MWBase::Environment::get().getWorld();
bool isNpc = false;
if (reference)
isNpc = ptr.getTypeName() == typeid(ESM::NPC).name();
if (creatureRefId != previousCreatureRefId)
{
deleteReference();
}
if (!creatureRefId.empty() && RecordHelper::doesCreatureExist(creatureRefId))
{
if (isNpc)
{
deleteReference();
}
std::string recId;
const ESM::Creature *tmpCreature = world->getStore().get<ESM::Creature>().search(creatureRefId);
creature = *tmpCreature;
creature.mScript = "";
if (!displayCreatureName)
creature.mName = npc.mName;
LOG_APPEND(Log::LOG_INFO, "- %s is disguised as %s", npc.mName.c_str(), creatureRefId.c_str());
if (!creatureRefId.empty())
{
const ESM::Creature *tmpCreature = world->getStore().get<ESM::Creature>().search(creatureRefId);
if (tmpCreature != 0)
// Is this our first time creating a creature record id for this player? If so, keep it around
// and reuse it
if (creatureRecordId.empty())
{
creature.mId = "Dedicated Player";
creature.mId = creatureRecordId = RecordHelper::createCreatureRecord(creature);
LOG_APPEND(Log::LOG_INFO, "- Creating new creature record %s", creatureRecordId.c_str());
}
else
{
creature.mId = creatureRecordId;
RecordHelper::updateCreatureRecord(creature);
}
if (!reference)
{
LOG_APPEND(Log::LOG_INFO, "- Creating reference for %s", creature.mId.c_str());
createReference(creature.mId);
}
else
{
reloadPtr();
}
}
// This player was already a creature, but the new creature refId was empty or
// invalid, so we'll turn this player into their NPC self again as a result
else if (!isNpc)
{
recId = getCreatureRecordId();
if (reference)
{
deleteReference();
}
RecordHelper::updateNpcRecord(npc);
createReference(npc.mId);
reloadPtr();
}
}
if (recId.empty())
{
recId = getNpcRecordId();
previousCreatureRefId = creatureRefId;
}
createReference(recId);
if (ptr.getTypeName() == typeid(ESM::NPC).name())
{
MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptr, isWerewolf);
@ -217,8 +274,38 @@ void DedicatedPlayer::setAnimFlags()
ptrCreatureStats->setMovementFlag(CreatureStats::Flag_ForceMoveJump, (movementFlags & CreatureStats::Flag_ForceMoveJump) != 0);
}
void DedicatedPlayer::setAttributes()
{
MWMechanics::CreatureStats *ptrCreatureStats = &ptr.getClass().getCreatureStats(ptr);
MWMechanics::AttributeValue attributeValue;
for (int i = 0; i < 8; ++i)
{
attributeValue.readState(creatureStats.mAttributes[i]);
ptrCreatureStats->setAttribute(i, attributeValue);
}
}
void DedicatedPlayer::setSkills()
{
// Go no further if the player is disguised as a creature
if (ptr.getTypeName() != typeid(ESM::NPC).name()) return;
MWMechanics::NpcStats *ptrNpcStats = &ptr.getClass().getNpcStats(ptr);
MWMechanics::SkillValue skillValue;
for (int i = 0; i < 27; ++i)
{
skillValue.readState(npcStats.mSkills[i]);
ptrNpcStats->setSkill(i, skillValue);
}
}
void DedicatedPlayer::setEquipment()
{
// Go no further if the player is disguised as a creature
if (!ptr.getClass().hasInventoryStore(ptr)) return;
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore(ptr);
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot)
{
@ -349,54 +436,6 @@ void DedicatedPlayer::playSpeech()
winMgr->messageBox(MWBase::Environment::get().getDialogueManager()->getVoiceCaption(sound), MWGui::ShowInDialogueMode_Never);
}
std::string DedicatedPlayer::getNpcRecordId()
{
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr();
ESM::NPC newNpc = *player.get<ESM::NPC>()->mBase;
// To avoid freezes caused by invalid races, only set race if we find it
// on our client
if (world->getStore().get<ESM::Race>().search(npc.mRace) != 0)
newNpc.mRace = npc.mRace;
newNpc.mHead = npc.mHead;
newNpc.mHair = npc.mHair;
newNpc.mClass = npc.mClass;
newNpc.mName = npc.mName;
newNpc.mFlags = npc.mFlags;
LOG_APPEND(Log::LOG_INFO, "- Creating new NPC record");
newNpc.mId = "Dedicated Player";
std::string recId = world->createRecord(newNpc)->mId;
return recId;
}
std::string DedicatedPlayer::getCreatureRecordId()
{
MWBase::World *world = MWBase::Environment::get().getWorld();
ESM::Creature creature;
const ESM::Creature *tmpCreature = world->getStore().get<ESM::Creature>().search(creatureRefId);
creature = *tmpCreature;
creature.mScript = "";
if (!displayCreatureName)
creature.mName = npc.mName;
LOG_APPEND(Log::LOG_INFO, "Player %s looks like %s", npc.mName.c_str(), creatureRefId.c_str());
LOG_APPEND(Log::LOG_INFO, "- Creating new NPC record");
creature.mId = "Dedicated Player";
std::string recId = world->createRecord(creature)->mId;
return recId;
}
void DedicatedPlayer::createReference(const std::string& recId)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
@ -436,3 +475,10 @@ void DedicatedPlayer::setPtr(const MWWorld::Ptr& newPtr)
{
ptr = newPtr;
}
void DedicatedPlayer::reloadPtr()
{
MWBase::World *world = MWBase::Environment::get().getWorld();
world->disable(ptr);
world->enable(ptr);
}

@ -38,6 +38,8 @@ namespace mwmp
void setBaseInfo();
void setShapeshift();
void setAnimFlags();
void setAttributes();
void setSkills();
void setEquipment();
void setCell();
@ -48,9 +50,6 @@ namespace mwmp
void playAnimation();
void playSpeech();
std::string getNpcRecordId();
std::string getCreatureRecordId();
void createReference(const std::string& recId);
void deleteReference();
@ -58,6 +57,7 @@ namespace mwmp
MWWorld::ManualRef* getRef();
void setPtr(const MWWorld::Ptr& newPtr);
void reloadPtr();
private:
@ -70,6 +70,11 @@ namespace mwmp
ESM::CustomMarker marker;
bool markerEnabled;
std::string previousRace;
std::string previousCreatureRefId;
std::string creatureRecordId;
};
}
#endif //OPENMW_DEDICATEDPLAYER_HPP

@ -832,7 +832,10 @@ void LocalPlayer::setCharacter()
MWBase::Environment::get().getWorld()->getPlayer().setBirthSign(birthsign);
if (resetStats)
{
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(npc.mRace, npc.isMale(), npc.mHead, npc.mHair);
setEquipment();
}
else
{
ESM::NPC player = *world->getPlayerPtr().get<ESM::NPC>()->mBase;
@ -846,8 +849,6 @@ void LocalPlayer::setCharacter()
MWBase::Environment::get().getMechanicsManager()->playerLoaded();
}
setEquipment();
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar();
}
else
@ -1094,7 +1095,11 @@ void LocalPlayer::setEquipment()
}
}
else
ptrInventory.equip(slot, it, ptrPlayer);
{
// Don't try to equip an item that is already equipped
if (!ptrInventory.getSlot(slot).isEqual(it))
ptrInventory.equip(slot, it, ptrPlayer);
}
}
else
ptrInventory.unequipSlot(slot, ptrPlayer);

@ -0,0 +1,55 @@
#include <components/openmw-mp/Log.hpp>
#include "../mwbase/environment.hpp"
#include "../mwworld/worldimp.hpp"
#include "RecordHelper.hpp"
bool RecordHelper::doesCreatureExist(const std::string& refId)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
return world->getStore().get<ESM::Creature>().search(refId);
}
bool RecordHelper::doesRaceExist(const std::string& raceId)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
return world->getStore().get<ESM::Race>().search(raceId);
}
std::string RecordHelper::createCreatureRecord(const ESM::Creature& creature)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
return world->createRecord(creature)->mId;
}
std::string RecordHelper::createNpcRecord(const ESM::NPC& npc)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
return world->createRecord(npc)->mId;
}
void RecordHelper::updateCreatureRecord(const ESM::Creature& creature)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::ESMStore *esmStore = const_cast<MWWorld::ESMStore *>(&world->getStore());
MWWorld::Store<ESM::Creature> *creatureStore = const_cast<MWWorld::Store<ESM::Creature> *> (&esmStore->get<ESM::Creature>());
creatureStore->insert(creature);
}
void RecordHelper::updateNpcRecord(const ESM::NPC& npc)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::ESMStore *esmStore = const_cast<MWWorld::ESMStore *>(&world->getStore());
MWWorld::Store<ESM::NPC> *npcStore = const_cast<MWWorld::Store<ESM::NPC> *> (&esmStore->get<ESM::NPC>());
npcStore->insert(npc);
}

@ -0,0 +1,20 @@
#ifndef OPENMW_RECORDHELPER_HPP
#define OPENMW_RECORDHELPER_HPP
#include <components/esm/loadcrea.hpp>
#include <components/esm/loadnpc.hpp>
namespace RecordHelper
{
bool doesCreatureExist(const std::string& refId);
bool doesRaceExist(const std::string& raceId);
std::string createCreatureRecord(const ESM::Creature& creature);
std::string createNpcRecord(const ESM::NPC& npc);
void updateCreatureRecord(const ESM::Creature& creature);
void updateNpcRecord(const ESM::NPC& npc);
}
#endif //OPENMW_RECORDHELPER_HPP

@ -31,15 +31,7 @@ namespace mwmp
}
else if (player != 0)
{
MWWorld::Ptr ptrPlayer = static_cast<DedicatedPlayer *>(player)->getPtr();
MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer);
MWMechanics::AttributeValue attributeValue;
for (int i = 0; i < 8; ++i)
{
attributeValue.readState(player->creatureStats.mAttributes[i]);
ptrCreatureStats->setAttribute(i, attributeValue);
}
static_cast<DedicatedPlayer *>(player)->setAttributes();
}
}
};

@ -23,7 +23,7 @@ namespace mwmp
if (isLocal())
{
LOG_APPEND(Log::LOG_INFO, "- Packet was about my id");
LOG_APPEND(Log::LOG_INFO, "- Packet was about LocalPlayer");
if (isRequest())
{

@ -15,8 +15,12 @@ namespace mwmp
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_SHAPESHIFT from server");
if (isLocal())
{
LOG_APPEND(Log::LOG_INFO, "- Packet was about LocalPlayer");
static_cast<LocalPlayer *>(player)->setShapeshift();
}
else if (player != 0)

@ -29,15 +29,7 @@ namespace mwmp
}
else if (player != 0)
{
MWWorld::Ptr ptrPlayer = static_cast<DedicatedPlayer *>(player)->getPtr();
MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer);
MWMechanics::SkillValue skillValue;
for (int i = 0; i < 27; ++i)
{
skillValue.readState(player->npcStats.mSkills[i]);
ptrNpcStats->setSkill(i, skillValue);
}
static_cast<DedicatedPlayer *>(player)->setSkills();
}
}
};

@ -6,6 +6,7 @@
#define OPENMW_BASEPLAYER_HPP
#include <components/esm/loadcell.hpp>
#include <components/esm/loadcrea.hpp>
#include <components/esm/loadnpc.hpp>
#include <components/esm/npcstats.hpp>
#include <components/esm/loadclas.hpp>
@ -316,6 +317,7 @@ namespace mwmp
ESM::Position previousCellPosition;
ESM::NPC npc;
ESM::NpcStats npcStats;
ESM::Creature creature;
ESM::Class charClass;
std::string birthsign;
Chat chat;

Loading…
Cancel
Save