Create affectors, terrain bonuses, buffs and debuffs, timed wave effects; anything that needs to be modified by multiple dynamic external sources. Modifiers can perform more than one action, and in future can affect other modifiers.
This is for organizing your game character/vehicle statistics, damage calculators, or content processors into a structural serializable list which can handle the calculations.
A modifier (MDF) is a class used by my game to affect values. The values are derived from a base or derived from an object or entity, clamped in a valid range, manipulated by a simple calculation and can optionally affect elements such as sound and objects. For example, if the player is in a certain zone, its defensive skill could be boosted; or a particle effect used could have its emitter tank size modified by the impact skill of its source.
In version 0.2 currently it is mainly focusing on managing values and interacting with objects and sounds.
Usage requires Matrix1, and will likely require Advanced2D in future updates. You will need to be pretty experienced to grasp this stuff.
Commands
AddMdf()
Adds an uninitialized modifier into the MDF array.
The array count is not identical to the number of modifiers that are initialized.
This array expands by 100 by default when it has no space to hold a new modifier. To speed up adding 100s of modifiers, set constant MODIFIER_EXPANSION_SIZE to a higher number. To save RAM, lower it.
RETURNS new ID which is identical to the global; NewMdf. This should be identical to the number of added modifiers with this command.
MakeMdf()
Creates a modifier which stores its current value in MDF(id).v#, which is the first field for ease with array sorting.
Providing the modifier is updated, the v# value will be set to the base value, clamped to the modifiers limit and affected by the following parameters:
//----------------------------
` Make a modifier with parameters:
` -- Base value for the skill/property
` -- Minimum value
` -- Maximum value
` -- Name for code reference
` -- Caption for third party GUI; eg Skill tables, hints etc
` ---- The next two properties requires understanding of Matrix1 Bit commands
` ---- Particularly Bit Intersect Mask which combines settings
` -- Read mode : See bM_Modifier_CONSTANTS
` -- This is a 64 bit integer storing optional sources of data to apply to the modifier. EG: Read object position
` -- Write mode : See bM_Modifier_CONSTANTS
` -- This is a 64 bit integer storing optional targets of data to apply to the modifier EG: Write sound pan
SetMdfWave
This will animate the value of the modifier with a sine wave animated over time. Could be used to modulate sound.
Create affectors, terrain bonuses, buffs and debuffs, timed wave effects; anything that needs to be modified by multiple dynamic external sources. Modifiers can perform more than one action, and in future will affect other modifiers.
A modifier (MDF) is a class used by my game to affect values. The values are derived from a base or derived from an object or entity, clamped in a valid range, manipulated by a simple calculation and can optionally affect elements such as sound and objects. For example, if the player is in a certain zone, its defensive skill could be boosted; or a particle effect used could have its emitter tank size modified by the impact skill of its source.
In version 0.2 currently it is mainly focusing on managing values and interacting with objects and sounds.
Usage requires Matrix1, and will likely require Advanced2D in future updates. You will need to be pretty experienced to grasp this stuff.
GOSUB InitModifiers to initiate the system
Commands
AddMdf()
Adds an uninitialized modifier into the MDF array.
The array count is not identical to the number of modifiers that are initialized.
This array expands by 100 by default when it has no space to hold a new modifier. To speed up adding 100s of modifiers, set constant MODIFIER_EXPANSION_SIZE to a higher number. To save RAM, lower it.
RETURNS new ID which is identical to the global; NewMdf. This should be identical to the number of added modifiers with this command.
MakeMdf()
Creates a modifier which stores its current value in MDF(id).v#, which is the first field for ease with array sorting.
Providing the modifier is updated, the v# value will be set to the base value, clamped to the modifiers limit and affected by the following parameters:
Quote: "` Make a modifier with parameters:
` -- Base value for the skill/property
` -- Minimum value
` -- Maximum value
` -- Name for code reference
` -- Caption for PrintMDF, MDF$ functions and third party GUI;
` ---- EG Skill tables, hints etc
` The next two properties requires understanding of Matrix1 Bit commands
` Particularly Bit Intersect Mask which combines settings
` -- Read mode : See bM_Modifier_CONSTANTS
` -- This is a 64 bit integer storing optional sources of data to apply to the modifier. EG: Read object position
` -- Write mode : See bM_Modifier_CONSTANTS
` -- This is a 64 bit integer storing optional targets of data to apply to the modifier EG: Write sound pan
` Create a modifier which affects an objects X position and rotation
` Only one axis can be writen or read by a single modifier
` But it can read/write positions, angles, scales etc all at once
"
SetMdfWave
This will animate the value of the modifier with a sine wave animated over time. Could be used to modulate sound.
The wave speed is how long it takes to complete the wave. A speed of 1.0 is equal to one per second, 0.5 is half per second and 2.0 is twice per second.
SetMdfObjs
Sets the read and write object of the modifier. Both are optional, but must exist if id specified is greater than zero, otherwise an error will occur
The possible modifications are specified in the constants file.
The objects will not be affected unless you apply write flags, see the example.
Object reads are added to the base and alteration properties; For example if an objects scale is 100 and the base is 50 and the alteration is 50, the v# value will then equal to 200 before being clamped into range.
SetMdfToDefault
Sets the modifier to default and in initialized state which currently is identical to assigning the DefaultMDF global, which you can adjust.
UpdateAllModifiers
Will update all modifiers, from 1 to the newest (NewMDF). Additionally you can call UpdateModifiers(first, last) for a range, or UpdateModifier( id ) for a single update.
MDF$
Returns the caption and value of the modifier as a string with number of decimal places specified in Decimals property.
PrintMDF
Prints the caption and value of the modifier as a string with number of decimal places specified in Decimals property.
Misc
Base
This is the basis of the modifier, which could be the base skill of a character or starting point of an animation
Alteration
The alteration# property is added to the base#, which are assigned to the v# value before calculation. To add a temporary bonus, set alteration to a positive value; set it to negative for a deficit.
Bias
ObjWriteBias# property will be added to modifier value, which is then added to the property you are writing to the object
ObjReadBias# property will be added to object property being read, which is then added to the modifier value base value. Note that at this point, the value is the modifiers base + alteration + object property + ObjReadBias; the final result is clamped in the set range.
Inverse
Set the inverse property to true to the set v# values final result to its reverse, which is the maximum minus the positive result.
Handling
You could handle a modifiers affect on objects or sounds directly by calling HandleModifierObjWrite(), HandleModifierSoundVolWrite() or similar functions. This enables you to supply different read/write actions. The object/sound stored in the MDF type instance is still the target, but could easily be changed. Handling wave modifiers gives you control over the scale of the wave if you do not want to alter
the property field
Enabling/Disabling
Set enabled to 0 to disable the updating of the modifier, even if called explicitly with UpdateModifier() instead of UpdateAllModifiers().
Bit clear MDF_READ or MDF_WRITE in MDF(m).Options to disable reading or writing respectively
Example code
Requires attached project and media
`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\///////////////////////////////////////////
` \\\ B I N A R Y M O D U L A R ///
` \\\ ///
` \\\=====================================================================///
` ||| M o d i f i e r s |||
` |||--------------------------------------------------------------------|||
` ||| v 0.2 |||
` |||====================================================================|||
` /// © 2013 \\\
` /// \\\
`||| __________________________________________________________ |||
`||| INFO: Animated, bonuse, buff-debuff value setter |||
`||| __________________________________________________________ |||
`||| AUTHOR: Chris Tate |||
`||| __________________________________________________________ |||
`||| WEBSITE: www.binarymodular.com | www.sportsfiction.net |||
`||| __________________________________________________________ |||
`||| EMAIL: Chris Tate |||
`||| __________________________________________________________ |||
`||| TERMS: Free for personal or commercial use. |||
`||| __________________________________________________________ |||
` \\\ __________________________________________________________ ///
` \\\ ///
` \\\====================================================================///
` INSTALLATION: Include all attached DBA files and gosub InitModifiers before use
` Remove DEBUG print statements
` Call UpdateAllModifiers() every loop or few seconds depending on desired rate
` or call UpdateModifiers( first, last ) for a range
` or call UpdateModifier( id ) to handle updates yourself
/////////////////////////////////////////////////////////////////
` Personal notes
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// LOW LEVEL SOURCE - NO CALLS TO GENERICS OR OTHER LIBRARIES //
/////////////////////////////////////////////////////////////////
` End of personal notes
/////////////////////////////////////////////////////////////////
Type ModifierType
v#
Base#
Inverse as Boolean
Max#
Min#
Initialized as Boolean
Updated as Boolean
UpdateOncePerLoop as Boolean
ReadMode as Double Integer
WriteMode as Double Integer
Options as Double Integer
Enabled as Boolean
Switches as Double Integer
CutOffs as Double Integer
Alteration#
Multiplier#
ObjReadBias#
ObjWriteBias#
Read
Write
ReadLimb
ReadObj
WriteObj
WriteLimb
Owner
Group as Word
DisabledValue#
AddBank
AddCount
SubBank
SubCount
DivBank
DivCount
MulBank
MulCount
LastWaveTime
Wave#
WaveSize#
WaveStep#
WaveSpeed#
Seek#
Curve#
CurveSpeed#
Decimals as Byte
Name$
Caption$
Endtype
Gosub InitModifiers
RunModifierTest()
End
//===================================================================
InitModifiers:
#CONSTANT MODIFIER_EXPANSION_SIZE 100
Global Dim Mdf(MODIFIER_EXPANSION_SIZE) as ModifierType
Global Dim MakeMdfArr(0) as ModifierType
Global NewMdf = 0
Global DefaultMDF as ModifierType
DefaultMDF.Initialized = 1
DefaultMDF.Options = 0
DefaultMDF.Options = Bit Set( DefaultMDF.Options, MDF_READ )
DefaultMDF.Options = Bit Set( DefaultMDF.Options, MDF_WRITE )
DefaultMDF.Enabled = 1
DefaultMDF.Multiplier# = 1.0
DefaultMDF.Min# = -9999999
DefaultMDF.Max# = 9999999
Return
//===================================================================
Function RunModifierTest()
` Setup a test program.
Sync On : Sync Rate 60
` Loop a sound we intend to control with a modifier
s = Reserve Free Sound()
Load Sound "3d_Event1.wav", s
Loop sound s
` Create objects we intend to control with a modifier
Make Object Cube 1, 5
Make Object Sphere 2, 1.3
Color Object 1, Rgb(255,0,0)
Color Object 2, Rgb(0,0,255)
Autocam Off
Make Matrix 1, 50, 50, 10, 10
Position Matrix 1, -25, 0, -25
Position Matrix 1, -25, -6, -25
Position Camera 0, 3,-25
Point Camera 0, 0, 0
Color Backdrop RGB(80,80,80)
//----------------------------
` Make a modifier with parameters:
` -- Base value for the skill/property
` -- Minimum value
` -- Maximum value
` -- Name for code reference
` -- Caption for PrintMDF, MDF$ functions and third party GUI;
` ---- EG Skill tables, hints etc
` The next two properties requires understanding of Matrix1 Bit commands
` Particularly Bit Intersect Mask which combines settings
` -- Read mode : See bM_Modifier_CONSTANTS
` -- This is a 64 bit integer storing optional sources of data to apply to the modifier. EG: Read object position
` -- Write mode : See bM_Modifier_CONSTANTS
` -- This is a 64 bit integer storing optional targets of data to apply to the modifier EG: Write sound pan
` Create a modifier which affects an objects X position and rotation
` Only one axis can be writen or read by a single modifier
` But it can read/write positions, angles, scales etc all at once
m = MakeMdf(0,-100,100,"Object Movement","Object Movement: ", 0, Bit Set ( Bit Set( 0, MDF_WRITE_OBJ_ANG_X ), MDF_WRITE_OBJ_POS_X ) )
` Animate the modifier with a wave at the speed of 0.5, and move the object by 25 either way
SetMdfWave(m, 0.5, 25.0)
` Set its read object to nothing, but its right object to object 1
SetMdfObjs(m,0,1)
` Make another modifier to have the object's position affect the sound volume
ms = MakeMdf(0,0,100,"","Sound Volume: ", Bit Set( 0, MDF_READ_OBJ_POS_X), Bit Set( 0, MDF_WRITE_SOUND_VOL ) )
` This time we set the read object; we could have also written to another object but did not.
SetMdfObjs(ms,1,0)
` The system requires the sound ID to stored in the write property
MDF(ms).Write = s
` A multiplier is used to multiply the result; could be used as a bonus multiplier
MDF(ms).Multiplier# = 12.0
Do
Set Cursor 0,0
Print Screen FPS()
Print "Set sound volume for "; s; " to "; Max(0, Mdf(ms).v#)
PrintMDF(m)
PrintMDF(ms)
Control Camera Using ArrowKeys 0, 1, 2
UpdateAllModifiers()
Sync
Loop
Endfunction
Version 0.2