Code:
[+] Added new receiver !!RD for managing recruit dialog and a few new events.
Whenever recruit dialog is created, an event "OnOpenRecruitDlg" is triggered with the following parameters:
x1 - selected/active monster slot (0..3)
x2 - flags/options. Combination of bits, controlling dialog behavior:
CLOSE_ON_BUY = 1; Dialog should be closed, when buy button is clicked. Used normally in towns
ir when there is only single recruit slot. Unset this flag to force use to manually close dialog.
AUTO_UPDATE_ADVMAP = 2; Adventure map screen should be updated after any recruit is hired (even when dialog is shown).
This flag is used during hiring recruits from adv. map dwellings, allowing player to see
new creature quantities in the right bottom info screen.
x3 - enable dialog = 1. Set to 0 to not show dialog at all.
When recruit dialog is closed, an appropriate "OnCloseRecruitDlg" is trigger without parameters.
When dialog slider is touched or active slot changed, recalculation of number of monsters to hire
and total costs is performed in "OnRecruitDlgRecalc" event. All parameters can be changed.
x1 - creature cost in gold
x2 - resource ID (0..5) or -1
x3 - resource cost
Dialog was modified to allow zero gold/resource cost.
When a few recruits are hired, "OnRecruitDlgAction" is triggered.
x1 - number of hired creatures. Read-only.
!!RD:C#slot/$type[/$num/$sourceId/#0 = use original number]; Configurate dialog
===============================================================================
#slot - dialog slot index (0..3)
$type - creature type to hire in specified slot or -1 for inactive slot.
$num - current number of creatures to hire. If the last parameter is 0, then it's original number
of monsters to hire, remembered right after "OnOpenRecruitDlg" event (get syntax only).
Number of creatures is usually directly binded to some source, like town creature dwelling.
Thus, settings this value in configuration phase, you change real creature quantity.
$sourceId - the source/memory, where available number of creatures is stored.
>> For existing towns on the map the following sourceId formula can be used:
Town ID * 14 + (town creature dwelling 0..6) + (7 for upgraded only), where Town ID is CA:U.
For instance, the source of second town on the map, 3-d upgraded dwelling is: 1 * 14 + 3 + 7 = 24.
>> If dialog is called with special, programmer-defined external sources, they will have the following IDs:
9000, 9001, 9002, 9003. For instance, mod maker implemented custom dwelling in town and has some memory,
where number of creatures for hiring is stored. Script writers will be able to see such sourceId as 9000.
>> Custom source. sourceId >= 10000. User-scripted implementation.
When custom source is used, unique memory block is allocated for it. Do not forget to set initial
value in "OnOpenRecruitDlg" and get final (remaining) value in "OnCloseRecruitDlg".
Same sourceId may be assigned to any number of dialog slots. All those slots will display same
creature quantity and update simultaneously. This is usefull for alternative creatures implementation.
Slots may have different creature types (and costs), but total amount of recruits is shared between all
slots.
SourceId is changed before applying new monsters number. Thus !!RD:C0/13/100/20000 will change
sourceId to 20000 (custom) first and then set monsters quantity to 100 archangels, without changing
original dwelling/object/etc population.
You can set slot 0 and 3 types to some values and slot 1 and 2 types to -1. Free space will collapse and user
will see only two slots.
Dialogs without working slots (creature type <> -1) will not be shown.
Example: !!RD:C2/?y3; y3 is creature type is 3-d dialog logical slot
!!RD:S#offset; Shift slots
===============================================================================
#offset - shift all slots by this value to the right (positive number) or to the left (negative number).
If slot goes outside of 0..3 indexes, it disappears.
Example: given 0..1 slots with normal and upgraded creatures and any sourceIds. Task: prepend two custom slots
with angels/archangels to them.
!!RD:S2 C0/12/2/12345 C1/13/2/54321;
Before:
[creatures A] [creatures B] [empty slot] [empty slot]
After:
[2 angels] [2 archangels] [creatures A] [creatures B]
Shifting is performed will all settings (number, type, sourceId) preserved.
Example 2: remove first slot with upgraded monsters and leave non upgraded only.
!!RD:C0/?t/?t/?y2; y2 is sourceId for slot 0, t - temp global quick var
!!VRy2:%14; y2 - is dwelling index 0..13, 7+ for upgraded
!!RD&y2>=7:S-1; shift one slot to the left if the first slot is upgraded town dwelling
!!RD:F#visualSlot/?$logicalSlot; Convert visual dialog slot index to logical one (used with !!RD:C)
===============================================================================
#visualSlot - visible slot index (0..3)
?$logicalSlot - logical slot index (0..3 or -1)
Command used together with mouse handling in recruit dialog. Visible slot IDs are monotonically
increasing and need to be converted to logical slot IDs.
Example:
[creature A] [empty slot] [empty slot] [creature B]
is displayed as
[creature A] [creature B], where creature B has visual slot index 1 and logical slot index 3
!!RD:I?$dialogId[/?$townId/?$dwellingId/?$selectedSlot]; Get current dialog Info
===============================================================================
?$dialogId - Unique recruit dialog ID. Used to distinguish between nested dialogs (yep, it's possible). Reusable.
?$townId - ID of town, for which dialog is opened or -1.
?dwellingId - ID of town dwelling, for which dialog is opened or -1. 0..6 non upgraded, 7..13 for upgraded.
Horde buildings (+X population) are treated as dwellings, they influence.
?$selectedSlot - Active logical slot index.
!!RD:M#var/$value; Access current recruit dialog associative memory
===============================================================================
#var - either integer number or unique string. Same as SN:W
$value - get/set/modify variable value
Commands provide fully-featured SN:W equivalent with memory, allocated for each created recruit dialog.
Memory is released after "OnCloseRecruitDlg" for each dialog.
Example:
!!RD:M^acm.mapX^/v998 M^acm.mapY^/v999 M^acm.mapZ^/v1000;
!!RD:M^mithril^/*2;
!!RD:O#townId/#dwellingId/#targetType/#targetId[/#dlgFlags]; Open new recruit dialog (previous dialogs will remain in the background)
===============================================================================
#townId - ID of town to open dialog for or -1. Town will be used as slots source.
#dwellingId - ID of town dwelling (0..13) or -1. Dwelling will be used as slots source.
#targetType - Type of the destination for hired recruits:
RECRUIT_TARGET_TOWN = 0;
RECRUIT_TARGET_HERO = 1;
RECRUIT_TARGET_CUSTOM = 2; Destination will be determined by Lua/ERM script and handled manually
#targetId - ID of target: hero ID, town ID or special value for Lua/ERM script.
#dlgFlags - Combination of CLOSE_ON_BUY and AUTO_UPDATE_ADVMAP flags. See "OnOpenRecruitDlg" event.
Don't set this parameter of using native/default settings.