Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Isowind 62c83a8: MMO mode: harvested plants, ore and kwama eggs grow back per player

Isowind7e03c6fbbe57
diff --git a/android/app/src/main/java/ui/activity/MainActivity.kt b/android/app/src/main/java/ui/activity/MainActivity.kt
index 36b3bf0..34de6d5 100644
--- a/android/app/src/main/java/ui/activity/MainActivity.kt
+++ b/android/app/src/main/java/ui/activity/MainActivity.kt
@@ -638,6 +638,8 @@ class MainActivity : AppCompatActivity() {
line.substringAfter('=').trim()
}
}
+ // Menus made for a controller: the handheld's pad or the on-screen one drives them
+ sections.getOrPut("GUI") { linkedMapOf() }["controller menus"] = "true"
val settingsFile = File(Constants.USER_CONFIG, "settings.cfg")
sections.forEach { (name, values) -> updateSettingsSection(settingsFile, name, values) }
}
diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp
index 4e5860c..27aff00 100644
--- a/apps/openmw-mp/Script/Functions/Objects.cpp
+++ b/apps/openmw-mp/Script/Functions/Objects.cpp
@@ -673,6 +673,11 @@ void ObjectFunctions::SetContainerItemSoul(const char* soul) noexcept
tempContainerItem.soul = soul;
}
+void ObjectFunctions::SetContainerItemActionCount(int actionCount) noexcept
+{
+ tempContainerItem.actionCount = actionCount;
+}
+
void ObjectFunctions::SetContainerItemActionCountByIndex(unsigned int objectIndex, unsigned int itemIndex, int actionCount) noexcept
{
writeObjectList.baseObjects.at(objectIndex).containerItems.at(itemIndex).actionCount = actionCount;
diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp
index 73ae9d7..2a6254f 100644
--- a/apps/openmw-mp/Script/Functions/Objects.hpp
+++ b/apps/openmw-mp/Script/Functions/Objects.hpp
@@ -143,6 +143,7 @@
{"SetContainerItemSoul", ObjectFunctions::SetContainerItemSoul},\
\
{"SetContainerItemActionCountByIndex", ObjectFunctions::SetContainerItemActionCountByIndex},\
+ {"SetContainerItemActionCount", ObjectFunctions::SetContainerItemActionCount},\
\
{"AddObject", ObjectFunctions::AddObject},\
{"AddClientLocalInteger", ObjectFunctions::AddClientLocalInteger},\
@@ -1260,6 +1261,15 @@ public:
*/
static void SetContainerItemSoul(const char* soul) noexcept;
+ /**
+ * \brief Set the action count of the temporary container item stored on the server: how many
+ * of it a REMOVE takes away.
+ *
+ * \param actionCount The action count.
+ * \return void
+ */
+ static void SetContainerItemActionCount(int actionCount) noexcept;
+
/**
* \brief Set the action count of the container item at a certain itemIndex in the container
* changes of the object at a certain objectIndex in the object list stored on the server.
diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp
index a7703a0..e95e42c 100644
--- a/apps/openmw/mwbase/windowmanager.hpp
+++ b/apps/openmw/mwbase/windowmanager.hpp
@@ -13,6 +13,7 @@
#include "../mwgui/mode.hpp"
+#include <components/esm3/quickkeys.hpp>
#include <components/sdlutil/events.hpp>
namespace ESM
@@ -254,6 +255,20 @@ namespace MWBase
virtual void addVisitedLocation(const std::string& name, int x, int y) = 0;
+ /// Isowind controller menus: whether this menu has several windows side by side (the inventory screen,
+ /// containers, barter, companions), so the bumpers switch between them and the triggers do the bumpers' jobs
+ /// in the windows
+ virtual bool controllerCyclesWindows() = 0;
+ /// How fast the controller's menu cursor moves here (slower over the world map, so it can pick out places)
+ virtual float getControllerCursorSpeedScale() = 0;
+ /// Isowind controller menus: a click on one of the windows side by side makes it the active one
+ virtual void selectControllerWindowUnderMouse() = 0;
+ /// Isowind: opens the Quick Keys menu to put this item (Item, MagicItem) or spell (Magic) on the slot chosen
+ virtual void beginQuickKeyAssign(
+ ESM::QuickKeys::Type type, const MWWorld::Ptr& item, const ESM::RefId& spellId) = 0;
+ /// Isowind multiplayer: an explored cell's world map picture (a PNG) from the server
+ virtual void setGlobalMapTile(int cellX, int cellY, const std::vector<char>& png) = 0;
+
/// Hides dialog and schedules dialog to be deleted.
virtual void removeDialog(std::unique_ptr<MWGui::Layout>&& dialog) = 0;
diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp
index 9575abb..d07336e 100644
--- a/apps/openmw/mwclass/npc.cpp
+++ b/apps/openmw/mwclass/npc.cpp
@@ -719,6 +719,14 @@ namespace MWClass
void Npc::onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
const MWWorld::Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const
{
+ // Isowind multiplayer: players' hits on each other don't land while the server has PvP off
+ if (mwmp::hooks::isPvpBlocked(attacker, ptr))
+ {
+ if (sourceType != MWMechanics::DamageSourceType::Magical)
+ mwmp::hooks::finishLocalHit(attacker, ptr, 0.f, false);
+ return;
+ }
+
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
bool wasDead = stats.isDead();
diff --git a/apps/openmw/mwgui/controllerbuttonsoverlay.cpp b/apps/openmw/mwgui/controllerbuttonsoverlay.cpp
index 49a65b7..6779b86 100644
--- a/apps/openmw/mwgui/controllerbuttonsoverlay.cpp
+++ b/apps/openmw/mwgui/controllerbuttonsoverlay.cpp
@@ -70,6 +70,15 @@ namespace MWGui
void ControllerButtonsOverlay::setButtons(ControllerButtons* buttons)
{
int buttonCount = 0;
+ // Isowind: where the bumpers switch windows, the triggers do what the window's guide gives the bumpers
+ ControllerButtons swapped;
+ if (buttons != nullptr && MWBase::Environment::get().getWindowManager()->controllerCyclesWindows())
+ {
+ swapped = *buttons;
+ std::swap(swapped.mL1, swapped.mL2);
+ std::swap(swapped.mR1, swapped.mR2);
+ buttons = &swapped;
+ }
if (buttons != nullptr)
{
for (const auto& row : sButtonDefs)
diff --git a/apps/openmw/mwgui/inventorytabsoverlay.cpp b/apps/openmw/mwgui/inventorytabsoverlay.cpp
index 9affdee..8fcfc64 100644
--- a/apps/openmw/mwgui/inventorytabsoverlay.cpp
+++ b/apps/openmw/mwgui/inventorytabsoverlay.cpp
@@ -24,13 +24,14 @@ namespace MWGui
}
MyGUI::ImageBox* image;
+ // Isowind: the bumpers switch between these windows
getWidget(image, "BtnL2Image");
image->setImageTexture(
- MWBase::Environment::get().getInputManager()->getControllerAxisIcon(SDL_CONTROLLER_AXIS_TRIGGERLEFT));
+ MWBase::Environment::get().getInputManager()->getControllerButtonIcon(SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
getWidget(image, "BtnR2Image");
- image->setImageTexture(
- MWBase::Environment::get().getInputManager()->getControllerAxisIcon(SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
+ image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerButtonIcon(
+ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
}
int InventoryTabsOverlay::getHeight()
diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp
index 9400ab0..b50a2ec 100644
--- a/apps/openmw/mwgui/inventorywindow.cpp
+++ b/apps/openmw/mwgui/inventorywindow.cpp
@@ -140,19 +140,19 @@ namespace MWGui
if (Settings::gui().mControllerMenus)
{
- // Show L1 and R1 buttons next to tabs
+ // Show the buttons for the tabs next to them: the triggers (Isowind: the bumpers switch windows)
MyGUI::ImageBox* image;
getWidget(image, "BtnL1Image");
image->setVisible(true);
image->setUserString("Hidden", "false");
- image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerButtonIcon(
- SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
+ image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerAxisIcon(
+ SDL_CONTROLLER_AXIS_TRIGGERLEFT));
getWidget(image, "BtnR1Image");
image->setVisible(true);
image->setUserString("Hidden", "false");
- image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerButtonIcon(
- SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
+ image->setImageTexture(MWBase::Environment::get().getInputManager()->getControllerAxisIcon(
+ SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
mControllerButtons.mR3 = "#{Interface:Info}";
}
@@ -979,18 +979,21 @@ namespace MWGui
switch (mGuiMode)
{
case MWGui::GM_Companion:
+ mControllerButtons.mY.clear();
mControllerButtons.mA = "#{OMWEngine:InventorySelect}";
mControllerButtons.mB = "#{Interface:Close}";
mControllerButtons.mX.clear();
mControllerButtons.mR2 = "#{Interface:Share}";
break;
case MWGui::GM_Container:
+ mControllerButtons.mY.clear();
mControllerButtons.mA = "#{OMWEngine:InventorySelect}";
mControllerButtons.mB = "#{Interface:Close}";
mControllerButtons.mX = "#{Interface:TakeAll}";
mControllerButtons.mR2 = "#{Interface:Container}";
break;
case MWGui::GM_Barter:
+ mControllerButtons.mY.clear();
mControllerButtons.mA = "#{Interface:Sell}";
mControllerButtons.mB = "#{Interface:Cancel}";
mControllerButtons.mX = "#{Interface:Offer}";
@@ -1001,6 +1004,7 @@ namespace MWGui
mControllerButtons.mA = "#{Interface:Equip}";
mControllerButtons.mB = "#{Interface:Back}";
mControllerButtons.mX = "#{Interface:Drop}";
+ mControllerButtons.mY = "#{sQuickMenuTitle}";
mControllerButtons.mR2.clear();
break;
}
@@ -1026,6 +1030,14 @@ namespace MWGui
mItemView->onControllerButton(SDL_CONTROLLER_BUTTON_A);
}
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y && mGuiMode == MWGui::GM_Inventory)
+ {
+ // Isowind: the focused item onto a quick key (the Quick Keys menu opens to pick the slot)
+ const int index = mItemView->getControllerFocus();
+ if (index >= 0 && index < mItemView->getItemCount())
+ MWBase::Environment::get().getWindowManager()->beginQuickKeyAssign(
+ ESM::QuickKeys::Type::Item, mSortModel->getItem(index).mBase, ESM::RefId());
+ }
else if (arg.button == SDL_CONTROLLER_BUTTON_X)
{
if (mGuiMode == MWGui::GM_Inventory)
@@ -1094,16 +1106,8 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
if (winMgr->getMode() == MWGui::GM_Inventory)
{
- // Fill the screen, or limit to a certain size on large screens. Size chosen to
- // match the size of the stats window.
- MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
- int width = std::min(viewSize.width, 1600);
- int height = std::min(winMgr->getControllerMenuHeight(), StatsWindow::getIdealHeight());
- int x = (viewSize.width - width) / 2;
- int y = (viewSize.height - height) / 2;
-
+ // Isowind: the windows keep Morrowind's layout (the active one is lit, see WindowBase)
MyGUI::Window* window = mMainWidget->castType<MyGUI::Window>();
- window->setCoord(x, active ? y : viewSize.height + 1, width, height);
adjustPanes();
updatePreviewSize();
diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp
index 953c3d9..ff556bc 100644
--- a/apps/openmw/mwgui/mapwindow.cpp
+++ b/apps/openmw/mwgui/mapwindow.cpp
@@ -21,6 +21,7 @@
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp"
+#include "../mwbase/inputmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
@@ -1196,6 +1197,11 @@ namespace MWGui
return markerWidget;
}
+ void MapWindow::setGlobalMapTile(int cellX, int cellY, const std::vector<char>& png)
+ {
+ mGlobalMapRender->setTile(cellX, cellY, png);
+ }
+
void MapWindow::addVisitedLocation(const std::string& name, int x, int y)
{
CellId cell;
@@ -1249,6 +1255,7 @@ namespace MWGui
updateGlobalPlayerMarkers();
}
+
void MapWindow::updateGlobalPlayerMarkers()
{
std::size_t used = 0;
@@ -1583,19 +1590,7 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
if (winMgr->getMode() == MWGui::GM_Inventory)
{
- // Fill the screen, or limit to a certain size on large screens. Size chosen to
- // show the entire local map without scrolling.
- MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
- MyGUI::IntSize canvasSize = mLocalMap->getCanvasSize();
- MyGUI::IntSize borderSize = mMainWidget->getSize() - mMainWidget->getClientWidget()->getSize();
-
- int width = std::min(viewSize.width, canvasSize.width + borderSize.width);
- int height = std::min(winMgr->getControllerMenuHeight(), canvasSize.height + borderSize.height);
- int x = (viewSize.width - width) / 2;
- int y = (viewSize.height - height) / 2;
-
- MyGUI::Window* window = mMainWidget->castType<MyGUI::Window>();
- window->setCoord(x, active ? y : viewSize.height + 1, width, height);
+ // Isowind: the windows keep Morrowind's layout (the active one is lit, see WindowBase)
}
WindowBase::setActiveControllerWindow(active);
diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp
index 8e0b7f6..e7f6912 100644
--- a/apps/openmw/mwgui/mapwindow.hpp
+++ b/apps/openmw/mwgui/mapwindow.hpp
@@ -255,6 +255,9 @@ namespace MWGui
/// @param name The ESM::Cell::mName
void addVisitedLocation(const std::string& name, int x, int y);
+ /// Isowind multiplayer: an explored cell's picture (a PNG) from the server
+ void setGlobalMapTile(int cellX, int cellY, const std::vector<char>& png);
+
// reveals this cell's map on the global map
void cellExplored(int x, int y);
diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp
index f066e03..0c93242 100644
--- a/apps/openmw/mwgui/quickkeysmenu.cpp
+++ b/apps/openmw/mwgui/quickkeysmenu.cpp
@@ -133,6 +133,7 @@ namespace MWGui
void QuickKeysMenu::onClose()
{
WindowBase::onClose();
+ mPendingType = ESM::QuickKeys::Type::Unassigned;
if (mAssignDialog)
mAssignDialog->setVisible(false);
@@ -221,6 +222,13 @@ namespace MWGui
onAssignItem(item);
}
+ void QuickKeysMenu::beginAssign(ESM::QuickKeys::Type type, const MWWorld::Ptr& item, const ESM::RefId& spellId)
+ {
+ mPendingType = type;
+ mPendingItem = item;
+ mPendingSpell = spellId;
+ }
+
void QuickKeysMenu::unassignKey(int index)
{
if (index < 1 || index > static_cast<int>(mKey.size()))
@@ -252,6 +260,21 @@ namespace MWGui
if (mSelected->index == 10)
return;
+ // Isowind: an item or spell picked beforehand (Y in the inventory or magic window) goes straight on
+ if (mPendingType != ESM::QuickKeys::Type::Unassigned)
+ {
+ const ESM::QuickKeys::Type type = mPendingType;
+ mPendingType = ESM::QuickKeys::Type::Unassigned;
+ if (type == ESM::QuickKeys::Type::Item)
+ onAssignItem(mPendingItem);
+ else if (type == ESM::QuickKeys::Type::MagicItem)
+ onAssignMagicItem(mPendingItem);
+ else if (type == ESM::QuickKeys::Type::Magic)
+ onAssignMagic(mPendingSpell);
+ MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_QuickKeysMenu);
+ return;
+ }
+
// open assign dialog
if (!mAssignDialog)
mAssignDialog = std::make_unique<QuickKeysMenuAssign>(this);
diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp
index 7735070..b48b16c 100644
--- a/apps/openmw/mwgui/quickkeysmenu.hpp
+++ b/apps/openmw/mwgui/quickkeysmenu.hpp
@@ -54,6 +54,10 @@ namespace MWGui
/// Isowind's action bar: the Item / Magic / Delete dialog for a key (1-based), as clicking it here opens.
void openAssignDialog(int index);
void assignItemToKey(int index, const MWWorld::Ptr& item);
+
+ /// Isowind: the slot picked next gets this item (Item, MagicItem) or spell (Magic) instead of opening the
+ /// assign dialog; then the menu closes
+ void beginAssign(ESM::QuickKeys::Type type, const MWWorld::Ptr& item, const ESM::RefId& spellId);
void unassignKey(int index);
/// Isowind multiplayer: assigns a key (1-based slot) as the server says.
@@ -67,6 +71,10 @@ namespace MWGui
std::string_view getWindowIdForLua() const override { return "QuickKeys"; }
private:
+ ESM::QuickKeys::Type mPendingType = ESM::QuickKeys::Type::Unassigned;
+ MWWorld::Ptr mPendingItem;
+ ESM::RefId mPendingSpell;
+
struct keyData
{
int index = -1;
diff --git a/apps/openmw/mwgui/spellview.cpp b/apps/openmw/mwgui/spellview.cpp
index de18b25..cb8814e 100644
--- a/apps/openmw/mwgui/spellview.cpp
+++ b/apps/openmw/mwgui/spellview.cpp
@@ -307,6 +307,13 @@ namespace MWGui
return MyGUI::utility::parseInt(widget->getUserString("SpellModelIndex"));
}
+ int SpellView::getControllerFocusModelIndex() const
+ {
+ if (mControllerFocus >= mButtons.size())
+ return -1;
+ return MyGUI::utility::parseInt(mButtons[mControllerFocus].first->getUserString("SpellModelIndex"));
+ }
+
void SpellView::onSpellSelected(MyGUI::Widget* sender)
{
eventSpellClicked(getSpellModelIndex(sender));
diff --git a/apps/openmw/mwgui/spellview.hpp b/apps/openmw/mwgui/spellview.hpp
index e054334..846c6f9 100644
--- a/apps/openmw/mwgui/spellview.hpp
+++ b/apps/openmw/mwgui/spellview.hpp
@@ -42,6 +42,8 @@ namespace MWGui
void setModel(SpellModel* model);
SpellModel* getModel();
+ /// Isowind: the model index of the row the controller is on, or -1
+ int getControllerFocusModelIndex() const;
void update();
diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp
index 69d033e..356722b 100644
--- a/apps/openmw/mwgui/spellwindow.cpp
+++ b/apps/openmw/mwgui/spellwindow.cpp
@@ -68,6 +68,7 @@ namespace MWGui
setPinButtonVisible(false);
mControllerButtons.mA = "#{Interface:Select}";
mControllerButtons.mB = "#{Interface:Back}";
+ mControllerButtons.mY = "#{sQuickMenuTitle}";
mControllerButtons.mR3 = "#{Interface:Info}";
}
}
@@ -312,6 +313,21 @@ namespace MWGui
{
if (arg.button == SDL_CONTROLLER_BUTTON_B)
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
+ else if (arg.button == SDL_CONTROLLER_BUTTON_Y)
+ {
+ // Isowind: the focused spell or enchanted item onto a quick key (the Quick Keys menu picks the slot)
+ const int index = mSpellView->getControllerFocusModelIndex();
+ if (index >= 0 && index < static_cast<int>(mSpellView->getModel()->getItemCount()))
+ {
+ const Spell& spell = mSpellView->getModel()->getItem(index);
+ if (spell.mType == Spell::Type_EnchantedItem)
+ MWBase::Environment::get().getWindowManager()->beginQuickKeyAssign(
+ ESM::QuickKeys::Type::MagicItem, spell.mItem, ESM::RefId());
+ else
+ MWBase::Environment::get().getWindowManager()->beginQuickKeyAssign(
+ ESM::QuickKeys::Type::Magic, MWWorld::Ptr(), spell.mId);
+ }
+ }
else
mSpellView->onControllerButton(arg.button);
@@ -323,16 +339,8 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
if (winMgr->getMode() == MWGui::GM_Inventory)
{
- // Fill the screen, or limit to a certain size on large screens. Size chosen to
- // match the size of the stats window.
- MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
- int width = std::min(viewSize.width, StatsWindow::getIdealWidth());
- int height = std::min(winMgr->getControllerMenuHeight(), StatsWindow::getIdealHeight());
- int x = (viewSize.width - width) / 2;
- int y = (viewSize.height - height) / 2;
-
+ // Isowind: the windows keep Morrowind's layout (the active one is lit, see WindowBase)
MyGUI::Window* window = mMainWidget->castType<MyGUI::Window>();
- window->setCoord(x, active ? y : viewSize.height + 1, width, height);
MWBase::Environment::get().getWindowManager()->setControllerTooltipVisible(
active && Settings::gui().mControllerTooltips);
diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp
index 4323e7f..708a715 100644
--- a/apps/openmw/mwgui/statswindow.cpp
+++ b/apps/openmw/mwgui/statswindow.cpp
@@ -748,16 +748,8 @@ namespace MWGui
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
if (winMgr->getMode() == MWGui::GM_Inventory)
{
- // Fill the screen, or limit to a certain size on large screens. Size chosen to
- // show all stats.
- MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
- int width = std::min(viewSize.width, getIdealWidth());
- int height = std::min(winMgr->getControllerMenuHeight(), getIdealHeight());
- int x = (viewSize.width - width) / 2;
- int y = (viewSize.height - height) / 2;
-
+ // Isowind: the windows keep Morrowind's layout (the active one is lit, see WindowBase)
MyGUI::Window* window = mMainWidget->castType<MyGUI::Window>();
- window->setCoord(x, active ? y : viewSize.height + 1, width, height);
if (active)
onWindowResize(window);
diff --git a/apps/openmw/mwgui/windowbase.cpp b/apps/openmw/mwgui/windowbase.cpp
index 82053e6..5d21b0f 100644
--- a/apps/openmw/mwgui/windowbase.cpp
+++ b/apps/openmw/mwgui/windowbase.cpp
@@ -15,6 +15,21 @@
using namespace MWGui;
+void WindowBase::setActiveControllerWindow(bool active)
+{
+ mActiveControllerWindow = active;
+ // Isowind: with several windows side by side, the one the controller works in is lit and the others dimmed
+ if (Settings::gui().mControllerMenus && mMainWidget)
+ {
+ const float alpha
+ = active || !MWBase::Environment::get().getWindowManager()->controllerCyclesWindows() ? 1.f : 0.55f;
+ mMainWidget->setAlpha(alpha);
+ // Windows that fade under a dragged item settle back to this rather than to fully opaque
+ if (NoDrop* noDrop = dynamic_cast<NoDrop*>(this))
+ noDrop->setRestAlpha(alpha);
+ }
+}
+
size_t MWGui::wrap(size_t index, size_t max, int delta)
{
if (max == 0)
@@ -188,7 +203,8 @@ void NoDrop::onFrame(float dt)
else
{
mWidget->setNeedMouseFocus(true);
- setAlpha(std::min(1.0f, mWidget->getAlpha() + dt * 5));
+ const float alpha = mWidget->getAlpha();
+ setAlpha(alpha < mRestAlpha ? std::min(mRestAlpha, alpha + dt * 5) : std::max(mRestAlpha, alpha - dt * 5));
}
}
diff --git a/apps/openmw/mwgui/windowbase.hpp b/apps/openmw/mwgui/windowbase.hpp
index feb1d12..205b3ec 100644
--- a/apps/openmw/mwgui/windowbase.hpp
+++ b/apps/openmw/mwgui/windowbase.hpp
@@ -85,7 +85,7 @@ namespace MWGui
bool isGamepadCursorAllowed() { return !mDisableGamepadCursor; }
virtual bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) { return true; }
virtual bool onControllerThumbstickEvent(const SDL_ControllerAxisEvent& arg) { return false; }
- virtual void setActiveControllerWindow(bool active) { mActiveControllerWindow = active; }
+ virtual void setActiveControllerWindow(bool active);
protected:
virtual void onTitleDoubleClicked();
@@ -124,10 +124,14 @@ namespace MWGui
virtual void setAlpha(float alpha);
virtual ~NoDrop() = default;
+ /// Isowind: the alpha the window settles back to (dimmed when it isn't the controller's active window)
+ void setRestAlpha(float alpha) { mRestAlpha = alpha; }
+
private:
MyGUI::Widget* mWidget;
DragAndDrop* mDrag;
bool mTransparent;
+ float mRestAlpha = 1.f;
};
class BookWindowBase : public WindowBase
diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp
index a70f2cf..d883075 100644
--- a/apps/openmw/mwgui/windowmanagerimp.cpp
+++ b/apps/openmw/mwgui/windowmanagerimp.cpp
@@ -701,6 +701,14 @@ namespace MWGui
mControllerButtonsOverlay->setVisible(false);
if (mInventoryTabsOverlay)
mInventoryTabsOverlay->setVisible(false);
+ // Isowind: out of the menus no window is dimmed (the pinned map shows on the HUD)
+ for (WindowBase* window : { static_cast<WindowBase*>(mMap), static_cast<WindowBase*>(mStatsWindow),
+ static_cast<WindowBase*>(mInventoryWindow), static_cast<WindowBase*>(mSpellWindow) })
+ {
+ window->mMainWidget->setAlpha(1.f);
+ if (NoDrop* noDrop = dynamic_cast<NoDrop*>(window))
+ noDrop->setRestAlpha(1.f);
+ }
}
return;
}
@@ -1893,11 +1901,68 @@ namespace MWGui
mWaitDialog->wakeUp();
}
+ bool WindowManager::controllerCyclesWindows()
+ {
+ if (!Settings::gui().mControllerMenus || mGuiModes.empty() || !mCurrentModals.empty())
+ return false;
+ const GuiMode mode = mGuiModes.back();
+ if (mode != GM_Inventory && mode != GM_Container && mode != GM_Companion && mode != GM_Barter)
+ return false;
+ int visible = 0;
+ for (WindowBase* window : mGuiModeStates[mode].mWindows)
+ {
+ if (window->isVisible())
+ ++visible;
+ }
+ return visible > 1;
+ }
+
+ float WindowManager::getControllerCursorSpeedScale()
+ {
+ if (Settings::gui().mControllerMenus && Settings::map().mGlobal && getMode() == GM_Inventory
+ && getActiveControllerWindow() == mMap)
+ return 0.45f;
+ return 1.f;
+ }
+
+ void WindowManager::selectControllerWindowUnderMouse()
+ {
+ if (!controllerCyclesWindows())
+ return;
+ MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getMouseFocusWidget();
+ if (!focus)
+ return;
+ while (focus->getParent())
+ focus = focus->getParent();
+ const GuiMode mode = mGuiModes.back();
+ const std::vector<WindowBase*>& windows = mGuiModeStates[mode].mWindows;
+ for (size_t i = 0; i < windows.size(); ++i)
+ {
+ if (windows[i]->mMainWidget == focus && i != mActiveControllerWindows[mode])
+ {
+ setActiveControllerWindow(mode, i);
+ return;
+ }
+ }
+ }
+
+ void WindowManager::beginQuickKeyAssign(
+ ESM::QuickKeys::Type type, const MWWorld::Ptr& item, const ESM::RefId& spellId)
+ {
+ mQuickKeysMenu->beginAssign(type, item, spellId);
+ pushGuiMode(GM_QuickKeysMenu);
+ }
+
void WindowManager::addVisitedLocation(const std::string& name, int x, int y)
{
mMap->addVisitedLocation(name, x, y);
}
+ void WindowManager::setGlobalMapTile(int cellX, int cellY, const std::vector<char>& png)
+ {
+ mMap->setGlobalMapTile(cellX, cellY, png);
+ }
+
const Translation::Storage& WindowManager::getTranslationDataStorage() const
{
return mTranslationDataStorage;
diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp
index ddba8ec..5507e88 100644
--- a/apps/openmw/mwgui/windowmanagerimp.hpp
+++ b/apps/openmw/mwgui/windowmanagerimp.hpp
@@ -261,6 +261,12 @@ namespace MWGui
void notifyInputActionBound() override;
void addVisitedLocation(const std::string& name, int x, int y) override;
+ bool controllerCyclesWindows() override;
+ float getControllerCursorSpeedScale() override;
+ void selectControllerWindowUnderMouse() override;
+ void beginQuickKeyAssign(
+ ESM::QuickKeys::Type type, const MWWorld::Ptr& item, const ESM::RefId& spellId) override;
+ void setGlobalMapTile(int cellX, int cellY, const std::vector<char>& png) override;
/// Hides dialog and schedules dialog to be deleted.
void removeDialog(std::unique_ptr<Layout>&& dialog) override;
diff --git a/apps/openmw/mwinput/bindingsmanager.cpp b/apps/openmw/mwinput/bindingsmanager.cpp
index 2e3ef63..4003ed8 100644
--- a/apps/openmw/mwinput/bindingsmanager.cpp
+++ b/apps/openmw/mwinput/bindingsmanager.cpp
@@ -375,6 +375,7 @@ namespace MWInput
defaultButtonBindings[A_QuickKeyNext] = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
defaultButtonBindings[A_ZoomIn] = SDL_CONTROLLER_BUTTON_DPAD_UP;
defaultButtonBindings[A_ZoomOut] = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
+ defaultButtonBindings[A_QuickKeysMenu] = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
defaultButtonBindings[A_Sneak] = SDL_CONTROLLER_BUTTON_LEFTSTICK;
defaultButtonBindings[A_Rest] = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
defaultButtonBindings[A_Inventory] = SDL_CONTROLLER_BUTTON_BACK;
diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp
index d921376..b73b305 100644
--- a/apps/openmw/mwinput/controllermanager.cpp
+++ b/apps/openmw/mwinput/controllermanager.cpp
@@ -98,7 +98,8 @@ namespace MWInput
// We keep track of our own mouse position, so that moving the mouse while in
// game mode does not move the position of the GUI cursor
float uiScale = MWBase::Environment::get().getWindowManager()->getScalingFactor();
- const float gamepadCursorSpeed = Settings::input().mGamepadCursorSpeed;
+ const float gamepadCursorSpeed = Settings::input().mGamepadCursorSpeed
+ * MWBase::Environment::get().getWindowManager()->getControllerCursorSpeedScale();
const float xMove = xAxis * dt * 1500.0f / uiScale * gamepadCursorSpeed;
const float yMove = yAxis * dt * 1500.0f / uiScale * gamepadCursorSpeed;
@@ -276,6 +277,15 @@ namespace MWInput
if (mGamepadGuiCursorEnabled && treatAsMouse && arg.button == SDL_CONTROLLER_BUTTON_A)
return false;
+ // Isowind: in menus with several windows side by side the bumpers switch between them
+ if (winMgr->controllerCyclesWindows()
+ && (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER
+ || arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER))
+ {
+ winMgr->cycleActiveControllerWindow(arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
+ return true;
+ }
+
if (topWin->onControllerButtonEvent(arg))
return true;
}
@@ -362,17 +372,30 @@ namespace MWInput
if (Settings::gui().mControllerMenus)
{
- // Left and right triggers toggle through open GUI windows.
+ // Left and right triggers toggle through open GUI windows. Isowind: where the bumpers do that (several
+ // windows side by side), the triggers instead do what the bumpers do in the active window.
+ const auto triggerPressed = [&](bool right) {
+ MWGui::WindowBase* activeWin = winMgr->getActiveControllerWindow();
+ if (winMgr->controllerCyclesWindows() && activeWin && activeWin->isVisible())
+ {
+ SDL_ControllerButtonEvent bumper{};
+ bumper.type = SDL_CONTROLLERBUTTONDOWN;
+ bumper.state = SDL_PRESSED;
+ bumper.button
+ = right ? SDL_CONTROLLER_BUTTON_RIGHTSHOULDER : SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
+ activeWin->onControllerButtonEvent(bumper);
+ }
+ else
+ winMgr->cycleActiveControllerWindow(right);
+ };
if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
{
- handleTriggerPress(
- arg.value, mRightTriggerGuiPressed, [&] { winMgr->cycleActiveControllerWindow(true); });
+ handleTriggerPress(arg.value, mRightTriggerGuiPressed, [&] { triggerPressed(true); });
return true;
}
else if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT)
{
- handleTriggerPress(
- arg.value, mLeftTriggerGuiPressed, [&] { winMgr->cycleActiveControllerWindow(false); });
+ handleTriggerPress(arg.value, mLeftTriggerGuiPressed, [&] { triggerPressed(false); });
return true;
}
diff --git a/apps/openmw/mwinput/mousemanager.cpp b/apps/openmw/mwinput/mousemanager.cpp
index 4186b5a..1d98488 100644
--- a/apps/openmw/mwinput/mousemanager.cpp
+++ b/apps/openmw/mwinput/mousemanager.cpp
@@ -169,6 +169,8 @@ namespace MWInput
guiMode = MyGUI::InputManager::getInstance().injectMousePress(static_cast<int>(mGuiCursorX),
static_cast<int>(mGuiCursorY), SDLUtil::sdlMouseButtonToMyGui(id))
&& guiMode;
+ if (guiMode)
+ MWBase::Environment::get().getWindowManager()->selectControllerWindowUnderMouse();
if (MyGUI::InputManager::getInstance().getMouseFocusWidget() != nullptr)
{
MyGUI::Button* b
@@ -252,8 +254,11 @@ namespace MWInput
bool MouseManager::injectMouseButtonPress(Uint8 button)
{
- return MyGUI::InputManager::getInstance().injectMousePress(
+ const bool handled = MyGUI::InputManager::getInstance().injectMousePress(
static_cast<int>(mGuiCursorX), static_cast<int>(mGuiCursorY), SDLUtil::sdlMouseButtonToMyGui(button));
+ if (handled)
+ MWBase::Environment::get().getWindowManager()->selectControllerWindowUnderMouse();
+ return handled;
}
bool MouseManager::injectMouseButtonRelease(Uint8 button)
diff --git a/apps/openmw/mwlua/nearbybindings.cpp b/apps/openmw/mwlua/nearbybindings.cpp
index 48b1663..69c926a 100644
--- a/apps/openmw/mwlua/nearbybindings.cpp
+++ b/apps/openmw/mwlua/nearbybindings.cpp
@@ -13,6 +13,8 @@
#include "../mwworld/cellstore.hpp"
#include "../mwworld/scene.hpp"
+#include "../mwmp/Hooks.hpp"
+
#include "context.hpp"
#include "luamanagerimp.hpp"
#include "objectlists.hpp"
@@ -199,6 +201,8 @@ namespace MWLua
api["doors"] = LObjectList{ objectLists->getDoorsInScene() };
api["items"] = LObjectList{ objectLists->getItemsInScene() };
api["players"] = LObjectList{ objectLists->getPlayers() };
+ // Isowind multiplayer: whether an actor is another player (to the engine they are ordinary NPCs)
+ api["isOtherPlayer"] = [](const LObject& object) { return mwmp::hooks::isDedicatedPlayer(object.ptr()); };
api["NAVIGATOR_FLAGS"]
= LuaUtil::makeStrictReadOnly(LuaUtil::tableFromPairs<std::string_view, DetourNavigator::Flag>(lua,
diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp
index 5d80cb5..84160c5 100644
--- a/apps/openmw/mwmechanics/character.cpp
+++ b/apps/openmw/mwmechanics/character.cpp
@@ -2316,7 +2316,9 @@ namespace MWMechanics
{
float height = cls.getCreatureStats(mPtr).land(isPlayer);
float healthLost = 0.f;
- if (!inwater)
+ // Isowind multiplayer: other players and the actors another client runs get their health over
+ // the network; their positions jump as packets arrive, which would look like falls here
+ if (!inwater && !mwmp::hooks::isRemotelyControlled(mPtr))
healthLost = getFallDamage(mPtr, height);
if (healthLost > 0.0f)
diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp
index 4627f2e..ba9e9ca 100644
--- a/apps/openmw/mwmechanics/spellcasting.cpp
+++ b/apps/openmw/mwmechanics/spellcasting.cpp
@@ -198,6 +198,9 @@ namespace MWMechanics
const ESM::MagicEffect* magicEffect = store.find(enam.mData.mEffectID);
if (!magicEffect)
continue;
+ // Isowind multiplayer: no harmful spells from one player on another while the server has PvP off
+ if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && mwmp::hooks::isPvpBlocked(mCaster, target))
+ continue;
// caster needs to be an actor for linked effects (e.g. Absorb)
if (magicEffect->mData.mFlags & ESM::MagicEffect::CasterLinked
&& (mCaster.isEmpty() || !mCaster.getClass().isActor()))
diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp
index 3906a38..f86ffa0 100644
--- a/apps/openmw/mwmp/DedicatedActor.cpp
+++ b/apps/openmw/mwmp/DedicatedActor.cpp
@@ -1,3 +1,4 @@
+#include <algorithm>
#include <cmath>
#include <components/settings/values.hpp>
#include <components/vfs/pathutil.hpp>
@@ -59,12 +60,11 @@ DedicatedActor::~DedicatedActor()
void DedicatedActor::update(float dt)
{
- // Only move and set anim flags if the framerate isn't too low
- if (dt < 0.1)
- {
- move(dt);
- setAnimFlags();
- }
+ // Isowind: every frame, slow ones too (skipping them let the actor wander off on its last movement until the
+ // framerate picked up, ending up somewhere else than for everyone else); the step toward the position from the
+ // network is dt * 15 of the way, so dt is capped where that gets all the way there
+ move(std::min(dt, 1.f / 15.f));
+ setAnimFlags();
setStatsDynamic();
}
diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp
index 52f64ed..69da13f 100644
--- a/apps/openmw/mwmp/DedicatedPlayer.cpp
+++ b/apps/openmw/mwmp/DedicatedPlayer.cpp
@@ -1,3 +1,4 @@
+#include <algorithm>
#include <cmath>
#include <components/esm3/loadmgef.hpp>
@@ -75,12 +76,11 @@ DedicatedPlayer::~DedicatedPlayer()
void DedicatedPlayer::update(float dt)
{
- // Only move and set anim flags if the framerate isn't too low
- if (dt < 0.1)
- {
- move(dt);
- setAnimFlags();
- }
+ // Isowind: every frame, slow ones too (skipping them let the actor wander off on its last movement until the
+ // framerate picked up, ending up somewhere else than for everyone else); the step toward the position from the
+ // network is dt * 15 of the way, so dt is capped where that gets all the way there
+ move(std::min(dt, 1.f / 15.f));
+ setAnimFlags();
MWMechanics::CreatureStats *ptrCreatureStats = &ptr.getClass().getCreatureStats(ptr);
diff --git a/apps/openmw/mwmp/Hooks.cpp b/apps/openmw/mwmp/Hooks.cpp
index dcc07b6..2e040d5 100644
--- a/apps/openmw/mwmp/Hooks.cpp
+++ b/apps/openmw/mwmp/Hooks.cpp
@@ -544,6 +544,39 @@ namespace mwmp::hooks
return otherPlayer && contains(player->alliedPlayers, otherPlayer->guid);
}
+ namespace
+ {
+ bool sPvp = false;
+ bool sMmo = false;
+
+ bool isPlayer(const MWWorld::Ptr& ptr)
+ {
+ return isLocalPlayer(ptr) || isDedicatedPlayer(ptr);
+ }
+ }
+
+ bool applyServerRule(const std::string& name, const std::string& value)
+ {
+ if (name == "isowind pvp")
+ sPvp = value == "true";
+ else if (name == "isowind mode")
+ sMmo = value == "mmo";
+ else
+ return false;
+ return true;
+ }
+
+ bool isPvpBlocked(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim)
+ {
+ return isMultiplayer() && !sPvp && !attacker.isEmpty() && !victim.isEmpty() && attacker != victim
+ && isPlayer(attacker) && isPlayer(victim);
+ }
+
+ bool isMmoMode()
+ {
+ return isMultiplayer() && sMmo;
+ }
+
void sendSummonRemoval(const MWWorld::Ptr& creature)
{
if (!isLoggedIn() || creature.isEmpty())
@@ -1288,4 +1321,20 @@ namespace mwmp::hooks
objectList->sendObjectSpawn();
}
}
+
+ bool claimExploredMapTile(int cellX, int cellY)
+ {
+ if (!isLoggedIn())
+ return false;
+ mwmp::Worldstate* worldstate = Main::get().getNetworking()->getWorldstate();
+ if (worldstate->containsExploredMapTile(cellX, cellY))
+ return false;
+ worldstate->markExploredMapTile(cellX, cellY);
+ return true;
+ }
+
+ void sendExploredMapTile(int cellX, int cellY, const std::vector<char>& png)
+ {
+ Main::get().getNetworking()->getWorldstate()->sendMapExplored(cellX, cellY, png);
+ }
}
diff --git a/apps/openmw/mwmp/Hooks.hpp b/apps/openmw/mwmp/Hooks.hpp
index fb668da..98ee59c 100644
--- a/apps/openmw/mwmp/Hooks.hpp
+++ b/apps/openmw/mwmp/Hooks.hpp
@@ -162,6 +162,13 @@ namespace mwmp::hooks
/// Whether other is a player allied to the player actor (both the local player or other players), for siding
/// with each other (companions forgive their hits, they don't give away each other's sneaking)
bool isAlliedPlayer(const MWWorld::Ptr& actor, const MWWorld::Ptr& other);
+ /// The host's choices the server sends with the game settings ("isowind pvp", "isowind mode"): returns false
+ /// for other settings
+ bool applyServerRule(const std::string& name, const std::string& value);
+ /// Whether this is a hit or harmful spell from one player on another while the server has PvP off
+ bool isPvpBlocked(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim);
+ /// Whether the server is in MMO mode (everyone loots and quests for themselves)
+ bool isMmoMode();
/// A summoned creature going away: the server removes it for everyone, when this client is the one to say so
void sendSummonRemoval(const MWWorld::Ptr& creature);
@@ -300,6 +307,11 @@ namespace mwmp::hooks
ESM::RefId getDoorDestination(const ESM::RefId& destination);
/// Whether the server wants objects without collision of their own (items) to collide, and how
bool hasEnforcedCollision(const MWWorld::Ptr& ptr, bool& asActor);
+
+ /// The world map: whether this newly explored exterior cell's picture should go to the server (once per cell, which
+ /// it then counts as sent), and sending it (a PNG). The server keeps them and sends them all back at login.
+ bool claimExploredMapTile(int cellX, int cellY);
+ void sendExploredMapTile(int cellX, int cellY, const std::vector<char>& png);
}
#endif
diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp
index 5849050..56ff4e4 100644
--- a/apps/openmw/mwmp/MechanicsHelper.cpp
+++ b/apps/openmw/mwmp/MechanicsHelper.cpp
@@ -13,7 +13,9 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
+#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
+#include "../mwworld/scene.hpp"
#include "../mwmechanics/activespells.hpp"
#include "../mwmechanics/actorutil.hpp"
@@ -105,6 +107,27 @@ void MechanicsHelper::spawnLeveledCreatures(MWWorld::CellStore* cellStore)
objectList->sendObjectSpawn();
}
+bool MechanicsHelper::respawnActor(const MWWorld::Ptr& ptr)
+{
+ if (ptr.isEmpty() || !ptr.getClass().isActor() || ptr.getCell()->getState() != MWWorld::CellStore::State_Loaded
+ || MWBase::Environment::get().getWorldScene()->isCellActive(*ptr.getCell()))
+ return false;
+
+ // What Npc::respawn and Creature::respawn do, whatever the Respawn flag and time since death (its local
+ // script comes back when the cell becomes active)
+ MWBase::World* world = MWBase::Environment::get().getWorld();
+ if (ptr.getCellRef().getCount() == 0)
+ ptr.getCellRef().setCount(1);
+ MWBase::Environment::get().getWindowManager()->onDeleteCustomData(ptr);
+ ptr.getRefData().setCustomData(nullptr);
+ ptr.getRefData().enable();
+
+ const ESM::Position& start = ptr.getCellRef().getPosition();
+ MWWorld::Ptr moved = world->moveObject(ptr, ptr.getCell()->getOriginCell(ptr), start.asVec3());
+ world->rotateObject(moved, start.asRotationVec3(), MWBase::RotationFlag_none);
+ return true;
+}
+
bool MechanicsHelper::isUsingRangedWeapon(const MWWorld::Ptr& ptr)
{
if (ptr.getClass().hasInventoryStore(ptr))
diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp
index 2720ec5..9d4a6fe 100644
--- a/apps/openmw/mwmp/MechanicsHelper.hpp
+++ b/apps/openmw/mwmp/MechanicsHelper.hpp
@@ -15,6 +15,9 @@ namespace MechanicsHelper
ESM::Position getPositionFromVector(osg::Vec3f vector);
void spawnLeveledCreatures(MWWorld::CellStore* cellStore);
+ /// Isowind MMO: an actor the server brings back (respawns), alive and fresh at its starting place, as when
+ /// Morrowind respawns one. Only for cells nobody here is in; returns whether it was done.
+ bool respawnActor(const MWWorld::Ptr& ptr);
bool isUsingRangedWeapon(const MWWorld::Ptr& ptr);
diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp
index 91eda73..8f1767e 100644
--- a/apps/openmw/mwmp/ObjectList.cpp
+++ b/apps/openmw/mwmp/ObjectList.cpp
@@ -990,6 +990,10 @@ void ObjectList::runConsoleCommands(MWWorld::CellStore* cellStore)
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Running on object %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
+ // A cell this client hasn't loaded has its actors as they start anyway
+ if (consoleCommand == "isowind respawn" && cellStore->getState() != MWWorld::CellStore::State_Loaded)
+ continue;
+
MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum, mwmp::refId(baseObject.refId));
if (!ptrFound.isEmpty())
@@ -997,6 +1001,14 @@ void ObjectList::runConsoleCommands(MWWorld::CellStore* cellStore)
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Found %s %i-%i", mwmp::idString(ptrFound.getCellRef().getRefId()).c_str(),
ptrFound.getCellRef().getMpRefNum(), ptrFound.getCellRef().getMpNum());
+ // Isowind MMO: not a console command, the server bringing an enemy or NPC back
+ if (consoleCommand == "isowind respawn")
+ {
+ if (!MechanicsHelper::respawnActor(ptrFound))
+ LOG_APPEND(TimedLog::LOG_INFO, "-- Not respawned here (its cell is in use)");
+ continue;
+ }
+
windowManager->setConsolePtr(ptrFound);
windowManager->executeCommandInConsole(consoleCommand);
}
diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp
index 937d9af..00ec0bb 100644
--- a/apps/openmw/mwmp/Worldstate.cpp
+++ b/apps/openmw/mwmp/Worldstate.cpp
@@ -455,12 +455,9 @@ void Worldstate::setMapExplored()
MWBase::Environment::get().getWindowManager()->addVisitedLocation(
std::string(cellStore.getCell()->getNameId()), mapTile.x, mapTile.y);
- // TODO: TES3MP also shared the explored map's pictures (WindowManager::setGlobalMapImage), which needs
- // porting to OpenMW 0.51's global map
- //MWBase::Environment::get().getWindowManager()->setGlobalMapImage(mapTile.x, mapTile.y, mapTile.imageData);
-
- // Keep this tile marked as explored so we don't send any more packets for it
+ // Keep this tile marked as explored so we don't send any more packets for it (before drawing it)
markExploredMapTile(mapTile.x, mapTile.y);
+ MWBase::Environment::get().getWindowManager()->setGlobalMapTile(mapTile.x, mapTile.y, mapTile.imageData);
}
}
diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp
index a59c770..355853d 100644
--- a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp
+++ b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp
@@ -6,6 +6,7 @@
#include "apps/openmw/mwgui/windowmanagerimp.hpp"
#include "../PlayerProcessor.hpp"
+#include "apps/openmw/mwmp/Hooks.hpp"
namespace mwmp
{
@@ -54,6 +55,12 @@ namespace mwmp
for (auto setting : player->gameSettings)
{
+ // Isowind: the host's choices (PvP, game mode) come this way too
+ if (hooks::applyServerRule(setting.first, setting.second))
+ {
+ LOG_APPEND(TimedLog::LOG_INFO, "- %s: %s", setting.first.c_str(), setting.second.c_str());
+ continue;
+ }
// Ignore settings this version of the game doesn't have
try
{
diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp
index a9acfb8..3be0047 100644
--- a/apps/openmw/mwrender/globalmap.cpp
+++ b/apps/openmw/mwrender/globalmap.cpp
@@ -26,6 +26,8 @@
#include "../mwbase/environment.hpp"
+#include "../mwmp/Hooks.hpp"
+
#include "../mwworld/esmstore.hpp"
#include "vismask.hpp"
@@ -410,6 +412,40 @@ namespace MWRender
originX, mHeight - originY, cellSize, cellSize, std::move(localMapTexture), false, true);
}
+ void GlobalMap::setTile(int cellX, int cellY, const std::vector<char>& png)
+ {
+ ensureLoaded();
+
+ if (png.empty() || cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
+ return;
+
+ osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
+ if (!readerwriter)
+ return;
+ Files::IMemStream istream(png.data(), png.size());
+ osgDB::ReaderWriter::ReadResult result = readerwriter->readImage(istream);
+ if (!result.success())
+ {
+ Log(Debug::Warning) << "Can't read the map picture of cell " << cellX << ", " << cellY << ": "
+ << result.message();
+ return;
+ }
+
+ osg::ref_ptr<osg::Texture2D> texture(new osg::Texture2D);
+ texture->setImage(result.getImage());
+ texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
+ texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
+ texture->setResizeNonPowerOfTwoHint(false);
+
+ // Where exploreCell draws it; no copy back, which would only send it to the server again
+ const int cellSize = Settings::map().mGlobalMapCellSize;
+ const int originX = (cellX - mMinX) * cellSize;
+ const int originY = (cellY - mMinY + 1) * cellSize;
+ requestOverlayTextureUpdate(originX, mHeight - originY, cellSize, cellSize, std::move(texture), false, false);
+ }
+
void GlobalMap::clear()
{
ensureLoaded();
@@ -600,6 +636,16 @@ namespace MWRender
}
mOverlayImage->copySubImage(imageDest.mX, imageDest.mY, 0, imageDest.mImage);
+
+ // Isowind multiplayer: a newly explored cell's picture goes to the server, which keeps every player's
+ // exploration and sends it back at login (only exploreCell copies back like this; its corner is
+ // (cell - min) * cellSize in the image's bottom-left coordinates)
+ const int cellSize = Settings::map().mGlobalMapCellSize;
+ const int cellX = imageDest.mX / cellSize + mMinX;
+ const int cellY = imageDest.mY / cellSize + mMinY;
+ if (mwmp::hooks::claimExploredMapTile(cellX, cellY))
+ mwmp::hooks::sendExploredMapTile(cellX, cellY, writePng(*imageDest.mImage));
+
mPendingImageDest.erase(it);
return true;
}
diff --git a/apps/openmw/mwrender/globalmap.hpp b/apps/openmw/mwrender/globalmap.hpp
index 07d7731..5394cf7 100644
--- a/apps/openmw/mwrender/globalmap.hpp
+++ b/apps/openmw/mwrender/globalmap.hpp
@@ -45,6 +45,10 @@ namespace MWRender
void exploreCell(int cellX, int cellY, osg::ref_ptr<osg::Texture2D> localMapTexture);
+ /// Isowind multiplayer: draws an explored cell's picture (a PNG, as exploring it here would have made) from
+ /// the server
+ void setTile(int cellX, int cellY, const std::vector<char>& png);
+
/// Clears the overlay
void clear();
diff --git a/files/shaders/lib/util/cutaway.glsl b/files/shaders/lib/util/cutaway.glsl
index 9c37558..5665130 100644
--- a/files/shaders/lib/util/cutaway.glsl
+++ b/files/shaders/lib/util/cutaway.glsl
@@ -129,8 +129,13 @@ vec2 applyCutaway(vec3 viewPos, vec3 viewNormal, bool terrain)
vec2 towardCamera = -normalize(cameraForward.xy + vec2(1e-5));
bool inFront = dot(world.xy - playerPos.xy, towardCamera) > CUTAWAY_FRONT_MARGIN;
+ // Level surfaces below the player's waist (swamp scum on a pool they wade in, rugs, tabletops, lower steps)
+ // never hide them from above, so a faded object stays whole there
+ vec3 worldNormal = (osg_ViewMatrixInverse * vec4(viewNormal, 0.0)).xyz;
+ bool lowFloor = abs(worldNormal.z) > 0.7 && world.z < playerPos.z + CUTAWAY_WALL_HEIGHT;
+
float cut = 0.0;
- if (occluderFade > 0.0)
+ if (occluderFade > 0.0 && !lowFloor)
{
// Open in a circle around the player on screen (measured at their distance) and see-through around it,
// where this fragment is in front of them
@@ -171,7 +176,6 @@ vec2 applyCutaway(vec3 viewPos, vec3 viewNormal, bool terrain)
{
float around = 1.0 - smoothstep(cutawayOverheadRadius * 0.8, cutawayOverheadRadius,
length(world.xy - playerPos.xy));
- vec3 worldNormal = (osg_ViewMatrixInverse * vec4(viewNormal, 0.0)).xyz;
if (abs(worldNormal.z) > 0.5)
cut = max(cut, around);
cut = max(cut, around * step(CUTAWAY_STOREY_HEIGHT, world.z - playerPos.z));
diff --git a/isowind/README.txt b/isowind/README.txt
index 04845b7..599ce63 100644
--- a/isowind/README.txt
+++ b/isowind/README.txt
@@ -23,7 +23,7 @@ Getting started
On Linux, unpack the folder and use isowind.sh instead of Isowind.exe, from a terminal:
./isowind.sh play (pixel art; ./isowind.sh normal for the normal look)
./isowind.sh join ADDRESS play on a server
- ./isowind.sh host run a server in that terminal
+ ./isowind.sh host run a server in that terminal (it asks its settings first)
The first time it finds Morrowind in Steam's usual places and sets up OpenMW for it; otherwise run it as
MORROWIND=/path/to/Morrowind ./isowind.sh (the folder with "Data Files" in it). The pixel art look
needs Python 3; it fetches Pillow for itself if your system doesn't have it.
@@ -46,16 +46,26 @@ Joining a friend's server
The address is remembered for next time.
Hosting a server
-1. Press "Host a server" in Isowind.exe. A server window opens; close it to stop the server.
-2. Press Join (the address is set to 127.0.0.1, this computer) to play on it yourself.
+1. Press "Host a server" in Isowind.exe and choose its settings:
+ - Name, port (25565 unless you change it), most players, and a password (empty: anyone can join).
+ - Game: Co-op is one shared world, as in single player. MMO gives everyone their own loot
+ (containers, corpses, plants, items lying around) and their own quests, and enemies and NPCs
+ come back after they die once no one is nearby: weak ones after 1.5 minutes, normal ones 5,
+ tough ones 15, bosses 60 ("Enemy respawns" speeds that up or slows it down). Plants and ore
+ you harvested grow back for you after 10 minutes; chests don't refill.
+ - PvP (whether players can hurt each other), difficulty and how fast the time of day goes.
+ Then a server window opens; close it to stop the server.
+2. Press Join (the address is set to this computer) to play on it yourself.
3. Friends need to reach your computer, one of two ways:
- - Port forwarding: in your router, forward UDP port 25565 to this computer, and allow
- tes3mp-server.exe through the Windows firewall when it asks. Friends use your internet address
- (search "what is my IP").
+ - Port forwarding: in your router, forward the server's UDP port (25565) to this computer, and
+ allow tes3mp-server.exe through the Windows firewall when it asks. Friends use your internet
+ address (search "what is my IP").
- A VPN that puts you on one network, such as Tailscale, ZeroTier or Radmin VPN (free). Everyone
joins the same network and friends use this computer's address in it.
-The server's settings (port, password, player count) are in server\tes3mp-server-default.cfg, and
-everything it saves (characters, the world) in server\CoreScripts\data. Its log is in server\logs.
+Your choices are kept in server\tes3mp-server.cfg (over server\tes3mp-server-default.cfg), and
+everything the server saves (characters, the world) in server\CoreScripts\data. Its log is in
+server\logs. Keep the same game (co-op or MMO) for a world: an MMO world switched to co-op forgets
+what each player looted, so it's all back.
In multiplayer
Enter Talk in the chat; F2 hides or shows the chat window.
diff --git a/isowind/linux/isowind.sh b/isowind/linux/isowind.sh
index 29881c9..dc48dbb 100755
--- a/isowind/linux/isowind.sh
+++ b/isowind/linux/isowind.sh
@@ -4,7 +4,8 @@
# ./isowind.sh play (pixel art look, or the look you used last)
# ./isowind.sh normal play with the normal look (or: pixelart)
# ./isowind.sh join ADDRESS play on a server, e.g. ./isowind.sh join 203.0.113.7:25565 (look optional after it)
-# ./isowind.sh host run a server here, in this terminal (others join with this computer's address)
+# ./isowind.sh host run a server here, in this terminal, after asking its settings (others join
+# with this computer's address)
#
# The first time, it finds Morrowind (Steam's usual places; otherwise run it as MORROWIND=/path/to/Morrowind
# ./isowind.sh, the folder with "Data Files" and Morrowind.ini) and sets up OpenMW for it, like OpenMW's wizard.
@@ -58,20 +59,107 @@ Install your distribution's python3-pillow (or python3-venv), or play with the n
echo "Built by isowind.sh from your Morrowind files" > "$TEXTURES_MARKER"
}
+# set_setting FILE SECTION KEY VALUE: sets KEY in [SECTION] of a settings file (OpenMW's settings.cfg, the server's
+# tes3mp-server.cfg); a new one goes after the section's last setting
+set_setting() {
+ awk -v section="[$2]" -v key="$3" -v value="$4" '
+ function emit() { print key " = " value; done = 1 }
+ function flush() { printf "%s", blanks; blanks = "" }
+ $0 == section { print; insection = 1; next }
+ insection && /^[ \t\r]*$/ { blanks = blanks $0 "\n"; next }
+ /^\[/ && insection { if (!done) emit(); insection = 0 }
+ insection && index($0, key " =") == 1 { flush(); emit(); next }
+ { flush(); print }
+ END { if (!done) { if (!insection) print "\n" section; emit() } flush() }
+ ' "$1" > "$1.tmp" && mv "$1.tmp" "$1"
+}
+
+# get_server_setting SECTION KEY DEFAULT: from the server's settings files (in the current folder), tes3mp-server.cfg's
+# over tes3mp-server-default.cfg's
+get_server_setting() {
+ VALUE=$(cat tes3mp-server-default.cfg tes3mp-server.cfg 2>/dev/null | tr -d '\r' | awk -v section="[$1]" -v key="$2" '
+ /^\[/ { insection = ($0 == section); next }
+ insection && !/^#/ && (i = index($0, "=")) {
+ k = substr($0, 1, i - 1); v = substr($0, i + 1)
+ gsub(/^[ \t]+|[ \t]+$/, "", k); gsub(/^[ \t]+|[ \t]+$/, "", v)
+ if (k == key) found = v
+ }
+ END { print found }')
+ echo "${VALUE:-$3}"
+}
+
+# ask QUESTION DEFAULT [PATTERN]: the answer in REPLY (Enter keeps the default); asked again until it matches the
+# extended regular expression PATTERN
+ask() {
+ while :; do
+ printf '%s [%s]: ' "$1" "$2"
+ read -r REPLY || REPLY=""
+ [ -n "$REPLY" ] || REPLY=$2
+ if [ -z "$3" ] || printf '%s\n' "$REPLY" | grep -Eqx "$3"; then return; fi
+ echo " That isn't one of the choices."
+ done
+}
+
+# The host's choices, kept in server/tes3mp-server.cfg (over tes3mp-server-default.cfg), as Isowind.exe's
+# "Host a server" window does on Windows
+ask_host_settings() {
+ FILE=tes3mp-server.cfg
+ [ -f "$FILE" ] || echo "# This server's settings, over those in tes3mp-server-default.cfg (isowind.sh host writes them)" > "$FILE"
+ if [ ! -t 0 ]; then return; fi
+ echo "Hosting a server. Press Enter to keep the choice in [brackets]."
+ ask "Server name" "$(get_server_setting General hostname 'Isowind server')" '[^=#]{1,60}'
+ set_setting "$FILE" General hostname "$REPLY"
+ ask "Port" "$(get_server_setting General port 25565)" '[0-9]{4,5}'
+ PORT=$REPLY
+ set_setting "$FILE" General port "$REPLY"
+ ask "Most players" "$(get_server_setting General maximumPlayers 16)" '[1-9]|[1-5][0-9]|6[0-4]'
+ set_setting "$FILE" General maximumPlayers "$REPLY"
+ PASSWORD=$(get_server_setting General password '')
+ ask "Password (a single - for none)" "${PASSWORD:--}" '[^ ]{1,40}'
+ [ "$REPLY" = "-" ] && REPLY=""
+ set_setting "$FILE" General password "$REPLY"
+ echo "Game: coop - one shared world, as in single player"
+ echo " mmo - everyone loots and quests for themselves, and enemies come back"
+ ask "Game (coop or mmo)" "$(get_server_setting Isowind mode coop)" 'coop|mmo'
+ MODE=$REPLY
+ set_setting "$FILE" Isowind mode "$REPLY"
+ PVP=$(get_server_setting Isowind pvp false)
+ [ "$PVP" = true ] && PVP=yes || PVP=no
+ ask "Can players hurt each other (PvP)? (yes or no)" "$PVP" 'yes|no'
+ [ "$REPLY" = yes ] && REPLY=true || REPLY=false
+ set_setting "$FILE" Isowind pvp "$REPLY"
+ ask "Difficulty, -100 (very easy) to 100 (very hard), 0 is Morrowind's normal" \
+ "$(get_server_setting Isowind difficulty 0)" '-?[0-9]{1,3}'
+ set_setting "$FILE" Isowind difficulty "$REPLY"
+ if [ "$MODE" = mmo ]; then
+ ask "How fast enemies come back: 0.5, 1, 2 or 4 (1: 1.5 minutes for the weakest, 60 for bosses)" \
+ "$(get_server_setting Isowind respawnSpeed 1)" '0\.5|1|2|4'
+ set_setting "$FILE" Isowind respawnSpeed "$REPLY"
+ fi
+ ask "How fast the time of day goes: 0.5, 1, 2 or 4 (1: Morrowind's, an hour in 2 minutes)" \
+ "$(get_server_setting Isowind timeSpeed 1)" '0\.5|1|2|4'
+ set_setting "$FILE" Isowind timeSpeed "$REPLY"
+}
+
play() {
LOOK=${1:-$(cat "$LOOK_FILE" 2>/dev/null || echo pixelart)}
case $LOOK in pixelart|normal) ;; *) die "unknown look '$LOOK' (pixelart or normal)" ;; esac
echo "$LOOK" > "$LOOK_FILE"
setup_morrowind
[ "$LOOK" = pixelart ] && build_textures
+ # Menus made for a controller when one is plugged in, Morrowind's own (drag and drop) otherwise
+ if ls /dev/input/js* >/dev/null 2>&1; then MENUS=true; else MENUS=false; fi
+ set_setting "$ROOT/profiles/$LOOK/settings.cfg" GUI "controller menus" "$MENUS"
exec "$ENGINE/openmw" --config "$ROOT/profiles/$LOOK" $CONNECT
}
case $1 in
host)
cd "$ROOT/server"
- echo "Starting the server (Ctrl+C stops it). Play on it with: $0 join 127.0.0.1"
- echo "Friends join with this computer's address; the host's router needs UDP port 25565 forwarded to it."
+ ask_host_settings
+ PORT=$(get_server_setting General port 25565)
+ echo "Starting the server (Ctrl+C stops it). Play on it with: $0 join 127.0.0.1:$PORT"
+ echo "Friends join with this computer's address; the host's router needs UDP port $PORT forwarded to it."
exec "$ENGINE/tes3mp-server" ;;
join)
[ -n "$2" ] || die "join needs the server's address, e.g. $0 join 203.0.113.7"
@@ -80,6 +168,6 @@ case $1 in
""|pixelart|normal)
play "$1" ;;
*)
- sed -n '2,11p' "$0" | sed 's/^# \{0,1\}//'
+ sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'
exit 1 ;;
esac
diff --git a/isowind/mod/isowind.omwscripts b/isowind/mod/isowind.omwscripts
index 2e01e72..5f3933f 100644
--- a/isowind/mod/isowind.omwscripts
+++ b/isowind/mod/isowind.omwscripts
@@ -1,2 +1,3 @@
PLAYER: scripts/isowind/topdown.lua
GLOBAL: scripts/isowind/topdown_global.lua
+MENU: scripts/isowind/settings.lua
diff --git a/isowind/mod/l10n/Isowind/en.yaml b/isowind/mod/l10n/Isowind/en.yaml
new file mode 100644
index 0000000..d096b14
--- /dev/null
+++ b/isowind/mod/l10n/Isowind/en.yaml
@@ -0,0 +1,5 @@
+settings_page: "Isowind"
+settings_page_desc: "Isowind's own options."
+settings_multiplayer: "Multiplayer"
+settings_player_names: "Show player names"
+settings_player_names_desc: "Always show the other players' names over them."
diff --git a/isowind/mod/scripts/isowind/healthbars.lua b/isowind/mod/scripts/isowind/healthbars.lua
index fc14c71..8d27028 100644
--- a/isowind/mod/scripts/isowind/healthbars.lua
+++ b/isowind/mod/scripts/isowind/healthbars.lua
@@ -1,8 +1,10 @@
--- Health bars over the heads of creatures, and of people once they are hurt or hostile (Diablo style).
+-- Health bars over the heads of creatures, and of people once they are hurt or hostile (Diablo style); in
+-- multiplayer, the other players' names over them too (Options -> Scripts -> Isowind).
-- Used by topdown.lua, which supplies the projection from the world onto the screen.
local self = require('openmw.self')
local nearby = require('openmw.nearby')
+local storage = require('openmw.storage')
local types = require('openmw.types')
local ui = require('openmw.ui')
local util = require('openmw.util')
@@ -19,7 +21,12 @@ local texture = ui.texture { path = 'textures/menu_bar_red.dds' }
local backColor = util.color.rgb(0.08, 0.04, 0.04)
local fillColor = util.color.rgb(0.85, 0.15, 0.1)
+local NAME_SIZE = 16
+local nameColor = util.color.rgb(0.792, 0.647, 0.376) -- Morrowind's normal text colour
+local multiplayerSettings = storage.playerSection('Settings/Isowind/Multiplayer')
+
local bars = {} -- actor id -> UI element
+local names = {} -- actor id -> UI element (other players' names)
local M = {}
@@ -66,10 +73,54 @@ local function remove(id)
bars[id] = nil
end
+local function removeName(id)
+ names[id]:destroy()
+ names[id] = nil
+end
+
+local function makeName(text)
+ return ui.create {
+ layer = 'IsowindOverlay',
+ type = ui.TYPE.Text,
+ props = {
+ anchor = v2(0.5, 1),
+ text = text,
+ textSize = NAME_SIZE,
+ textColor = nameColor,
+ textShadow = true,
+ textShadowColor = util.color.rgb(0, 0, 0),
+ },
+ }
+end
+
+-- Another player whose name should show (multiplayer, and the option is on)
+local function showsName(actor)
+ return nearby.isOtherPlayer ~= nil and nearby.isOtherPlayer(actor)
+ and multiplayerSettings:get('ShowPlayerNames') ~= false
+ and (actor.position - self.position):length() <= RANGE
+end
+
-- project(worldPosition) returns a normalised screen position, or nil when it is off screen.
function M.update(project)
local seen = {}
+ local seenNames = {}
for _, actor in ipairs(nearby.actors) do
+ if showsName(actor) then
+ local box = actor:getBoundingBox()
+ local screen = project(v3(box.center.x, box.center.y, box.center.z + box.halfSize.z + 12))
+ if screen then
+ seenNames[actor.id] = true
+ local label = names[actor.id]
+ if not label then
+ label = makeName(types.NPC.record(actor).name)
+ names[actor.id] = label
+ end
+ label.layout.props.relativePosition = screen
+ -- above where the health bar goes
+ label.layout.props.position = v2(0, -(HEIGHT + 2))
+ label:update()
+ end
+ end
local fraction = wanted(actor)
if fraction then
local box = actor:getBoundingBox()
@@ -91,10 +142,14 @@ function M.update(project)
for id in pairs(bars) do
if not seen[id] then remove(id) end
end
+ for id in pairs(names) do
+ if not seenNames[id] then removeName(id) end
+ end
end
function M.clear()
for id in pairs(bars) do remove(id) end
+ for id in pairs(names) do removeName(id) end
end
return M
diff --git a/isowind/mod/scripts/isowind/settings.lua b/isowind/mod/scripts/isowind/settings.lua
new file mode 100644
index 0000000..18b96d5
--- /dev/null
+++ b/isowind/mod/scripts/isowind/settings.lua
@@ -0,0 +1,28 @@
+-- Isowind's page in the game's Options -> Scripts (a MENU script, where settings pages are registered). The player
+-- scripts read these from storage.playerSection('Settings/Isowind/Multiplayer').
+
+local I = require('openmw.interfaces')
+
+I.Settings.registerPage {
+ key = 'Isowind',
+ l10n = 'Isowind',
+ name = 'settings_page',
+ description = 'settings_page_desc',
+}
+
+I.Settings.registerGroup {
+ key = 'Settings/Isowind/Multiplayer',
+ page = 'Isowind',
+ l10n = 'Isowind',
+ name = 'settings_multiplayer',
+ permanentStorage = true,
+ settings = {
+ {
+ key = 'ShowPlayerNames',
+ renderer = 'checkbox',
+ name = 'settings_player_names',
+ description = 'settings_player_names_desc',
+ default = true,
+ },
+ },
+}
diff --git a/isowind/mod/scripts/isowind/topdown.lua b/isowind/mod/scripts/isowind/topdown.lua
index 999a758..57c5b28 100644
--- a/isowind/mod/scripts/isowind/topdown.lua
+++ b/isowind/mod/scripts/isowind/topdown.lua
@@ -818,9 +818,24 @@ local function onKeyPress(key)
end
end
+-- A frame that fails part way must not leave the selection ring or the health bars stuck where they were: hide them
+-- and say (once per different error) what went wrong.
+local lastFrameError = nil
+local function onFrameSafe(dt)
+ local ok, err = pcall(onFrame, dt)
+ if not ok then
+ pcall(hidesRing)
+ pcall(healthbars.clear)
+ if err ~= lastFrameError then
+ lastFrameError = err
+ print('top-down frame failed: ' .. tostring(err))
+ end
+ end
+end
+
return {
engineHandlers = {
- onFrame = onFrame,
+ onFrame = onFrameSafe,
onMouseButtonPress = onMouseButtonPress,
onInputAction = onInputAction,
onKeyPress = onKeyPress,
diff --git a/isowind/profiles/input_v3.xml b/isowind/profiles/input_v3.xml
index 23ca47d..f62a017 100644
--- a/isowind/profiles/input_v3.xml
+++ b/isowind/profiles/input_v3.xml
@@ -171,6 +171,7 @@
</Control>
<Control name="41" autoChangeDirectionOnLimitsAfterStop="false" autoReverseToInitialValue="true" initialValue="0" stepSize="MAX" stepsPerSeconds="MAX">
<KeyBinder key="58" direction="INCREASE" />
+ <JoystickButtonBinder button="13" direction="INCREASE" deviceId="1" />
<Channel number="41" direction="DIRECT" percentage="1" />
</Control>
<Control name="42" autoChangeDirectionOnLimitsAfterStop="false" autoReverseToInitialValue="true" initialValue="0" stepSize="MAX" stepsPerSeconds="MAX">
diff --git a/isowind/server/CoreScripts/.gitignore b/isowind/server/CoreScripts/.gitignore
index 093cb16..0631fef 100644
--- a/isowind/server/CoreScripts/.gitignore
+++ b/isowind/server/CoreScripts/.gitignore
@@ -2,3 +2,4 @@ data/*
lib/*
scripts/custom/*
!/lib/lua
+!scripts/custom/isowind*.lua
diff --git a/isowind/server/CoreScripts/scripts/custom/isowindHost.lua b/isowind/server/CoreScripts/scripts/custom/isowindHost.lua
new file mode 100644
index 0000000..7be17a3
--- /dev/null
+++ b/isowind/server/CoreScripts/scripts/custom/isowindHost.lua
@@ -0,0 +1,77 @@
+-- Isowind: the host's choices, from [Isowind] in tes3mp-server-default.cfg and then tes3mp-server.cfg (which
+-- Isowind.exe's "Host a server" and "isowind.sh host" write). The server runs in the folder they're in.
+--
+-- mode coop (one shared world) or mmo (everyone loots and quests for themselves, enemies respawn)
+-- pvp whether players can hurt each other
+-- difficulty -100 to 100, 0 is Morrowind's normal
+-- respawnSpeed MMO: how much faster than normal enemies come back (0.5 to 4)
+-- timeSpeed how much faster than Morrowind's the time of day goes (0.5 to 4)
+--
+-- Players are told the mode and PvP with the game settings sent at login ("isowind mode", "isowind pvp").
+
+IsowindHost = { mode = "coop", pvp = false, difficulty = 0, respawnSpeed = 1, timeSpeed = 1 }
+
+local function readSettings(path, values)
+ local file = io.open(path, "r")
+ if file == nil then
+ return
+ end
+ local section = ""
+ for line in file:lines() do
+ line = line:match("^%s*(.-)%s*$")
+ if line ~= "" and line:sub(1, 1) ~= "#" then
+ local name = line:match("^%[(.-)%]$")
+ if name ~= nil then
+ section = name
+ elseif section == "Isowind" then
+ local key, value = line:match("^(.-)%s*=%s*(.*)$")
+ if key ~= nil and value ~= "" then
+ values[key] = value
+ end
+ end
+ end
+ end
+ file:close()
+end
+
+local function clamp(value, low, high, default)
+ value = tonumber(value)
+ if value == nil then
+ return default
+ end
+ return math.max(low, math.min(high, value))
+end
+
+local values = {}
+readSettings("tes3mp-server-default.cfg", values)
+readSettings("tes3mp-server.cfg", values)
+
+IsowindHost.mode = string.lower(values.mode or "coop") == "mmo" and "mmo" or "coop"
+IsowindHost.pvp = string.lower(values.pvp or "false") == "true"
+IsowindHost.difficulty = math.floor(clamp(values.difficulty, -500, 500, 0))
+IsowindHost.respawnSpeed = clamp(values.respawnSpeed, 0.1, 10, 1)
+IsowindHost.timeSpeed = clamp(values.timeSpeed, 0.1, 10, 1)
+
+function IsowindHost.IsMmo()
+ return IsowindHost.mode == "mmo"
+end
+
+config.gameMode = IsowindHost.mode == "mmo" and "Isowind MMO" or "Isowind co-op"
+config.difficulty = IsowindHost.difficulty
+table.insert(config.gameSettings, { name = "isowind mode", value = IsowindHost.mode })
+table.insert(config.gameSettings, { name = "isowind pvp", value = IsowindHost.pvp })
+
+tes3mp.LogMessage(enumerations.log.INFO, "[Isowind] " .. config.gameMode .. ", PvP " ..
+ (IsowindHost.pvp and "on" or "off") .. ", difficulty " .. IsowindHost.difficulty .. ", respawns x" ..
+ IsowindHost.respawnSpeed .. ", time x" .. IsowindHost.timeSpeed)
+
+-- Morrowind's time of day goes 30 times (40 at night) faster than real time; the host's speed scales both
+customEventHooks.registerHandler("OnServerInit", function(eventStatus)
+ if WorldInstance == nil then
+ return
+ end
+ WorldInstance.data.time.dayTimeScale = config.defaultTimeTable.dayTimeScale * IsowindHost.timeSpeed
+ WorldInstance.data.time.nightTimeScale = config.defaultTimeTable.nightTimeScale * IsowindHost.timeSpeed
+ WorldInstance:UpdateFrametimeMultiplier()
+ WorldInstance:QuicksaveToDrive()
+end)
diff --git a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
new file mode 100644
index 0000000..b983b38
--- /dev/null
+++ b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
@@ -0,0 +1,596 @@
+-- Isowind MMO mode (mode = mmo in the server's [Isowind] settings, see isowindHost.lua).
+--
+-- * Everyone loots for themselves: what a player takes from or puts in a container, a corpse, a plant or ore is
+-- theirs alone (kept per player in the cell's data, isowindLoot, and replayed to them when they load the cell).
+-- Containers players placed stay shared.
+-- * Loose items from the game's files (not ones players dropped) are picked up per player too (isowindTaken).
+-- * Quests, topics, factions, bounties, reputation and kill counts are each player's own.
+-- * Enemies and NPCs come back after they die, once no player is in or next to their cell, after a time from how
+-- tough they were (WoW-like tiers, from their health): trash 1.5 minutes, normal 5, elite 15, bosses 60, divided by
+-- the host's respawn speed. Ones from the game's files are reset on each client ("isowind respawn", a console
+-- command packet the game handles itself); leveled-list ones are spawned again where they first appeared.
+
+if not IsowindHost.IsMmo() then
+ return
+end
+
+config.shareJournal = false
+config.shareTopics = false
+config.shareFactionRanks = false
+config.shareFactionExpulsion = false
+config.shareFactionReputation = false
+config.shareBounty = false
+config.shareReputation = false
+config.shareKills = false
+config.shareVideos = false
+
+local isowindMmo = {}
+
+-- Minutes until an actor comes back, by its maximum health
+local tiers = {
+ { name = "trash", maxHealth = 60, minutes = 1.5 },
+ { name = "normal", maxHealth = 200, minutes = 5 },
+ { name = "elite", maxHealth = 500, minutes = 15 },
+ { name = "boss", minutes = 60 }
+}
+-- Bosses whatever their health
+local bossPatterns = { "^dagoth", "^vivec_god", "^almalexia", "^karstaag", "^lich_", "^heart_akulakhan" }
+
+local CHECK_SECONDS = 10
+
+-- Plants, ore and kwama eggs a player harvested grow back for them after this many minutes (divided by the respawn
+-- speed). Chests don't refill: players keep things in them.
+local REGROW_MINUTES = 10
+local regrowPatterns = { "^flora_", "^rock_", "^egg_kwama" }
+
+-- This session's players (by name): the cells their game has loaded since they logged in, so has their own loot in
+-- it, and what grew back there for them, to give their game when they load it again
+local seenCells = {}
+local regrown = {}
+
+local isAreaEmpty
+
+local function playerKey(pid)
+ return string.lower(Players[pid].accountName)
+end
+
+local function splitIndex(uniqueIndex)
+ local parts = uniqueIndex:split("-")
+ return tonumber(parts[1]), tonumber(parts[2])
+end
+
+local function withCell(cellDescription, callback)
+ local temporary = LoadedCells[cellDescription] == nil
+ if temporary then
+ logicHandler.LoadCell(cellDescription)
+ end
+ local result = callback(LoadedCells[cellDescription])
+ if temporary then
+ logicHandler.UnloadCell(cellDescription)
+ end
+ return result
+end
+
+local function isPlacedByPlayer(cell, uniqueIndex)
+ return tableHelper.containsValue(cell.data.packets.place or {}, uniqueIndex)
+end
+
+local function isActor(cell, uniqueIndex)
+ local objectData = cell.data.objectData[uniqueIndex]
+ return objectData ~= nil and (objectData.deathState ~= nil or objectData.stats ~= nil or objectData.location ~= nil)
+end
+
+-- --- Loot per player ---------------------------------------------------------------------------------------------
+
+local function regrows(refId)
+ refId = string.lower(refId or "")
+ for _, pattern in ipairs(regrowPatterns) do
+ if refId:find(pattern) then
+ return true
+ end
+ end
+ return false
+end
+
+local function getRegrowths()
+ WorldInstance.data.isowindRegrow = WorldInstance.data.isowindRegrow or {}
+ return WorldInstance.data.isowindRegrow
+end
+
+-- When a player's harvest of a plant or ore is due to grow back: once they've only taken from it
+local function scheduleRegrowth(cellDescription, uniqueIndex, refId, name, mine)
+ local regrowths = getRegrowths()
+ local onlyTaken = next(mine) ~= nil
+ for _, item in pairs(mine) do
+ if item.count > 0 then
+ onlyTaken = false
+ end
+ end
+ local cellDue = regrowths[cellDescription] or {}
+ local due = cellDue[uniqueIndex] or {}
+ if onlyTaken and regrows(refId) then
+ due[name] = due[name] or os.time() + math.floor(REGROW_MINUTES * 60 / IsowindHost.respawnSpeed)
+ else
+ due[name] = nil
+ end
+ cellDue[uniqueIndex] = next(due) ~= nil and due or nil
+ regrowths[cellDescription] = next(cellDue) ~= nil and cellDue or nil
+end
+
+-- A Container packet from a player (already read): kept as that player's change, and sent back to them only
+local function saveOwnContainerChange(pid, cell)
+ local action = tes3mp.GetObjectListAction()
+ local name = playerKey(pid)
+ cell.data.isowindLoot = cell.data.isowindLoot or {}
+
+ for objectIndex = 0, tes3mp.GetObjectListSize() - 1 do
+ local uniqueIndex = tes3mp.GetObjectRefNum(objectIndex) .. "-" .. tes3mp.GetObjectMpNum(objectIndex)
+ local record = cell.data.isowindLoot[uniqueIndex]
+ if record == nil then
+ record = { refId = tes3mp.GetObjectRefId(objectIndex), players = {} }
+ cell.data.isowindLoot[uniqueIndex] = record
+ end
+ local mine = record.players[name] or {}
+
+ for itemIndex = 0, tes3mp.GetContainerChangesSize(objectIndex) - 1 do
+ local item = {
+ refId = tes3mp.GetContainerItemRefId(objectIndex, itemIndex),
+ charge = tes3mp.GetContainerItemCharge(objectIndex, itemIndex),
+ enchantmentCharge = tes3mp.GetContainerItemEnchantmentCharge(objectIndex, itemIndex),
+ soul = tes3mp.GetContainerItemSoul(objectIndex, itemIndex)
+ }
+ local change
+ if action == enumerations.container.ADD then
+ change = tes3mp.GetContainerItemCount(objectIndex, itemIndex)
+ else
+ change = -tes3mp.GetContainerItemActionCount(objectIndex, itemIndex)
+ end
+ local key = string.lower(item.refId) .. "|" .. tostring(item.charge) .. "|" ..
+ tostring(item.enchantmentCharge) .. "|" .. tostring(item.soul)
+ local entry = mine[key] or item
+ entry.count = (entry.count or 0) + change
+ if entry.count == 0 then
+ mine[key] = nil
+ else
+ mine[key] = entry
+ end
+ end
+
+ if next(mine) == nil then
+ record.players[name] = nil
+ else
+ record.players[name] = mine
+ end
+ scheduleRegrowth(cell.description, uniqueIndex, record.refId, name, mine)
+ end
+
+ seenCells[name] = seenCells[name] or {}
+ seenCells[name][cell.description] = true
+ cell:QuicksaveToDrive()
+ WorldInstance:QuicksaveToDrive()
+end
+
+local function onContainer(eventStatus, pid, cellDescription, objects)
+ if eventStatus.validDefaultHandler == false then
+ return
+ end
+ local action = tes3mp.GetObjectListAction()
+ local subAction = tes3mp.GetObjectListContainerSubAction()
+ -- Replies to the server's request for what containers hold are the shared, untouched contents
+ if subAction == enumerations.containerSub.REPLY_TO_REQUEST or
+ (action ~= enumerations.container.ADD and action ~= enumerations.container.REMOVE) then
+ return
+ end
+
+ return withCell(cellDescription, function(cell)
+ for objectIndex = 0, tes3mp.GetObjectListSize() - 1 do
+ local uniqueIndex = tes3mp.GetObjectRefNum(objectIndex) .. "-" .. tes3mp.GetObjectMpNum(objectIndex)
+ if isPlacedByPlayer(cell, uniqueIndex) then
+ return
+ end
+ end
+
+ saveOwnContainerChange(pid, cell)
+
+ -- The player's game makes the change when it comes back, unless a script or dialogue already made it
+ local packetOrigin = tes3mp.GetObjectListOrigin()
+ if packetOrigin ~= enumerations.packetOrigin.CLIENT_SCRIPT_LOCAL and
+ packetOrigin ~= enumerations.packetOrigin.CLIENT_SCRIPT_GLOBAL and
+ packetOrigin ~= enumerations.packetOrigin.CLIENT_DIALOGUE then
+ tes3mp.CopyReceivedObjectListToStore()
+ tes3mp.SendContainer(false, false)
+ end
+ return customEventHooks.makeEventStatus(false, true)
+ end)
+end
+
+-- --- Loose items per player --------------------------------------------------------------------------------------
+
+local function onObjectDelete(eventStatus, pid, cellDescription, objects)
+ if eventStatus.validDefaultHandler == false or
+ tes3mp.GetObjectListOrigin() ~= enumerations.packetOrigin.CLIENT_GAMEPLAY then
+ return
+ end
+ local cell = LoadedCells[cellDescription]
+ if cell == nil then
+ return
+ end
+
+ local mine, shared = {}, {}
+ for uniqueIndex, object in pairs(objects) do
+ local _, mpNum = splitIndex(uniqueIndex)
+ if mpNum == 0 and not isActor(cell, uniqueIndex) then
+ mine[uniqueIndex] = object
+ else
+ shared[uniqueIndex] = object
+ end
+ end
+ if next(mine) == nil then
+ return
+ end
+
+ local name = playerKey(pid)
+ cell.data.isowindTaken = cell.data.isowindTaken or {}
+ tes3mp.ClearObjectList()
+ tes3mp.SetObjectListPid(pid)
+ tes3mp.SetObjectListCell(cellDescription)
+ for uniqueIndex, object in pairs(mine) do
+ cell.data.isowindTaken[uniqueIndex] = cell.data.isowindTaken[uniqueIndex] or {}
+ cell.data.isowindTaken[uniqueIndex][name] = true
+ packetBuilder.AddObjectDelete(uniqueIndex, object)
+ end
+ tes3mp.SendObjectDelete(false)
+
+ -- The rest as the default handler does
+ if next(shared) ~= nil then
+ cell:SaveObjectsByPacketType("ObjectDelete", shared)
+ cell:LoadObjectsByPacketType("ObjectDelete", pid, shared, tableHelper.getArrayFromIndexes(shared), true)
+ end
+ cell:QuicksaveToDrive()
+ return customEventHooks.makeEventStatus(false, true)
+end
+
+-- A player loading a cell gets their own loot and pickups there on top of the shared state just sent
+local function onCellLoad(eventStatus, pid, cellDescription)
+ local cell = LoadedCells[cellDescription]
+ if cell == nil or Players[pid] == nil then
+ return
+ end
+ local name = playerKey(pid)
+
+ if cell.data.isowindTaken ~= nil then
+ tes3mp.ClearObjectList()
+ tes3mp.SetObjectListPid(pid)
+ tes3mp.SetObjectListCell(cellDescription)
+ local count = 0
+ for uniqueIndex, takers in pairs(cell.data.isowindTaken) do
+ if takers[name] then
+ packetBuilder.AddObjectDelete(uniqueIndex, {})
+ count = count + 1
+ end
+ end
+ if count > 0 then
+ tes3mp.SendObjectDelete(false)
+ end
+ end
+
+ if cell.data.isowindLoot ~= nil then
+ for _, action in ipairs({ enumerations.container.ADD, enumerations.container.REMOVE }) do
+ tes3mp.ClearObjectList()
+ tes3mp.SetObjectListPid(pid)
+ tes3mp.SetObjectListCell(cellDescription)
+ local objectCount = 0
+ for uniqueIndex, record in pairs(cell.data.isowindLoot) do
+ local mine = record.players[name]
+ if mine ~= nil then
+ local refNum, mpNum = splitIndex(uniqueIndex)
+ tes3mp.SetObjectRefNum(refNum)
+ tes3mp.SetObjectMpNum(mpNum)
+ tes3mp.SetObjectRefId(record.refId)
+ local itemCount = 0
+ for _, item in pairs(mine) do
+ if (item.count > 0) == (action == enumerations.container.ADD) then
+ tes3mp.SetContainerItemRefId(item.refId)
+ tes3mp.SetContainerItemCount(math.abs(item.count))
+ tes3mp.SetContainerItemActionCount(math.abs(item.count))
+ tes3mp.SetContainerItemCharge(item.charge)
+ tes3mp.SetContainerItemEnchantmentCharge(item.enchantmentCharge)
+ tes3mp.SetContainerItemSoul(item.soul)
+ tes3mp.AddContainerItem()
+ itemCount = itemCount + 1
+ end
+ end
+ if itemCount > 0 then
+ tes3mp.AddObject()
+ objectCount = objectCount + 1
+ end
+ end
+ end
+ if objectCount > 0 then
+ tes3mp.SetObjectListAction(action)
+ tes3mp.SendContainer(false, false)
+ end
+ end
+ end
+
+ -- What grew back since their game last had this cell loaded (their game still has it harvested)
+ local grown = regrown[name] ~= nil and regrown[name][cellDescription] or nil
+ if grown ~= nil then
+ tes3mp.ClearObjectList()
+ tes3mp.SetObjectListPid(pid)
+ tes3mp.SetObjectListCell(cellDescription)
+ for uniqueIndex, entry in pairs(grown) do
+ local refNum, mpNum = splitIndex(uniqueIndex)
+ tes3mp.SetObjectRefNum(refNum)
+ tes3mp.SetObjectMpNum(mpNum)
+ tes3mp.SetObjectRefId(entry.refId)
+ for _, item in pairs(entry.items) do
+ tes3mp.SetContainerItemRefId(item.refId)
+ tes3mp.SetContainerItemCount(-item.count)
+ tes3mp.SetContainerItemCharge(item.charge)
+ tes3mp.SetContainerItemEnchantmentCharge(item.enchantmentCharge)
+ tes3mp.SetContainerItemSoul(item.soul)
+ tes3mp.AddContainerItem()
+ end
+ tes3mp.AddObject()
+ end
+ tes3mp.SetObjectListAction(enumerations.container.ADD)
+ tes3mp.SendContainer(false, false)
+ regrown[name][cellDescription] = nil
+ end
+
+ seenCells[name] = seenCells[name] or {}
+ seenCells[name][cellDescription] = true
+end
+
+-- Plants and ore due to grow back, for players not near them: their harvest is forgotten, and a player whose game has
+-- the cell loaded this session gets the plant back the next time they load it
+local function checkRegrowth()
+ local regrowths = getRegrowths()
+ local now = os.time()
+ local changed = false
+ for cellDescription, cellDue in pairs(regrowths) do
+ local ready = {}
+ for uniqueIndex, due in pairs(cellDue) do
+ for name, time in pairs(due) do
+ if time <= now then
+ table.insert(ready, { uniqueIndex = uniqueIndex, name = name })
+ end
+ end
+ end
+ if #ready > 0 and isAreaEmpty(cellDescription) then
+ withCell(cellDescription, function(cell)
+ local loot = cell.data.isowindLoot or {}
+ for _, entry in ipairs(ready) do
+ local record = loot[entry.uniqueIndex]
+ local mine = record ~= nil and record.players[entry.name] or nil
+ if mine ~= nil then
+ record.players[entry.name] = nil
+ if seenCells[entry.name] ~= nil and seenCells[entry.name][cellDescription] then
+ regrown[entry.name] = regrown[entry.name] or {}
+ regrown[entry.name][cellDescription] = regrown[entry.name][cellDescription] or {}
+ regrown[entry.name][cellDescription][entry.uniqueIndex] =
+ { refId = record.refId, items = mine }
+ end
+ end
+ cellDue[entry.uniqueIndex][entry.name] = nil
+ if next(cellDue[entry.uniqueIndex]) == nil then
+ cellDue[entry.uniqueIndex] = nil
+ end
+ end
+ cell:QuicksaveToDrive()
+ end)
+ if next(cellDue) == nil then
+ regrowths[cellDescription] = nil
+ end
+ changed = true
+ end
+ end
+ if changed then
+ WorldInstance:QuicksaveToDrive()
+ end
+end
+
+-- --- Respawns ----------------------------------------------------------------------------------------------------
+
+local function getRespawns()
+ WorldInstance.data.isowindRespawns = WorldInstance.data.isowindRespawns or {}
+ return WorldInstance.data.isowindRespawns
+end
+
+local function respawnMinutes(refId, objectData)
+ refId = string.lower(refId or "")
+ for _, pattern in ipairs(bossPatterns) do
+ if refId:find(pattern) then
+ return tiers[#tiers].minutes
+ end
+ end
+ local health = objectData ~= nil and objectData.stats ~= nil and objectData.stats.healthBase or nil
+ if health == nil then
+ return tiers[2].minutes
+ end
+ for _, tier in ipairs(tiers) do
+ if tier.maxHealth == nil or health < tier.maxHealth then
+ return tier.minutes
+ end
+ end
+end
+
+-- Leveled-list creatures: where they first appeared, to come back there
+local function onObjectSpawn(eventStatus, pid, cellDescription, objects)
+ local cell = LoadedCells[cellDescription]
+ if cell == nil then
+ return
+ end
+ cell.data.isowindSpawnPoints = cell.data.isowindSpawnPoints or {}
+ for uniqueIndex, object in pairs(objects) do
+ if object.summon == nil and object.location ~= nil then
+ cell.data.isowindSpawnPoints[uniqueIndex] = { refId = object.refId, location = object.location }
+ end
+ end
+end
+
+local function onActorDeath(eventStatus, pid, cellDescription, actors)
+ local cell = LoadedCells[cellDescription]
+ if cell == nil then
+ return
+ end
+ local respawns = getRespawns()
+ local now = os.time()
+ for uniqueIndex, actor in pairs(actors) do
+ local objectData = cell.data.objectData[uniqueIndex]
+ local _, mpNum = splitIndex(uniqueIndex)
+ local isSummon = objectData ~= nil and objectData.summon ~= nil
+ local spawnPoints = cell.data.isowindSpawnPoints or {}
+ if not isSummon and (mpNum == 0 or spawnPoints[uniqueIndex] ~= nil) then
+ local minutes = respawnMinutes(actor.refId or (objectData and objectData.refId), objectData)
+ respawns[cellDescription] = respawns[cellDescription] or {}
+ respawns[cellDescription][uniqueIndex] = now + math.floor(minutes * 60 / IsowindHost.respawnSpeed)
+ end
+ end
+ WorldInstance:QuicksaveToDrive()
+end
+
+-- No player in the cell, or (outdoors) in the cells around it that their game has loaded
+function isAreaEmpty(cellDescription)
+ local loaded = LoadedCells[cellDescription]
+ if loaded ~= nil and tableHelper.getCount(loaded.visitors) > 0 then
+ return false
+ end
+ local x, y = cellDescription:match("^(%-?%d+), (%-?%d+)$")
+ for _, player in pairs(Players) do
+ if player:IsLoggedIn() and player.data.location ~= nil then
+ local playerCell = player.data.location.cell
+ if playerCell == cellDescription then
+ return false
+ end
+ if x ~= nil then
+ local px, py = playerCell:match("^(%-?%d+), (%-?%d+)$")
+ if px ~= nil and math.abs(tonumber(px) - tonumber(x)) <= 1 and
+ math.abs(tonumber(py) - tonumber(y)) <= 1 then
+ return false
+ end
+ end
+ end
+ end
+ return true
+end
+
+local function respawnInCell(cellDescription, uniqueIndexes)
+ local fromGameFiles = {}
+ local leveled = {}
+
+ withCell(cellDescription, function(cell)
+ local spawnPoints = cell.data.isowindSpawnPoints or {}
+ for _, uniqueIndex in ipairs(uniqueIndexes) do
+ local objectData = cell.data.objectData[uniqueIndex]
+ local moved = objectData ~= nil and (objectData.cellChangeTo ~= nil or objectData.cellChangeFrom ~= nil)
+ local _, mpNum = splitIndex(uniqueIndex)
+ if not moved then
+ if cell.data.isowindLoot ~= nil then
+ cell.data.isowindLoot[uniqueIndex] = nil
+ end
+ if mpNum == 0 then
+ -- Forgetting its death, wounds, place and inventory brings it back as the game's files have it
+ cell:DeleteObjectData(uniqueIndex)
+ table.insert(fromGameFiles, uniqueIndex)
+ elseif spawnPoints[uniqueIndex] ~= nil then
+ table.insert(leveled, { uniqueIndex = uniqueIndex, spawn = spawnPoints[uniqueIndex] })
+ spawnPoints[uniqueIndex] = nil
+ end
+ end
+ end
+ cell:QuicksaveToDrive()
+ end)
+
+ local anyPid = nil
+ for pid, player in pairs(Players) do
+ if player:IsLoggedIn() then
+ anyPid = pid
+ break
+ end
+ end
+
+ if #fromGameFiles > 0 and anyPid ~= nil then
+ logicHandler.RunConsoleCommandOnObjects(anyPid, "isowind respawn", cellDescription, fromGameFiles, true)
+ end
+
+ for _, entry in ipairs(leveled) do
+ if anyPid ~= nil then
+ logicHandler.DeleteObjectForEveryone(cellDescription, entry.uniqueIndex)
+ else
+ withCell(cellDescription, function(cell) cell:DeleteObjectData(entry.uniqueIndex) end)
+ end
+ local newIndex = logicHandler.CreateObjectAtLocation(cellDescription, entry.spawn.location,
+ { refId = entry.spawn.refId, count = 1, charge = -1, enchantmentCharge = -1, soul = "" }, "spawn")
+ if newIndex ~= nil then
+ withCell(cellDescription, function(cell)
+ cell.data.isowindSpawnPoints = cell.data.isowindSpawnPoints or {}
+ cell.data.isowindSpawnPoints[newIndex] = entry.spawn
+ cell:QuicksaveToDrive()
+ end)
+ end
+ end
+
+ tes3mp.LogMessage(enumerations.log.INFO, "[Isowind] Respawned " .. (#fromGameFiles + #leveled) ..
+ " in " .. cellDescription)
+end
+
+local function checkRespawns()
+ local respawns = getRespawns()
+ local now = os.time()
+ local changed = false
+ for cellDescription, due in pairs(respawns) do
+ local ready = {}
+ for uniqueIndex, time in pairs(due) do
+ if time <= now then
+ table.insert(ready, uniqueIndex)
+ end
+ end
+ if #ready > 0 and isAreaEmpty(cellDescription) then
+ respawnInCell(cellDescription, ready)
+ for _, uniqueIndex in ipairs(ready) do
+ due[uniqueIndex] = nil
+ end
+ if next(due) == nil then
+ respawns[cellDescription] = nil
+ end
+ changed = true
+ end
+ end
+ if changed then
+ WorldInstance:QuicksaveToDrive()
+ end
+end
+
+local respawnTimer = nil
+
+function IsowindMmoRespawnTimer()
+ for _, check in ipairs({ checkRespawns, checkRegrowth }) do
+ local ok, err = pcall(check)
+ if not ok then
+ tes3mp.LogMessage(enumerations.log.ERROR, "[Isowind] Respawn check failed: " .. tostring(err))
+ end
+ end
+ tes3mp.RestartTimer(respawnTimer, time.seconds(CHECK_SECONDS))
+end
+
+-- After the server's own validators (added when it starts), so these see what they decided
+customEventHooks.registerHandler("OnServerPostInit", function(eventStatus)
+ customEventHooks.registerValidator("OnContainer", onContainer)
+ customEventHooks.registerValidator("OnObjectDelete", onObjectDelete)
+ customEventHooks.registerHandler("OnCellLoad", onCellLoad)
+ customEventHooks.registerHandler("OnObjectSpawn", onObjectSpawn)
+ customEventHooks.registerHandler("OnActorDeath", onActorDeath)
+ -- A player who logs in again starts with a game that hasn't loaded any cell
+ customEventHooks.registerValidator("OnPlayerDisconnect", function(eventStatus, pid)
+ if Players[pid] ~= nil then
+ seenCells[playerKey(pid)] = nil
+ regrown[playerKey(pid)] = nil
+ end
+ end)
+ respawnTimer = tes3mp.CreateTimer("IsowindMmoRespawnTimer", time.seconds(CHECK_SECONDS))
+ tes3mp.StartTimer(respawnTimer)
+end)
+
+return isowindMmo
diff --git a/isowind/server/CoreScripts/scripts/customScripts.lua b/isowind/server/CoreScripts/scripts/customScripts.lua
index 5887d5b..f8e9148 100644
--- a/isowind/server/CoreScripts/scripts/customScripts.lua
+++ b/isowind/server/CoreScripts/scripts/customScripts.lua
@@ -5,3 +5,6 @@
-- Refer to the Tutorial.md file for information on how to use various event and command hooks in your scripts.
+
+require("custom/isowindHost")
+require("custom/isowindMmo")
diff --git a/isowind/server/tes3mp-server-default.cfg b/isowind/server/tes3mp-server-default.cfg
index ce44f20..6eca2c8 100644
--- a/isowind/server/tes3mp-server-default.cfg
+++ b/isowind/server/tes3mp-server-default.cfg
@@ -10,6 +10,19 @@ logLevel = 1
# Leave empty for no password; players then type it at login
password =
+[Isowind]
+# Isowind.exe's "Host a server" (or "isowind.sh host") puts your choices in tes3mp-server.cfg, over these.
+# coop: one shared world, as in single player. mmo: everyone loots and quests for themselves, and enemies respawn
+mode = coop
+# Whether players can hurt each other
+pvp = false
+# -100 (very easy) to 100 (very hard); 0 is Morrowind's normal
+difficulty = 0
+# MMO: how much faster than normal enemies come back (normal: 1.5 minutes for the weakest to 60 for bosses)
+respawnSpeed = 1
+# How much faster than Morrowind's the time of day goes (Morrowind's: an hour in 2 minutes)
+timeSpeed = 1
+
[Plugins]
home = ./CoreScripts
plugins = serverCore.lua