Skip to content

Commit 0d4bff8

Browse files
committed
Merge branch 'data-mw' into 'master'
Move Morrowind mechanics to data-mw See merge request OpenMW/openmw!4937
2 parents 2a63ec6 + f0b7fec commit 0d4bff8

File tree

21 files changed

+412
-348
lines changed

21 files changed

+412
-348
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
8282
set(OPENMW_VERSION_MAJOR 0)
8383
set(OPENMW_VERSION_MINOR 51)
8484
set(OPENMW_VERSION_RELEASE 0)
85-
set(OPENMW_LUA_API_REVISION 102)
85+
set(OPENMW_LUA_API_REVISION 103)
8686
set(OPENMW_POSTPROCESSING_API_REVISION 3)
8787

8888
set(OPENMW_VERSION_COMMITHASH "")

docs/source/luadoc_data_paths.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ paths=(
22
openmw_aux/*lua
33
scripts/omw/activationhandlers.lua
44
scripts/omw/ai.lua
5-
scripts/omw/combat/local.lua
5+
scripts/omw/combat/interface.lua
66
scripts/omw/input/playercontrols.lua
77
scripts/omw/mechanics/animationcontroller.lua
88
scripts/omw/input/gamepadcontrols.lua

docs/source/reference/lua-scripting/interface_combat.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ Interface Combat
44
.. include:: version.rst
55

66
.. raw:: html
7-
:file: generated_html/scripts_omw_combat_local.html
7+
:file: generated_html/scripts_omw_combat_interface.html
88

files/data-mw/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,29 @@ set(BUILTIN_DATA_MW_FILES
2020

2121
# Game-specific settings for calendar.lua
2222
openmw_aux/calendarconfig.lua
23+
24+
scripts/omw/cellhandlers.lua
25+
scripts/omw/combat/common.lua
26+
scripts/omw/combat/global.lua
27+
scripts/omw/combat/local.lua
28+
scripts/omw/combat/menu.lua
29+
scripts/omw/music/helpers.lua
30+
scripts/omw/music/music.lua
31+
scripts/omw/music/settings.lua
32+
scripts/omw/playerskillhandlers.lua
2333
)
2434

2535
foreach (f ${BUILTIN_DATA_MW_FILES})
2636
copy_resource_file("${CMAKE_CURRENT_SOURCE_DIR}/${f}" "${OPENMW_RESOURCES_ROOT}" "resources/vfs-mw/${f}")
2737
endforeach (f)
38+
39+
# Concat data/builtin.omwscripts and data-mw/builtin.omwscripts.in to create vfs-mw/builtin.omwscripts
40+
set(builtinBase "${CMAKE_CURRENT_SOURCE_DIR}/../data/builtin.omwscripts")
41+
42+
# https://gitlab.kitware.com/cmake/cmake/-/issues/20181
43+
if (NOT CMAKE_GENERATOR MATCHES "Ninja")
44+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${builtinBase}")
45+
endif()
46+
47+
file(READ "${builtinBase}" BUILTIN_SCRIPTS)
48+
configure_resource_file("${CMAKE_CURRENT_SOURCE_DIR}/builtin.omwscripts.in" "${OPENMW_RESOURCES_ROOT}" "resources/vfs-mw/builtin.omwscripts")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@BUILTIN_SCRIPTS@
2+
3+
# Game specific scripts to append to builtin.omwscripts
4+
GLOBAL: scripts/omw/cellhandlers.lua
5+
GLOBAL: scripts/omw/combat/global.lua
6+
MENU: scripts/omw/combat/menu.lua
7+
NPC,CREATURE,PLAYER: scripts/omw/combat/local.lua
8+
PLAYER: scripts/omw/music/music.lua
9+
MENU: scripts/omw/music/settings.lua
10+
PLAYER: scripts/omw/playerskillhandlers.lua
File renamed without changes.
File renamed without changes.
File renamed without changes.

files/data/scripts/omw/combat/local.lua renamed to files/data-mw/scripts/omw/combat/local.lua

Lines changed: 16 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
local animation = require('openmw.animation')
2-
local async = require('openmw.async')
31
local core = require('openmw.core')
42
local I = require('openmw.interfaces')
53
local self = require('openmw.self')
64
local storage = require('openmw.storage')
75
local types = require('openmw.types')
8-
local util = require('openmw.util')
9-
local auxUtil = require('openmw_aux.util')
106
local Actor = types.Actor
11-
local Weapon = types.Weapon
127
local Player = types.Player
138
local Creature = types.Creature
149
local Armor = types.Armor
10+
local auxUtil = require('openmw_aux.util')
1511
local isPlayer = Player.objectIsInstance(self)
1612

1713
local godMode = function() return false end
@@ -20,8 +16,6 @@ if isPlayer then
2016
godMode = function() return require('openmw.debug').isGodMode() end
2117
end
2218

23-
local onHitHandlers = {}
24-
2519
local settings = storage.globalSection('SettingsOMWCombat')
2620

2721
local function getSkill(actor, skillId)
@@ -271,16 +265,13 @@ local function spawnBloodEffect(position)
271265
end
272266

273267
local function onHit(data)
274-
if auxUtil.callEventHandlers(onHitHandlers, data) then
275-
return
276-
end
277268
if data.successful and not godMode() then
278269
I.Combat.applyArmor(data)
279270
I.Combat.adjustDamageForDifficulty(data)
280271
if getDamage(data, 'health') > 0 then
281272
core.sound.playSound3d('Health Damage', self)
282273
if data.hitPos then
283-
spawnBloodEffect(data.hitPos)
274+
I.Combat.spawnBloodEffect(data.hitPos)
284275
end
285276
end
286277
elseif data.attacker and Player.objectIsInstance(data.attacker) then
@@ -289,142 +280,20 @@ local function onHit(data)
289280
Actor._onHit(self, data)
290281
end
291282

292-
---
293-
-- Table of possible attack source types
294-
-- @type AttackSourceType
295-
-- @field #string Magic
296-
-- @field #string Melee
297-
-- @field #string Ranged
298-
-- @field #string Unspecified
299-
300-
---
301-
-- @type AttackInfo
302-
-- @field [parent=#AttackInfo] #table damage A table mapping a stat name (health, fatigue, or magicka) to a number. For example, {health = 50, fatigue = 10} will cause 50 damage to health and 10 to fatigue (before adjusting for armor and difficulty). This field is ignored for failed attacks.
303-
-- @field [parent=#AttackInfo] #number strength A number between 0 and 1 representing the attack strength. This field is ignored for failed attacks.
304-
-- @field [parent=#AttackInfo] #boolean successful Whether the attack was successful or not.
305-
-- @field [parent=#AttackInfo] #AttackSourceType sourceType What class of attack this is.
306-
-- @field [parent=#AttackInfo] openmw.self#ATTACK_TYPE type (Optional) Attack variant if applicable. For melee attacks this represents chop vs thrust vs slash. For unarmed creatures this implies which of its 3 possible attacks were used. For other attacks this field can be ignored.
307-
-- @field [parent=#AttackInfo] openmw.types#Actor attacker (Optional) Attacking actor
308-
-- @field [parent=#AttackInfo] openmw.types#Weapon weapon (Optional) Attacking weapon
309-
-- @field [parent=#AttackInfo] #string ammo (Optional) Ammo record ID
310-
-- @field [parent=#AttackInfo] openmw.util#Vector3 hitPos (Optional) Where on the victim the attack is landing. Used to spawn blood effects. Blood effects are skipped if nil.
311-
return {
312-
--- Basic combat interface
313-
-- @module Combat
314-
-- @usage require('openmw.interfaces').Combat
315-
--
316-
--I.Combat.addOnHitHandler(function(attack)
317-
-- -- Adds fatigue loss when hit by draining fatigue when taking health damage
318-
-- if attack.damage.health and not attack.damage.fatigue then
319-
-- local strengthFactor = Actor.stats.attributes.strength(self).modified / 100 * 0.66
320-
-- local enduranceFactor = Actor.stats.attributes.endurance(self).modified / 100 * 0.34
321-
-- local factor = 1 - math.min(strengthFactor + enduranceFactor, 1)
322-
-- if factor > 0 then
323-
-- attack.damage.fatigue = attack.damage.health * factor
324-
-- end
325-
-- end
326-
--end)
283+
I.Combat.addOnHitHandler(onHit)
327284

328-
interfaceName = 'Combat',
329-
interface = {
330-
--- Interface version
331-
-- @field [parent=#Combat] #number version
332-
version = 1,
333-
334-
--- Add new onHit handler for this actor
335-
-- If `handler(attack)` returns false, other handlers for
336-
-- the call will be skipped. Where attack is the same @{#AttackInfo} passed to #Combat.onHit
337-
-- @function [parent=#Combat] addOnHitHandler
338-
-- @param #function handler The handler.
339-
addOnHitHandler = function(handler)
340-
onHitHandlers[#onHitHandlers + 1] = handler
341-
end,
342-
343-
--- Calculates the character's armor rating and adjusts damage accordingly.
344-
-- Note that this function only adjusts the number, use #Combat.applyArmor
345-
-- to include other side effects.
346-
-- @function [parent=#Combat] adjustDamageForArmor
347-
-- @param #number Damage The numeric damage to adjust
348-
-- @param openmw.core#GameObject actor (Optional) The actor to calculate the armor rating for. Defaults to self.
349-
-- @return #number Damage adjusted for armor
350-
adjustDamageForArmor = function(damage, actor) return adjustDamageForArmor(damage, actor or self) end,
351-
352-
--- Calculates a difficulty multiplier based on the current difficulty settings
353-
-- and adjusts damage accordingly. Has no effect if both this actor and the
354-
-- attacker are NPCs, or if both are Players.
355-
-- @function [parent=#Combat] adjustDamageForDifficulty
356-
-- @param #Attack attack The attack to adjust
357-
-- @param openmw.core#GameObject defendant (Optional) The defendant to make the difficulty adjustment for. Defaults to self.
358-
adjustDamageForDifficulty = function(attack, defendant) return adjustDamageForDifficulty(attack, defendant or self) end,
359-
360-
--- Applies this character's armor to the attack. Adjusts damage, reduces item
361-
-- condition accordingly, progresses armor skill, and plays the armor appropriate
362-
-- hit sound.
363-
-- @function [parent=#Combat] applyArmor
364-
-- @param #Attack attack
365-
applyArmor = applyArmor,
366-
367-
--- Computes this character's armor rating.
368-
-- Note that this interface function is read by the engine to update the UI.
369-
-- This function can still be overridden same as any other interface, but must not call any functions or interfaces that modify anything.
370-
-- @function [parent=#Combat] getArmorRating
371-
-- @param openmw.core#GameObject actor (Optional) The actor to calculate the armor rating for. Defaults to self.
372-
-- @return #number
373-
getArmorRating = function(actor) return getArmorRating(actor or self) end,
374-
375-
--- Computes this character's armor rating.
376-
-- You can override this to return any skill you wish (including non-armor skills, if you so wish).
377-
-- Note that this interface function is read by the engine to update the UI.
378-
-- This function can still be overridden same as any other interface, but must not call any functions or interfaces that modify anything.
379-
-- @function [parent=#Combat] getArmorSkill
380-
-- @param openmw.core#GameObject item The item
381-
-- @return #string The armor skill identifier, or unarmored if the item was nil or not an instace of @{openmw.types#Armor}
382-
getArmorSkill = getArmorSkill,
383-
384-
--- Computes the armor rating of a single piece of @{openmw.types#Armor}, adjusted for skill
385-
-- Note that this interface function is read by the engine to update the UI.
386-
-- This function can still be overridden same as any other interface, but must not call any functions or interfaces that modify anything.
387-
-- @function [parent=#Combat] getSkillAdjustedArmorRating
388-
-- @param openmw.core#GameObject item The item
389-
-- @param openmw.core#GameObject actor (Optional) The actor, defaults to self
390-
-- @return #number
391-
getSkillAdjustedArmorRating = function(item, actor) return getSkillAdjustedArmorRating(item, actor or self) end,
392-
393-
--- Computes the effective armor rating of a single piece of @{openmw.types#Armor}, adjusted for skill and item condition
394-
-- @function [parent=#Combat] getEffectiveArmorRating
395-
-- @param openmw.core#GameObject item The item
396-
-- @param openmw.core#GameObject actor (Optional) The actor, defaults to self
397-
-- @return #number
398-
getEffectiveArmorRating = function(item, actor) return getEffectiveArmorRating(item, actor or self) end,
399-
400-
--- Spawns a random blood effect at the given position
401-
-- @function [parent=#Combat] spawnBloodEffect
402-
-- @param openmw.util#Vector3 position
403-
spawnBloodEffect = spawnBloodEffect,
404-
405-
--- Hit this actor. Normally called as Hit event from the attacking actor, with the same parameters.
406-
-- @function [parent=#Combat] onHit
407-
-- @param #AttackInfo attackInfo
408-
onHit = onHit,
409-
410-
--- Picks a random armor slot and returns the item equipped in that slot.
411-
-- Used to pick which armor to damage / skill to increase when hit during combat.
412-
-- @function [parent=#Combat] pickRandomArmor
413-
-- @param openmw.core#GameObject actor (Optional) The actor to pick armor from, defaults to self
414-
-- @return openmw.core#GameObject The armor equipped in the chosen slot. nil if nothing was equipped in that slot.
415-
pickRandomArmor = function(actor) return pickRandomArmor(actor or self) end,
416-
417-
--- @{#AttackSourceType}
418-
-- @field [parent=#Combat] #AttackSourceType ATTACK_SOURCE_TYPES Available attack source types
419-
ATTACK_SOURCE_TYPES = {
420-
Magic = 'magic',
421-
Melee = 'melee',
422-
Ranged = 'ranged',
423-
Unspecified = 'unspecified',
424-
},
425-
},
285+
local interface = auxUtil.shallowCopy(I.Combat)
286+
interface.adjustDamageForArmor = function(damage, actor) return adjustDamageForArmor(damage, actor or self) end
287+
interface.adjustDamageForDifficulty = function(attack, defendant) return adjustDamageForDifficulty(attack, defendant or self) end
288+
interface.applyArmor = applyArmor
289+
interface.getArmorRating = function(actor) return getArmorRating(actor or self) end
290+
interface.getArmorSkill = getArmorSkill
291+
interface.getSkillAdjustedArmorRating = function(item, actor) return getSkillAdjustedArmorRating(item, actor or self) end
292+
interface.getEffectiveArmorRating = function(item, actor) return getEffectiveArmorRating(item, actor or self) end
293+
interface.spawnBloodEffect = spawnBloodEffect
294+
interface.pickRandomArmor = function(actor) return pickRandomArmor(actor or self) end
426295

427-
eventHandlers = {
428-
Hit = function(data) I.Combat.onHit(data) end,
429-
},
296+
return {
297+
interfaceName = 'Combat',
298+
interface = interface
430299
}

0 commit comments

Comments
 (0)