Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - [Matrix1] Modifiers

Author
Message
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 23rd Jan 2013 19:41 Edited at: 24th Jan 2013 05:30
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:


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



Version 0.2

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-02-26 01:56:04
Your offset time is: 2024-02-26 01:56:04