7 Logic
.Activities
= {"Follow Route", "Patrol", "Repeat Road", "Deploy", "Wander", "Rest In Zone", "Feed In Zone", "Hunt In Zone", "Guard Zone", "Stand Still", "Stand On Start Point", "Go To Start Point"}
8 Logic
.TimeLimits
= {"No Limit", "Until", "Few Sec", "Few Min", "Chat", "Season", "Day", "Month"}
9 Logic
.Seasons
= {"Spring", "Summer", "Autumn", "Winter"}
10 Logic
.Days
= {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
11 Logic
.Months
= {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
12 Logic
.ScriptActions
={"Sit Down", "Stand Up", "Go To Step", "Set Activity", "Stop Actions", "Start Mission"}
14 Logic
.EventModes
={"Once Only", "Repeating"}
15 Logic
.EventTypes
={"Time", "Place", "Entity or Group", "State Machine", "Counter"}
16 Logic
.ConditionTypes
={
18 {"Any player in zone", "All players in zone", "No players in zone", "Some players in zone"},
19 {"At Destination", "Enters State", "Leaves State", "Activity Is", "Die", "Is Attacked"},
21 {"v0_changed", "v3_changed", "Equals", "Lesser", "Greater", ""},
24 Logic
.ChatTypes
= {"None", "Repeating", "Non Repeating", "Continue"}
25 Logic
.InteractionTypes
= {"Give", "Say"}
27 Logic
.Name
= "Activity"
28 Logic
.Description
= "A feature for describing activities sequences"
38 -- ACTION -------------------
39 Logic
.Components
.LogicEntityAction
=
41 BaseClass
="BaseClass",
42 Name
= "LogicEntityAction",
43 DisplayerProperties
= "R2::CDisplayerLua",
44 DisplayerPropertiesParams
= "logicEntityActionPropertySheetDisplayer",
47 {Name
="Name", Type
="String"},
48 {Name
="Event", Type
="EventType"},
49 {Name
="Actions", Type
="Table"}, -- "ActionStep" list
50 {Name
="Conditions", Type
="Table"}, -- "ConditionStep" list
53 getName
= function(this
)
55 local logicEntity
= this
.Parent
.Parent
.Parent
58 if logicEntity
:isGrouped() then
59 logicEntity
= logicEntity
.ParentInstance
62 local coloredName
= (logicEntity
.InstanceId
== r2
.events
.filteredLogicEntityId
)
64 local eventType
= r2
.events
.keyWordsColor
.. i18n
.get("uiR2EdEventTxtPreEvent"):toUtf8() .. " "
67 eventType
= eventType
.. r2
.events
.filterWordColor
69 eventType
= eventType
.. r2
.events
.entityWordColor
71 local name
= "No name"
72 if logicEntity
.getName
then
73 name
= logicEntity
:getName()
74 elseif logicEntity
.Name
then
75 name
= logicEntity
.Name
77 eventType
= eventType
.. name
.. " "
78 eventType
= eventType
.. r2
.events
.communWordsColor
80 eventType
= eventType
..r2
.getLogicAttribute(logicEntity
.Class
, "Events", this
.Event
.Type
).text
82 if this
.Event
.Value
~="" then
83 local instance
= r2
:getInstanceFromId(this
.Event
.Value
)
86 eventType
= eventType
.. " " .. instance
:getShortName()
90 if this
.Event
.ValueString
and this
.Event
.ValueString
~= "" then
91 if string.gfind(eventType
, "%%1")() then
92 eventType
= string.gsub(eventType
, "%%1", "'"..tostring(this
.Event
.ValueString
).."'")
94 eventType
= eventType
.. " '" .. tostring(this
.Event
.ValueString
).. "'"
98 eventType
= eventType
.. ", "
102 local conditionsList
= ""
103 for i
=0, this
.Conditions
.Size
-1 do
104 local conditionInst
= this
.Conditions
[i
]
106 if conditionInst
.Entity
~="" and conditionInst
.Condition
.Type
~="" then
108 conditionsList
= conditionsList
.. "\n" .. r2
.events
.keyWordsColor
109 ..string.upper(i18n
.get("uiR2EdEventTxtPreCondition"):toUtf8()).." "
110 .. r2
.events
.communWordsColor
112 local conditionLogicEntity
= r2
:getInstanceFromId(tostring(conditionInst
.Entity
))
113 assert(conditionLogicEntity
)
115 coloredName
= (conditionLogicEntity
.InstanceId
== r2
.events
.filteredLogicEntityId
)
117 conditionsList
= conditionsList
.. r2
.events
.filterWordColor
119 conditionsList
= conditionsList
.. r2
.events
.entityWordColor
121 conditionsList
= conditionsList
.. conditionLogicEntity
.Name
.. " "
122 conditionsList
= conditionsList
.. r2
.events
.communWordsColor
124 conditionsList
= conditionsList
..r2
.getLogicAttribute(conditionLogicEntity
.Class
, "Conditions", conditionInst
.Condition
.Type
).text
126 if conditionInst
.Condition
.Value
~="" then
127 local instance
= r2
:getInstanceFromId(conditionInst
.Condition
.Value
)
129 conditionsList
= conditionsList
.. " '" .. instance
:getShortName() .."'"
132 conditionsList
= conditionsList
.. ", "
137 local actionsList
= ""
138 for i
=0, this
.Actions
.Size
-1 do
139 local actionInst
= this
.Actions
[i
]
141 if actionInst
.Entity
~="" and actionInst
.Action
.Type
~="" then
143 actionsList
= actionsList
.. "\n" .. r2
.events
.keyWordsColor
144 ..string.upper(i18n
.get("uiR2EdEventTxtPreActions"):toUtf8()).." "
145 .. r2
.events
.communWordsColor
147 local actionLogicEntity
= r2
:getInstanceFromId(tostring(actionInst
.Entity
))
148 assert(actionLogicEntity
)
150 coloredName
= (actionLogicEntity
.InstanceId
== r2
.events
.filteredLogicEntityId
)
152 actionsList
= actionsList
.. r2
.events
.filterWordColor
154 actionsList
= actionsList
.. r2
.events
.entityWordColor
156 local name
= "No name"
157 if actionLogicEntity
.getName
then
158 name
= actionLogicEntity
:getName()
159 elseif actionLogicEntity
.Name
then
160 name
= actionLogicEntity
.Name
162 actionsList
= actionsList
.. name
.. " "
163 actionsList
= actionsList
.. r2
.events
.communWordsColor
165 actionsList
= actionsList
..r2
.getLogicAttribute(actionLogicEntity
.Class
, "ApplicableActions", actionInst
.Action
.Type
).text
166 if actionInst
.Action
.Value
~="" then
167 local instance
= r2
:getInstanceFromId(actionInst
.Action
.Value
)
169 actionsList
= actionsList
.. " '" .. instance
:getShortName() .. "'"
172 if actionInst
.Action
.ValueString
and actionInst
.Action
.ValueString
~= "" then
174 if string.gfind(actionsList
, "%%1")() then
175 actionsList
= string.gsub(actionsList
, "%%1", "'"..tostring(actionInst
.Action
.ValueString
).."'")
177 actionsList
= actionsList
.. " '" .. tostring(actionInst
.Action
.ValueString
).. "'"
181 if i
~=this
.Actions
.Size
-1 then
182 actionsList
= actionsList
.. ","
184 actionsList
= actionsList
.. "."
189 if actionsList
=="" then
190 actionsList
= "\n..."
193 return eventType
.. conditionsList
.. actionsList
--.. "\n"
196 getLogicEntityParent
= function(this
)
198 local logicEntity
= this
.Parent
.Parent
.Parent
199 if logicEntity
:isGrouped() then logicEntity
= logicEntity
.Parent
.Parent
end
204 -- The act of the event
205 getLogicAct
= function(this
)
207 local currentAct
= r2
:getCurrentAct()
208 local baseAct
= r2
.Scenario
:getBaseAct()
209 local isBaseAct
= false
210 local presentActs
= {}
211 local isCurrentAct
= false
215 local entity
= this
:getLogicEntityParent()
216 if entity
and entity
.getParentAct
then
217 local act
= entity
:getParentAct()
219 if act
==currentAct
then
221 elseif act
==baseAct
then
224 presentActs
[act
.InstanceId
] = act
.InstanceId
231 local function verifyAct ( container
)
233 local key
, value
= next(container
, nil)
235 if value
.Action
and value
.Action
.Type
== "Start Act" then
237 local entityId
= value
.Entity
238 local entity
= r2
:getInstanceFromId(entityId
)
239 if entity
and entity
.getParentAct
then
240 local act
= entity
:getParentAct()
242 if act
==currentAct
then
244 elseif act
==baseAct
then
247 presentActs
[act
.InstanceId
] = act
.InstanceId
253 key
, value
= next(container
, key
)
257 verifyAct(this
.Actions
)
258 verifyAct(this
.Conditions
)
260 if counter
>=2 or (counter
==1 and isCurrentAct
) then
262 elseif counter
==1 and not isCurrentAct
and isBaseAct
then
264 for k
, actId
in pairs(presentActs
) do
265 act
= r2
:getInstanceFromId(actId
)
271 --inspect(currentAct)
280 -- called upon translation
281 getLogicActForTranslate
= function(this
)
282 local currentAct
= this
:getLogicEntityParent():getParentAct()
283 local baseAct
= r2
.Scenario
:getBaseAct()
285 local entity
= this
.Event
.Entity
286 if entity
and entity
.getParentAct
then
287 local act
= entity
:getParentAct()
288 if currentAct
== nil then
290 elseif act
~= currentAct
then
291 if currentAct
== baseAct
then
293 elseif act
== baseAct
then
303 local function verifyAct ( container
)
304 local key
, value
= next(container
, nil)
306 if value
.Action
and value
.Action
.Type
== "Start Act" then
308 local entityId
= value
.Entity
309 local entity
= r2
:getInstanceFromId(entityId
)
310 if entity
and entity
.getParentAct
then
311 local act
= entity
:getParentAct()
313 if currentAct
== nil then
315 elseif act
~= currentAct
then
316 if currentAct
== baseAct
then
318 elseif act
== baseAct
then
326 key
, value
= next(container
, key
)
332 if not verifyAct(this
.Actions
) then return false end
333 if not verifyAct(this
.Conditions
) then return false end
337 getLogicActInstanceId
= function(this
)
338 --local ok, act = pcall(Logic.Components.LogicEntityAction.getLogicAct, this)
339 local ok
, act
= pcall(Logic
.Components
.LogicEntityAction
.getLogicActForTranslate
, this
)
340 if not ok
or not act
then
344 return act
.InstanceId
348 Logic
.Components
.EventType
=
350 BaseClass
="BaseClass",
352 DisplayerProperties
= "R2::CDisplayerLua",
353 DisplayerPropertiesParams
= "eventTypePropertySheetDisplayer",
356 {Name
="Type", Type
="String"},
357 {Name
="Value", Type
="RefId"}, -- if type is end of activity/chat step/sequence, instance id
358 {Name
="ValueString", Type
="String", DefaultValue
="", DefaultInBase
=1}, -- if type is emit user event, sub timer...
363 local classActionStepVersion
= 2
364 Logic
.Components
.ActionStep
= {
365 BaseClass
="BaseClass",
367 Version
= classActionStepVersion
,
368 DisplayerProperties
= "R2::CDisplayerLua",
369 DisplayerPropertiesParams
= "actionStepPropertySheetDisplayer",
372 {Name
="Entity", Type
="RefId"}, -- entity target id
373 {Name
="Action", Type
="ActionType"} -- sequence id
376 updateVersion
= function(this
, scenarioValue
, currentValue
)
378 local patchValue
= scenarioValue
379 if patchValue
< 1 then
380 local invalidActions
= {}
381 invalidActions
["desactivate"] = "deactivate"
382 invalidActions
["Desactivate"] = "deactivate"
383 r2
.updateLogicActions(this
, invalidActions
, "BanditCamp")
387 if patchValue
< 2 then
389 local action
= this
.Action
390 if action
.Type
== "Add 10 Seconds" then
391 r2
.requestSetNode(action
.InstanceId
, "Type", "add seconds")
392 r2
.requestInsertNode(action
.InstanceId
, "", -1, "ValueString", "10")
395 if action
.Type
== "Sub 10 seconds" then
396 r2
.requestSetNode(action
.InstanceId
, "Type", "sub seconds")
397 r2
.requestInsertNode(action
.InstanceId
, "", -1, "ValueString", "10")
399 if action
.Type
== "Add 1 minute" then
400 r2
.requestSetNode(action
.InstanceId
, "Type", "add seconds")
401 r2
.requestInsertNode(action
.InstanceId
, "", -1, "ValueString", "60")
404 if action
.Type
== "Sub 1 minute" then
405 r2
.requestSetNode(action
.InstanceId
, "Type", "sub seconds")
406 r2
.requestInsertNode(action
.InstanceId
, "", -1, "ValueString", "60")
412 if patchValue
== currentValue
then return true end
418 Logic
.Components
.ActionType
=
420 BaseClass
="BaseClass",
422 DisplayerProperties
= "R2::CDisplayerLua",
423 DisplayerPropertiesParams
= "actionTypePropertySheetDisplayer",
426 {Name
="Type", Type
="String"},
427 {Name
="Value", Type
="RefId"}, -- if type is begin of activity/chat sequence, instance id
428 {Name
="ValueString", Type
="String", DefaultValue
="", DefaultInBase
=1}, -- if type is emit user event, sub timer...
434 Logic
.Components
.ConditionStep
=
436 BaseClass
="BaseClass",
437 Name
= "ConditionStep",
438 DisplayerProperties
= "R2::CDisplayerLua",
439 DisplayerPropertiesParams
= "conditionStepPropertySheetDisplayer",
442 {Name
="Entity", Type
="RefId"}, -- entity id
443 {Name
="Condition", Type
="ConditionType"}
448 Logic
.Components
.ConditionType
=
450 BaseClass
="BaseClass",
451 Name
= "ConditionType",
452 DisplayerProperties
= "R2::CDisplayerLua",
453 DisplayerPropertiesParams
= "conditionTypePropertySheetDisplayer",
456 {Name
="Type", Type
="String"},
457 {Name
="Value", Type
="RefId"}, -- if type is being in activity/chat step/sequence, instance id
463 -- REACTION -----------------
465 Logic
.Components
.LogicEntityReaction
=
467 BaseClass
="BaseClass",
468 Name
= "LogicEntityReaction",
469 DisplayerProperties
= "R2::CDisplayerLua",
470 DisplayerPropertiesParams
= "logicEntityReactionPropertySheetDisplayer",
473 {Name
="Name", Type
="String"},
474 {Name
="LogicEntityAction", Type
="String"}, -- id of associated LogicEntityAction
475 {Name
="ActionStep", Type
="String"}, -- id of associated ActionStep
479 Logic
.Components
.ChatAction
=
481 BaseClass
="BaseClass",
483 DisplayerProperties
= "R2::CDisplayerLua",
484 DisplayerPropertiesParams
= "chatActionPropertySheetDisplayer",
487 {Name
="Who", Type
="RefId"},
488 {Name
="WhoNoEntity", Type
="String"},
489 {Name
="Says", Type
="String"},
490 {Name
="Emote", Type
="String"},
491 {Name
="Facing", Type
="RefId"},
492 -- {Name ="FacingNoEntity", Type ="String"},
496 Logic
.Components
.ChatStep
= {
497 BaseClass
="BaseClass",
499 DisplayerProperties
= "R2::CDisplayerLua",
500 DisplayerPropertiesParams
= "chatStepPropertySheetDisplayer",
503 {Name
="Actions", Type
="Table"},
504 {Name
="Time", Type
="Number" },
505 {Name
="Name", Type
="String" }
508 getName
= function(this
)
511 local minNb
, secNb
= r2
.dialogs
:calculMinSec(this
.Time
)
514 time
= tostring(minNb
)..i18n
.get("uiR2EdShortMinutes"):toUtf8()
516 time
= time
.." " ..tostring(secNb
)..i18n
.get("uiR2EdShortSeconds"):toUtf8()
517 local afterTime
= "(" ..i18n
.get("uiR2EdAfter"):toUtf8().." ".. time
..") "
521 local action
= this
.Actions
[0]
522 local who
= action
.Who
523 if who
=="" then who
=action
.WhoNoEntity
end
524 if who
and who
~= "" then
526 if r2
:getInstanceFromId(who
) then
527 who
=r2
:getInstanceFromId(who
).Name
529 who
= r2
.dialogs
.whoToWhoTranslation
[who
]
532 whoToWho
= who
.. " "
534 local facing
= action
.Facing
536 whoToWho
= whoToWho
..i18n
.get("uiR2EdSaysTo"):toUtf8().. " " .. r2
:getInstanceFromId(facing
).Name
.. " "
539 local emote
= action
.Emote
540 if emote
~="" and r2
.dialogs
.fromEmoteIdToName
[emote
] ~= nil then
541 whoToWho
= whoToWho
.."(" .. r2
.dialogs
.fromEmoteIdToName
[emote
] .. ") :"
545 return afterTime
..whoToWho
549 getShortName
= function(this
)
553 local action
= this
.Actions
[0]
554 local who
= action
.Who
555 if who
~= "" or WhoNoEntity
~="" then
556 who
= r2
:getInstanceFromId(who
)
559 elseif action
.WhoNoEntity
=="_System" then
560 saysWhat
= i18n
.get("uiR2EdSystem"):toUtf8()
561 elseif action
.WhoNoEntity
=="_DM" then
562 saysWhat
= i18n
.get("uiR2EdDonjonMaster"):toUtf8()
565 saysWhat
= saysWhat
.. " " ..i18n
.get("uiR2EdSays"):toUtf8().. " "
567 local says
= action
.Says
569 local inst
=r2
:getInstanceFromId(says
)
572 local uc_says
= ucstring()
573 uc_says
:fromUtf8(says
)
574 uc_says
= uc_says
:substr(0, 4)
575 says
= uc_says
:toUtf8()
580 saysWhat
= saysWhat
.. says
.. "..."
587 --------------------------------------------------------------------------------------------
589 getParentTreeNode
= function(this
)
594 local classChatSequenceVersion
= 1
595 Logic
.Components
.ChatSequence
= {
596 PropertySheetHeader
= r2
.getDisplayButtonHeader("r2.dialogs:openEditor()", "uiR2EdEditDialogButton"),
597 BaseClass
= "LogicEntity",
598 Name
= "ChatSequence",
600 Menu
="ui:interface:r2ed_feature_menu",
601 Version
= classChatSequenceVersion
,
603 DisplayerProperties
= "R2::CDisplayerLua",
604 DisplayerPropertiesParams
= "chatSequencePropertySheetDisplayer",
606 DisplayerUI
= "R2::CDisplayerLua",
607 DisplayerUIParams
= "defaultUIDisplayer",
608 DisplayerVisual
= "R2::CDisplayerVisualEntity",
611 ApplicableActions
= {
612 "activate", "deactivate", "starts dialog", "stops dialog", "starts chat" , "continues dialog"
615 "start of dialog", "end of dialog" ,
616 "start of chat", "end of chat",
617 "activation", "deactivation"
620 "is not in dialog", "is in dialog", "is in chat"
629 {Name
= "Type", Type
="String",DefaultValue
= "None", Visible
=false},
630 {Name
="Repeating", Type
="Number" ,DefaultValue
= "0", Visible
=false},
631 {Name
="Components",Type
="Table"},
632 {Name
="SubComponents", Type
="Table"},
633 {Name
="Name", Type
="String", MaxNumChar
="32"},
634 {Name
="AutoStart", Type
="Number", WidgetStyle
="Boolean", DefaultValue
="1", Visible
=function(this
) return this
:mustDisplayAutostart() end},
635 {Name
="Active", Type
="Number", WidgetStyle
="Boolean", DefaultValue
= "1"},
639 mustDisplayAutostart
= function(this
)
640 if this
.Class
== "ProximityDialog" then
647 getParentTreeNode
= function(this
)
648 return this
:getFeatureParentTreeNode()
651 onPostCreate
= function(this
)
652 --this:createGhostComponents()
653 if this
.User
.DisplayProp
and this
.User
.DisplayProp
== 1 then
654 r2
:setSelectedInstanceId(this
.InstanceId
)
655 r2
:showProperties(this
)
656 this
.User
.DisplayProp
= nil
663 --if r2:getLeftQuota() <= 0 then -- ??
668 local function posOk(x
, y
, z
)
669 if r2
.mustDisplayInfo("ChatSequence") == 1 then
670 r2
.displayFeatureHelp("ChatSequence")
672 debugInfo(string.format("Validate creation of 'Dialog' at pos (%d, %d, %d)", x
, y
, z
))
673 r2
.dialogs
:newSequenceInst(x
, y
, z
)
675 local function posCancel()
676 debugInfo("Cancel choice 'Dialog' position")
679 local creature
= r2
.Translator
.getDebugCreature("object_component_dialog.creature")
680 r2
:choosePos(creature
, posOk
, posCancel
, "createDialog")
684 getName
= function(this
)
686 local name
= this
.Name
689 local index
= r2
.logicComponents
:searchElementIndex(this
)
691 name
= i18n
.get("uiR2EDDialog"):toUtf8() .. index
699 getShortName
= function(this
)
701 return this
:getName()
704 ---------------------------------------------------------------------------------------------------------
706 editDialogs
= function(this
)
707 r2
.dialogs
:openEditor()
710 getAvailableCommands
= function(this
, dest
)
711 r2
.Classes
.LogicEntity
.getAvailableCommands(this
, dest
)
712 table.insert(dest
, this
:buildCommand(this
.editDialogs
, "edit_dialogs", "uiR2EDEditDialogs", "r2ed_edit_dialog.tga", true))
713 this
:getAvailableDisplayModeCommands(dest
)
716 initEventValuesMenu
= function(this
, menu
, categoryEvent
)
717 for ev
=0,menu
:getNumLine()-1 do
719 local eventType
= tostring(menu
:getLineId(ev
))
721 if r2
.events
.eventTypeWithValue
[eventType
] == "Number" then
723 local subMenu
= menu
:getSubMenu(ev
)
726 local uc_name
= ucstring()
727 uc_name
:fromUtf8( tostring(i
) )
728 func
= "r2.events:setEventValue('','" .. categoryEvent
.."','".. tostring(i
).."')"
729 subMenu
:addLine(uc_name
, "lua", func
, tostring(i
))
732 elseif r2
.events
.eventTypeWithValue
[eventType
]=="ChatStep" then
735 local subMenu
= menu
:getSubMenu(ev
)
737 for c
=0, this
.Components
.Size
-1 do
738 local chat
= this
.Components
[c
]
739 local uc_name
= ucstring()
740 uc_name
:fromUtf8(chat
:getShortName())
741 subMenu
:addLine(uc_name
, "lua",
742 "r2.events:setEventValue('".. chat
.InstanceId
.."','" .. categoryEvent
.. "')", chat
.InstanceId
)
745 if this
.Components
.Size
==0 then
746 subMenu
:addLine(i18n
.get("uiR2EdNoSelelection"), "", "", "")
752 getLogicAction
= function(this
, context
, action
)
753 return r2
.Translator
.getDialogLogicAction(this
, context
, action
)
755 getLogicEvent
= function(this
, context
, event
)
756 return r2
.Translator
.getDialogLogicEvent(this
, context
, event
)
758 getLogicCondition
= function(this
, context
, condition
)
759 return r2
.Translator
.getDialogLogicCondition(this
, context
, condition
)
762 pretranslate
= function(this
, context
)
763 r2
.Translator
.createAiGroup(this
, context
)
766 translate
= function(this
, context
)
767 r2
.Translator
.translateFeatureActivation(this
, context
)
768 r2
.Translator
.translateDialog( this
, context
)
771 updateVersion
= function(this
, scenarioValue
, currentValue
)
772 local patchValue
= scenarioValue
773 if patchValue
< 1 then
774 local subComponents
= {}
775 r2
.requestInsertNode(this
.InstanceId
, "", -1, "SubComponents", subComponents
)
776 r2
.requestInsertNode(this
.InstanceId
, "", -1, "AutoStart", this
.Active
)
777 r2
.requestSetNode(this
.InstanceId
, "Active", 1)
778 r2
.requestSetNode(this
.InstanceId
, "Base", r2
.Translator
.getDebugBase("palette.entities.botobjects.dialog"))
782 if patchValue
== currentValue
then return true end
786 initLogicEntitiesInstancesMenu
= function(this
, subMenu
, calledFunction
)
788 local entitiesTable
= r2
.Scenario
:getAllInstancesByType(this
.Name
)
789 for key
, entity
in pairs(entitiesTable
) do
790 local uc_name
= ucstring()
791 uc_name
:fromUtf8(entity
.Name
)
792 subMenu
:addLine(uc_name
, "lua", calledFunction
.."('".. entity
.InstanceId
.."')", entity
.InstanceId
)
795 if table.getn(entitiesTable
)==0 then
796 subMenu
:addLine(i18n
.get("uiR2EdNoSelelection"), "", "", "")
803 local ActivityStepVersion
= 1
804 Logic
.Components
.ActivityStep
= {
805 BaseClass
="BaseClass",
806 Name
="ActivityStep",
807 Version
= ActivityStepVersion
,
808 BuildPropertySheet
= true,
809 Menu
="ui:interface:r2ed_feature_menu",
811 BuildPropertySheet
= false,
812 DisplayerVisualParams
=
814 Look
= r2
.PrimRender
.GroupLook
,
815 ArrayName
= "Components"
817 DisplayerProperties
= "R2::CDisplayerLua",
818 DisplayerPropertiesParams
= "activityStepPropertySheetDisplayer",
822 {Name
="Activity", Type
="String"},
823 {Name
="ActivityZoneId",Type
="RefId",Category
="ActivityStep"},
824 {Name
="TimeLimit",Type
="String",Category
="ActivityStep"},
825 {Name
="TimeLimitValue", Type
="String",Category
="ActivityStep",Category
="ActivityStep"},
826 {Name
="RoadCountLimit", Type
="String",Category
="ActivityStep",Category
="ActivityStep", DefaultInBase
= 1, DefaultValue
= "0"},
827 {Name
="Chat",Type
="RefId"},
828 {Name
= "Type", Type
="String",DefaultValue
= "None"}, --TEMP TEMP TEMP
829 {Name
="EventsIds",Type
="Table"},
830 {Name
="Name", Type
="String", MaxNumChar
="32"}
832 -- get sequencable parent for this activity step
833 getSequencableParent
= function(this
)
834 local currParent
= this
.Parent
836 if currParent
.InstanceId
and currParent
:isSequencable() then
839 currParent
= currParent
.Parent
843 getVerbLookupString
= function(this
)
844 local seqParent
= this
:getSequencableParent()
846 return seqParent
:getActivityVerbLookupName(this
.Activity
)
851 -- do lookup from the verb lookup string used to know the display name, and button texture
852 doLookupFromVerb
= function(this
, lookupTable
)
853 local lookupString
= this
:getVerbLookupString()
855 local value
= lookupTable
[lookupString
]
857 debugInfo(colorTag(255,0,0).."The activity '".. lookupString
.."' is not properly registred")
862 -- get texture for the button displayed in the mini activity view
863 getMiniButtonTexture
= function(this
)
864 local result
= this
:doLookupFromVerb(r2
.miniActivities
.activityTextures
)
865 if result
then return result
end
866 return "brick_default.tga"
868 -- get the verb for this activity (rest, feed, patrol etc...)
869 getVerb
= function(this
)
870 local result
= this
:doLookupFromVerb(r2
.activities
.activityTypeTranslation
)
871 if result
then result
= result
.trans
end
872 if result
then return result
end
873 return ucstring("Activity not registered : " .. lookupString
)
876 getName
= function(this
)
877 local activityType
= this
:getVerb() .. " "
878 if this
.ActivityZoneId
~= "" then
879 local place
= r2
:getInstanceFromId(tostring(this
.ActivityZoneId
))
881 activityType
= activityType
.. place
.Name
.." "
886 local activityTime
= ""
887 if this
.TimeLimit
== "Few Sec" then
889 local hourNb
, minNb
, secNb
= r2
.logicComponents
:calculHourMinSec(tonumber(this
.TimeLimitValue
))
891 local timeLimitText
= i18n
.get("uiR2EdFor"):toUtf8() .. " "
892 if hourNb
~= 0 then timeLimitText
= timeLimitText
.. hourNb
.. i18n
.get("uiR2EdShortHours"):toUtf8() .. " " end
893 if minNb
~= 0 then timeLimitText
= timeLimitText
.. minNb
.. i18n
.get("uiR2EdShortMinutes"):toUtf8() .. " " end
894 timeLimitText
= timeLimitText
.. secNb
.. i18n
.get("uiR2EdShortSeconds"):toUtf8()
896 activityTime
= timeLimitText
898 elseif r2
.activities
.timeLimitsTranslation
[this
.TimeLimit
] ~= nil then
899 activityTime
= string.lower(r2
.activities
.timeLimitsTranslation
[this
.TimeLimit
])
902 return activityType
..activityTime
906 getShortName
= function(this
)
909 local activityType
= this
:getVerb()
910 if this
.ActivityZoneId
~= "" then
911 local place
= r2
:getInstanceFromId(tostring(this
.ActivityZoneId
))
913 activityType
= activityType
.. " " .. place
.Name
920 updateVersion
= function(this
, scenarioValue
, currentValue
)
921 local patchValue
= scenarioValue
923 if patchValue
< 1 then
924 local activity
= this
.Activity
925 if (activity
and activity
== "Inactive") then
926 r2
.requestSetNode(this
.InstanceId
, "Activity", "Stand Still")
928 local name
= this
.Name
932 if patchValue
== currentValue
then return true end
939 Logic
.Components
.ActivitySequence
= {
940 BaseClass
="BaseClass",
941 Name
="ActivitySequence",
942 BuildPropertySheet
= true,
943 Menu
="ui:interface:r2ed_feature_menu",
945 --DisplayerUI = "R2::CDisplayerLua",
946 --DisplayerUIParams = "defaultUIDisplayer",
947 BuildPropertySheet
= false,
948 DisplayerVisual
= "R2::CDisplayerVisualActivitySequence",
949 DisplayerProperties
= "R2::CDisplayerLua",
950 DisplayerPropertiesParams
= "activitySequencePropertySheetDisplayer",
954 --{Name ="InstanceId", Type ="String"},
955 {Name
="Repeating", Type
="Number" , DefaultValue
= "1"},
956 {Name
="Components", Type
="Table"},
957 {Name
="Name", Type
="String"}
961 getName
= function(this
)
963 local name
= this
.Name
966 local index
= r2
.logicComponents
:searchElementIndex(this
)
969 name
= i18n
.get("uiR2EdSeq"):toUtf8() .. index
977 getShortName
= function(this
)
979 return this
:getName()
982 -- get ActiveLogicEntity parent
983 getActiveLogicEntityParent
= function(this
)
985 -- ActiveLogicEntity.Behavior.Activities
986 local activeLogicEntity
= this
.Parent
.Parent
.Parent
988 -- NpcGrpFeature.Components
989 --if activeLogicEntity:isGrouped() then activeLogicEntity = activeLogicEntity.Parent.Parent end
991 return activeLogicEntity
997 --this function must be called when we delete a ChatAction,
998 --to unregister the text
999 onDeleteChatAction
= function(chatAction
)
1000 if chatAction
.User
.DeleteInProgress
== true then return end
1001 chatAction
.User
.DeleteInProgress
= true
1002 if chatAction
.Says
~= nil and chatAction
.Says
~= ""
1005 debugInfo("onDeleteChatAction")
1006 r2
.unregisterTextFromId(chatAction
.Says
)
1010 --counts the states created, to ensure states names uniqueness
1012 --timer used to time the sequences steps
1013 Logic
.activityStepTimer
= "t0"
1014 Logic
.activityStepTimerId
= 0
1015 --timer used to time the chat steps
1016 Logic
.chatTimer
= "t1"
1017 Logic
.chatTimerId
= 1
1018 --timer used inside activities
1019 Logic
.activityInternalTimer
= "t2"
1020 Logic
.activityInternalTimerId
= 2
1022 --variable used to know which action of the current chat sequence
1024 Logic
.chatStepVar
= "v1"
1025 --variable used to know which chat sequence is currently played
1026 Logic
.chatSequenceVar
= "v0"
1027 --variable used to know which activity sequence is currently played
1028 Logic
.activityStepVar
= "v2"
1029 --variable used to know which interrupt action must be executed
1030 Logic
.triggerEventVar
= "v3"
1032 Logic
.EndOfActivitySequenceEvent
= 9
1033 Logic
.EndOfChatSequenceEvent
= 8
1035 --switch_action which hold all chat sequences
1036 Logic
.DialogAction
= nil
1037 --switch action holding chat sequences transitions
1038 Logic
.DialogAction2
= nil
1040 --switch_action which hold all sequence steps
1041 Logic
.SequenceAction
= nil
1042 Logic
.ActionStepCounter
=0
1043 Logic
.ChatSequenceCounter
= 0
1044 --used to know the names of all the states generated
1045 --to translate this activity
1046 Logic
.StatesByName
= ""
1048 --timer_triggered event, triggered
1049 --each time we must enter a new chat step
1050 Logic
.DialogEvent
= nil
1052 Logic
.DialogEvent2
= nil
1054 --timer_triggered event, triggered
1055 --each time we must enter a new sequence step
1056 Logic
.SequenceEvent
= nil
1058 --hold the states used in the current activity.
1059 --all the states are created at the start of the translation,
1060 --before translating the events and actions.
1063 --hold the states used in all the activities
1065 Logic
.ActivitiesStates
={}
1067 --the activity which is currently being translated.
1068 Logic
.CurrentActivity
= nil
1070 ----------------------------------------------------
1071 --to be called once for each sequence of each group
1072 --complete the AiActivity field of the first state of this sequence
1073 --and create the actions to go to the first step
1074 Logic
.initGroupActivitiesTranslation
= function(context
, hlComponent
, sequence
, first
, activityIndex
, aiActivity
, rtGrp
)
1075 assert(context
and hlComponent
and sequence
and activityIndex
and aiActivity
and rtGrp
)
1076 --get the states of this activity
1078 local activityStates
= Logic
.ActivitiesStates
[ tostring(sequence
.InstanceId
) ]
1079 assert(sequence
.Class
== "ActivitySequence")
1080 if not activityStates
then
1083 printWarning("Error while translating '" .. hlComponent
.Name
.. "' activities in sequence " .. sequence
.Name
)
1084 -- pretranslate sequence.InstanceId errors instanceId not added in currentAct.ActivitiesId ?
1088 --get the initial state of this activity
1089 local aiState
= activityStates
[sequence
.InstanceId
][1]
1090 Logic
.StatesByName
= ""
1091 for k
, v
in pairs(activityStates
)
1093 if v
.Class
~= "RtAiState"
1095 local k1
, v1
= next( v
, nil)
1097 Logic
.StatesByName
= r2
.Utils
.concat(Logic
.StatesByName
, v1
.Name
)
1098 k1
, v1
= next(v
, k1
)
1101 Logic
.StatesByName
= r2
.Utils
.concat(Logic
.StatesByName
, v
.Name
)
1104 aiState
.AiActivity
= aiActivity
1105 assert(aiState
.AiActivity
)
1106 local event
= r2
.Translator
.createEvent("start_of_state", aiState
.Name
, rtGrp
.Name
)
1107 -- local event = r2.Translator.createEvent("group_spawned", aiState.Name, rtGrp.Name)
1108 table.insert(context
.RtAct
.Events
, event
)
1111 table.insert(aiState
.Children
, rtGrp
.Id
)
1116 if hlComponent
.Speed
and hlComponent
.Speed
== "run" then speed
= "()addProfileParameter(\"running\");\n" end
1118 local code
= "currentActivitySequenceVar = " .. tostring(activityIndex
-1 ) ..";\n"
1119 .. "oldActivitySequenceVar = currentActivitySequenceVar;\n"
1120 .. "RoadCountLimit=0;\n"
1121 .. "oldActivityStepVar = -1;\n"
1122 .. "oldActivityStepVar2 = 0;\n"
1123 .. Logic
.activityStepVar
.." = 0;\n"
1126 .."(alive)isAlived();\n"
1127 .. "if (alive == 1)\n{\n"
1128 .. "\t()setTimer(30, " .. Logic
.activityStepTimerId
.. ");\n"
1136 local action
= r2
.Translator
.createAction("code", code
)
1137 action
.Name
= "startActivitySequence"
1139 table.insert(context
.RtAct
.Actions
, action
)
1140 table.insert(event
.ActionsId
, action
.Id
)
1145 local event
= r2
.Translator
.createEvent("group_spawned", aiState
.Name
, rtGrp
.Name
)
1146 local action
= r2
.Translator
.createAction("code", "if (init != 1)\n{\n\t()setTimer(30, " .. Logic
.activityStepTimerId
.. ");\n}\n")
1147 table.insert(context
.RtAct
.Events
, event
)
1148 table.insert(context
.RtAct
.Actions
, action
)
1149 table.insert(event
.ActionsId
, action
.Id
)
1153 local leader
= hlComponent
1155 if hlComponent
:isKindOf("NpcGrpFeature") then
1156 if hlComponent
.Components
.Size
~= 0 then
1157 leader
= hlComponent
.Components
[0]
1164 --insert an activity step at the specified position
1165 Logic
.insertActivityStep
= function(sequence
, step
, pos
)
1166 local n
= table.getn(sequence
.Components
)
1169 table.insert(sequence
.Components
, step
)
1171 table.insert(sequence
.Components
, pos
, step
)
1175 --insert a chat step at the specified position
1176 Logic
.insertChatStep
= function(chatSequence
, chatStep
, pos
)
1177 local n
= table.getn(chatSequence
.Components
)
1180 table.insert(chatSequence
.Components
, chatStep
)
1182 table.insert(chatSequence
.Components
, pos
)
1187 Logic
.createInteraction
= function(action
, parameter
)
1188 local index
= Logic
.find(Logic
.InteractionTypes
, action
)
1191 if index
== nil or parameter
== nil
1193 -- debugInfo(colorTag(255,0,0).."unknown interaction : " .. action .." !")
1197 interaction
= r2
.newComponent("Interaction")
1198 interaction
.Type
= action
1199 interaction
.Parameter
= parameter
1203 Logic
.createActivityStep
= function(activity
, timeLimit
, zoneId
, time
)
1204 local activityStep
= nil
1206 if activity
== nil or timeLimit
== nil
1211 --checking activity type and time limit type
1212 if Logic
.find(Logic
.Activities
, activity
)~= nil and Logic
.find(Logic
.TimeLimits
, timeLimit
)~= nil
1214 --checking activity parameter
1215 if ( (activity
~= "Stand Still") and (activity
~= "Inactive") and (zoneId
== nil) )
1217 --this activity need a zone, and no zone id is given
1218 -- debugInfo(colorTag(255,0,0).."activity <" .. activity .."> need a zone id!")
1222 --checking time parameter
1223 --if time parameter needed, check its presence
1224 if timeLimit
~="No Limit" and timeLimit
~="Chat" and time
== nil
1226 --this activity needs a time limit and no limit is given
1227 -- debugInfo(colorTag(255,0,0).."Time limit <" .. timeLimit .."> need a time limit parameter!")
1231 --check season validity
1232 if (timeLimit
== "Season") and (Logic
.find(Logic
.Seasons
, time
) == nil)
1234 -- debugInfo(colorTag(255,0,0).."Unknown season: " .. time)
1238 --check day validity
1239 if (timeLimit
== "Day") and (Logic
.find(Logic
.Days
, time
) == nil)
1241 debugInfo(colorTag(255,0,0).."Uknown week day: " .. time
)
1245 if (timeLimit
== "Month") and (Logic
.find(Logic
.Months
, time
)== nil)
1247 -- debugInfo(colorTag(255,0,0,0).."Uknown month: " .. time)
1251 activityStep
= r2
.newComponent("ActivityStep")
1252 activityStep
.Activity
= activity
1253 activityStep
.TimeLimit
= timeLimit
1254 activityStep
.ActivityZoneId
= zoneId
1255 activityStep
.TimeLimitValue
= time
1257 -- debugInfo(colorTag(255,0,0).."Unknown activity !")
1262 Logic
.createState
= function()
1263 local aiState
= r2
.newComponent("RtAiState")
1264 aiState
.Name
= aiState
.Id
1265 Logic
.StatesByName
= Logic
.StatesByName
.."\n" .. aiState
.Name
1269 --create the AiStates necessay to translate this step
1270 Logic
.createStepStates
= function(step
, context
)
1272 local state
= Logic
.createState()
1273 table.insert(states
, state
)
1274 table.insert(context
.RtAct
.AiStates
, state
)
1275 if step
.Activity
== "Patrol"
1277 local state
= Logic
.createState()
1278 table.insert(states
, state
)
1279 table.insert(context
.RtAct
.AiStates
, state
)
1284 --assign a zone or a road to an AiState
1285 --if invert is true, invert the road
1286 Logic
.assignZone
= function(rtAiState
, zone
, invert
)
1287 assert( zone
and type(zone
) == "userdata")
1288 local points
= zone
.Points
1289 assert( points
~= nil)
1291 local size
= points
.Size
+ 1
1296 local k
, v
= next(points
, nil)
1308 rtAiState
.Pts
[j
].x
= r2
.getWorldPos(v
).x
1309 rtAiState
.Pts
[j
].y
= r2
.getWorldPos(v
).y
1310 rtAiState
.Pts
[j
].z
= r2
.getWorldPos(v
).z
1311 k
, v
= next(points
, k
)
1315 --create all the states used in this activity Sequence
1316 Logic
.createActivityStates
= function(context
, sequence
)
1317 assert( sequence
~= nil)
1319 local activityStates
={}
1320 --activity's initial stat, aiStopStatee
1323 local aiStartState
= r2
.newComponent("RtAiState")
1324 aiStartState
.Name
= aiStartState
.Id
1325 Logic
.StatesByName
= aiStartState
.Name
1326 aiStartState
.AiMovement
= "idle" -- "stand_on_start_point"
1327 table.insert(context
.RtAct
.AiStates
, aiStartState
)
1331 local aiStopState
= r2
.newComponent("RtAiState")
1332 aiStopState
.Name
= aiStopState
.Id
1333 --Logic.StatesByName = aiStopState.Name
1334 aiStopState
.AiMovement
= "idle" -- "stand_on_start_point"
1335 table.insert(context
.RtAct
.AiStates
, aiStopState
)
1337 activityStates
[sequence
.InstanceId
]= { aiStartState
, aiStopState
}
1340 if (sequence
.Components
== nil) then assert(nil) end
1341 --creation of the states of the step
1342 local k
, v
= next(sequence
.Components
, nil)
1344 local states
= Logic
.createStepStates(v
, context
)
1345 activityStates
[v
.InstanceId
]= states
1346 k
, v
= next(sequence
.Components
, k
)
1348 Logic
.ActivitiesStates
[sequence
.InstanceId
] = activityStates
1351 Logic
.translateActivitySequence
= function(context
, hlComponent
, activitySequence
, sequenceId
, rtNpcGrp
)
1352 assert(rtNpcGrp
~= nil)
1353 if context
.Real
== false
1357 Logic
.ActionStepCounter
= 0
1358 Logic
.ChatSequenceCounter
= 0
1360 Logic
.CurrentActivity
= activitySequence
1363 local nbSteps
= activitySequence
.Components
.Size
1367 local sequence
= activitySequence
1370 if sequence
.Components
.Size
==0
1376 Logic
.initSequence(context
, rtNpcGrp
)
1377 if Logic
.ActivitiesStates
[sequence
.InstanceId
] then
1378 Logic
.States
= Logic
.ActivitiesStates
[sequence
.InstanceId
]
1386 local k
, activityStep
= next(sequence
.Components
, nil)
1389 Logic
.translateActivityStep(context
, hlComponent
, activitySequence
, activityStep
, i
, rtNpcGrp
)
1391 k
, activityStep
= next(sequence
.Components
, k
)
1395 --create actions to repeat the sequence
1396 if sequence
.Repeating
== 1
1400 "//sequence will repeat"..
1401 "oldChatSequenceVar = " .. Logic
.chatSequenceVar
.. ";\n" ..
1402 "RoadCountLimit=0;\n" ..
1403 "oldActivityStepVar = " .. Logic
.activityStepVar
.. ";\n" ..
1404 "oldActivityStepVar2 = " .. Logic
.activityStepVar
.. " + 1" .. ";\n" ..
1406 "()setTimer(1, " ..Logic
.activityStepTimerId
.. ");\n"
1407 -- .. "()setEvent(" .. Logic.EndOfActivitySequenceEvent ..");\n"
1409 local action
= r2
.Translator
.createAction("code", code
)
1410 action
.Name
= "repeat_sequence"
1411 table.insert(Logic
.SequenceAction
.Children
, action
)
1416 "//sequence will not repeat"..
1417 "oldChatSequenceVar = " .. Logic
.chatSequenceVar
.. ";\n" ..
1418 "RoadCountLimit=0;\n"..
1419 "oldActivityStepVar = " .. Logic
.activityStepVar
.. ";\n" ..
1420 "oldActivityStepVar2 = " .. Logic
.activityStepVar
.. " + 1" .. ";\n"
1422 local stateName
= Logic
.ActivitiesStates
[sequence
.InstanceId
][sequence
.InstanceId
][2].Id
1424 local setNextActivityState
= "()postNextState(\"" .. r2
.getNamespace() .. stateName
.."\");\n"
1426 local action
= r2
.Translator
.createAction("code", backupState
1427 -- .."()setEvent(" .. Logic.EndOfActivitySequenceEvent ..");\n"
1428 ..setNextActivityState
)
1431 action
.Name
= "end_of_activity_sequence"
1432 table.insert(Logic
.SequenceAction
.Children
, action
)
1435 Logic
.SequenceEvent
.StatesByName
= Logic
.StatesByName
1436 Logic
.DialogEvent
= nil
1437 Logic
.SequenceEvent
= nil
1442 Logic
._obsolete_TranslateScriptAction
= function(context
, step
, nextTime
)
1443 local actionType
= Logic
.getAction(step
)
1444 assert(actionType
~= nil)
1445 -- debugInfo(colorTag(0,255,0).. actionType)
1447 if actionType
== "stop_actions"
1449 local action
= r2
.Translator
.createAction("set_timer_" ..Logic
.chatTimer
, "0")
1453 if actionType
== "start_mission"
1455 local counterMission
= context
.Components
[step
.Parameter
]
1456 local action
= r2
.Translator
.createAction("trigger_event_1", context
.RtCounters
[counterMission
.InstanceId
].RtGroup
.Name
)
1457 -- debugInfo("action created!!")
1461 if 0==1 and actionType
== "go_to_step"
1464 local param
= tonumber(step
.Parameter
)
1465 debugInfo("param = " .. param
)
1466 if (param
< 1) or (Logic
.CurrentActivity
.Components
[param
]== nil)
1468 -- debugInfo(colorTag(255,0,0).."Impossible to go to step " .. param .." !")
1471 debugInfo(context
.Feature
.Class
)
1472 return Logic
.selectActivityStep(param
)
1475 if actionType
== "set_activity"
1480 if step
.Who
~= "" and step
.Who
~= nil
1483 rtGroup
= r2
.Translator
.getRtGroup(context
, group
)
1486 param
= tonumber(step
.Parameter
)
1488 -- debugInfo("param = " .. param)
1493 action
= r2
.Translator
.createAction("begin_state", Logic
.getActivityInitialStateName(group
, param
, context
))
1494 assert(action
~= nil)
1495 local index
= Logic
.addTriggeredAction(context
, context
.RtGroups
[group
].Name
, action
)
1496 action
= r2
.Translator
.createAction("modify_variable", rtGroup
.Name
..":" ..Logic
.triggerEventVar
.." = " .. index
)
1497 action
.Name
="set_activity"
1499 action
= r2
.Translator
.createAction("begin_state", Logic
.getActivityInitialStateName(context
.Group
.Name
, param
, context
))
1500 assert(action
~= nil)
1505 local action
= r2
.Translator
.createAction(actionType
)
1506 assert(action
~= nil)
1513 Logic
.translateChatAction
= function(context
, chatSequenceNumber
, chatStepNumber
, chatSequence
, chatStep
, chatAction
, rtMAction
)
1514 local getRtId
= r2
.Features
["TextManager"].getRtId
1515 if chatAction
.Class
== "ChatAction"
1517 local who
= r2
.Utils
.getNpcParam( tostring( chatAction
.Who
), context
)
1518 -- create say action
1521 local whoInstance
= r2
:getInstanceFromId( tostring(chatAction
.Who
) )
1522 local chatSequenceInstance
= r2
:getInstanceFromId(chatSequence
.InstanceId
)
1525 if whoInstance
then whoName
= "(" .. whoInstance
.Name
..")" end
1528 printWarning( "Error in ChatStep '" .. chatStep
:getName()
1529 .. "' of the ChatSequence '" .. chatSequence
:getName() .. "'"
1530 .. " the field Who '" .. chatAction
.Who
.."' is invalid " )
1537 if chatAction
.Says
~= "" and chatAction
.Says
~= nil
1539 local param
= getRtId(context
, tostring(chatAction
.Says
))
1541 action
= r2
.Translator
.createAction("npc_say", param
, who
);
1543 -- action = r2.newComponent("RtNpcEventHandlerAction")
1544 -- action.Action = "npc_say"
1546 -- action.Parameters = who .."\n" .. param
1547 table.insert(rtMAction
.Children
, action
)
1549 debugInfo(colorTag(255,255,0).."WRN: Text " .. chatAction
.Says
.. " error")
1554 -- create emot action
1555 if tostring(chatAction
.Emote
) ~= "" and chatAction
.Emote
~= nil
1557 action
= r2
.newComponent("RtNpcEventHandlerAction")
1558 action
.Action
= "emot"
1559 action
.Parameters
= tostring(chatAction
.Emote
).."\n" .. who
1560 table.insert(rtMAction
.Children
, action
)
1563 -- create facing action
1564 if tostring(chatAction
.Facing
) ~= "" and chatAction
.Facing
~= nil
1566 local facing
= r2
.Utils
.getNpcParam(tostring(chatAction
.Facing
), context
)
1568 action
= r2
.newComponent("RtNpcEventHandlerAction")
1569 action
.Action
= "facing"
1570 action
.Parameters
= facing
.."\n" .. who
1571 table.insert(rtMAction
.Children
, action
)
1573 printWarning("Can not find npc")
1577 printWarning( chatAction
.Class
.. " not implemented yet")
1581 Logic
.translateChatStep
= function(context
, chatSequenceNumber
, chatSequence
, chatStepNumber
, chatStep
, rtActionSwitchChatStep
)
1584 assert(chatStep
.Class
== "ChatStep")
1586 if chatStep
.Actions
.Size
> 0 then
1588 local rtMAction
= r2
.Translator
.createAction("multi_actions")
1589 table.insert(rtActionSwitchChatStep
.Children
, rtMAction
)
1591 local k
, chatAction
= next(chatStep
.Actions
, nil)
1593 Logic
.translateChatAction(context
, chatSequenceNumber
, chatStepNumber
, chatSequence
, chatStep
, chatAction
, rtMAction
)
1595 local oldChatAction
= chatAction
1599 if (chatStepNumber
< chatSequence
.Components
.Size
and chatSequence
.Components
[chatStepNumber
]) then
1601 local action
= r2
.Translator
.createAction("code",
1602 "oldChatStepVar = " .. tostring(chatStepNumber
)..";\n" ..
1603 Logic
.chatStepVar
.." = " .. tostring(chatStepNumber
+1)..";\n" ..
1604 "()setTimer(" .. tostring(1+chatSequence
.Components
[chatStepNumber
].Time
*10) .. ", " .. Logic
.chatTimerId
.. ");\n");
1605 action
.Name
= "next"
1606 table.insert(rtMAction
.Children
, action
)
1609 local action
= r2
.Translator
.createAction("code",
1610 "oldChatStepVar = " .. tostring(chatStepNumber
)..";\n" ..
1611 Logic
.chatStepVar
.." = " .. tostring(chatStepNumber
+1)..";\n" ..
1612 "()setEvent(" ..Logic
.EndOfChatSequenceEvent
..");\n" ..
1613 "if (repeatSequence == 1)\n{\n " .. Logic
.chatSequenceVar
.."=" ..Logic
.chatSequenceVar
..";\n" ..
1616 action
.Name
= "end_of_chat_sequence"
1617 table.insert(rtMAction
.Children
, action
)
1626 k
, chatAction
= next(chatStep
.Actions
, k
)
1632 local action
= r2
.Translator
.createAction("null_action")
1633 action
.Name
= "empty_chat_step_" .. chatStepNumber
1634 table.insert(rtActionSwitchChatStep
.Children
, action
)
1639 Logic
.translateChatSequence
= function (context
, chatSequenceNumber
, chatSequence
, rtSwitchChatSequence
)
1640 assert(chatSequence
)
1641 assert(chatSequence
.Class
== "ChatSequence")
1642 if chatSequence
.Components
.Size
> 0 then
1644 local rtActionSwitchChatStep
= r2
.Translator
.createAction("switch_actions", Logic
.chatStepVar
)
1645 rtActionSwitchChatStep
.Name
= "switch_chat_step"
1646 table.insert(rtSwitchChatSequence
.Children
, rtActionSwitchChatStep
)
1648 local chatStepNumber
= 0
1652 local action
= r2
.Translator
.createAction("code", "oldChatStepVar = 0;\n"
1653 .. Logic
.chatStepVar
.." = 1;\n()setTimer(" .. tostring( tonumber(chatSequence
.Components
[0].Time
)*10 + 1) .. ", " .. Logic
.chatTimerId
..");\n");
1654 action
.Name
= "initial_wait"
1655 table.insert(rtActionSwitchChatStep
.Children
, action
)
1659 local k
, chatStep
= next(chatSequence
.Components
, nil)
1661 chatStepNumber
= chatStepNumber
+ 1
1662 Logic
.translateChatStep(context
, chatSequenceNumber
, chatSequence
, chatStepNumber
, chatStep
, rtActionSwitchChatStep
)
1663 k
, chatStep
= next(chatSequence
.Components
, k
)
1666 local action
= r2
.Translator
.createAction("null_action")
1667 action
.Name
= "empty_chat_sequence_" .. chatSequenceNumber
1668 table.insert(rtSwitchChatSequence
.Children
, action
)
1672 Logic
.translateChatSequences
= function (context
, hlComponent
, behavior
, rtNpcGrp
)
1673 assert(behavior
.ChatSequences
)
1674 if behavior
.ChatSequences
.Size
> 0 then
1678 local event
= r2
.Translator
.createEvent("variable_" ..Logic
.chatSequenceVar
.."_changed", "", rtNpcGrp
.Name
)
1679 event
.Name
= "activity_sequence_changed"
1680 table.insert(context
.RtAct
.Events
, event
)
1682 local rtInitChatStep
= r2
.Translator
.createAction("code", "oldChatStepVar = -1;\n" .. Logic
.chatStepVar
.." = 0;\n()setTimer(1, " ..Logic
.chatTimerId
.. ");\n")
1683 rtInitChatStep
.Name
= "init_chat_step"
1684 table.insert(context
.RtAct
.Actions
, rtInitChatStep
)
1685 table.insert(event
.ActionsId
, rtInitChatStep
.Id
)
1689 local event
= r2
.Translator
.createEvent("timer_" ..Logic
.chatTimer
.."_triggered", "", rtNpcGrp
.Name
)
1690 event
.Name
= "dialog_event"
1691 table.insert(context
.RtAct
.Events
, event
)
1693 local rtSwitchChatSequence
= r2
.Translator
.createAction("switch_actions", Logic
.chatSequenceVar
)
1694 rtSwitchChatSequence
.Name
= "switch_chat_sequence"
1695 table.insert(context
.RtAct
.Actions
, rtSwitchChatSequence
)
1696 table.insert(event
.ActionsId
, rtSwitchChatSequence
.Id
)
1698 local chatSequenceNumber
= 0
1699 local k
, chatSequence
= next(behavior
.ChatSequences
, nil)
1701 context
.Feature
= nil
1702 chatSequenceNumber
= chatSequenceNumber
+ 1
1703 Logic
.translateChatSequence(context
, chatSequenceNumber
, chatSequence
, rtSwitchChatSequence
)
1704 k
, chatSequence
= next(behavior
.ChatSequences
, k
)
1711 function Logic
.isWanderActivity(activity
)
1712 return activity
== "Wander" or activity
== "Go To Zone" or activity
== "Rest In Zone" or activity
== "Feed In Zone"
1713 or activity
== "Hunt In Zone" or activity
== "Guard Zone"
1717 -------------------------------------------------
1718 --create a transition to go to step number stepNb
1719 --set a timer to go to next step
1721 --goto the step's state
1722 Logic
.createTransition
= function(context
, hlComponent
, activitySequence
, activityStep
, activityStepIndex
, stepAction
)
1723 local findChatSequenceIdByInstanceId
= function (chat
)
1725 local parent
= chat
.ParentInstance
.ChatSequences
1729 local nbSequence
= 0
1730 local k
, sequence
= next(parent
, nil)
1732 if tostring(sequence
.InstanceId
) == tostring(chat
.InstanceId
) then return nbSequence
end
1733 nbSequence
= nbSequence
+ 1
1734 k
, sequence
= next(parent
, k
)
1739 assert(activityStep
)
1744 if activityStep
.Chat
~= "" then
1745 chat
= r2
:getInstanceFromId( tostring(activityStep
.Chat
) )
1751 local backupState
= ""
1752 local setChatSequence
= ""
1753 local setNextActivity
= ""
1754 local setNextActivityTimer
= ""
1755 local setNextActivityState
= ""
1759 "oldChatSequenceVar = " .. Logic
.chatSequenceVar
.. ";\n" ..
1760 "RoadCountLimit=0;\n"..
1761 "oldActivityStepVar = " .. Logic
.activityStepVar
.. ";\n" ..
1762 "oldActivityStepVar2 = " .. Logic
.activityStepVar
.. " + 1;\n"
1766 local id
= findChatSequenceIdByInstanceId( chat
)
1768 setChatSequence
= Logic
.chatSequenceVar
.. " = " .. tostring( id
) .. ";\n"
1769 if (activityStep
.Type
== "Repeating") then
1770 setChatSequence
= setChatSequence
.. "repeatSequence = 1;\n"
1772 setChatSequence
= setChatSequence
.. "repeatSequence = 0;\n"
1777 setNextActivity
= Logic
.activityStepVar
.. " = " .. activityStepIndex
..";\n"
1779 -- next activity timer
1780 local param
= Logic
.getTimeLimit(activityStep
)
1781 if param
~= nil then
1782 if Logic
.isWanderActivity(activityStep
.Activity
) then
1783 -- The time limite is use by the activity
1785 setNextActivityTimer
= "()setTimer(" .. param
..", " ..Logic
.activityStepTimerId
.. ");\n"
1789 local states
= Logic
.States
[activityStep
.InstanceId
]
1790 local stateName
= states
[1].Name
1792 -- next activity state
1794 setNextActivityState
= "()postNextState(\"" .. r2
.getNamespace() .. stateName
.."\");\n"
1795 local action
= r2
.Translator
.createAction("code", backupState
.. setChatSequence
.. setNextActivity
.. setNextActivityTimer
.. setNextActivityState
)
1798 action
.Name
= "process_activity_step" .. activityStepIndex
1801 local tmpAction
= r2
.Translator
.createAction("multi_actions")
1802 table.insert(tmpAction
.Children
, action
)
1803 table.insert(tmpAction
.Children
, stepAction
)
1807 action
.Name
= "process_activity_step" .. activityStepIndex
1813 ------------------------------------------
1814 --crée une action qui permet de
1815 --sélectionner une séquence de chat
1816 Logic
.selectDialog
= function(dialogNb
, rtNpcGrp
)
1819 if (rtNpcGrp
~= nil) then
1820 prefix
= r2
.getNamespace() .. rtNpcGrp
.. "."
1823 action
= r2
.Translator
.createAction("code",
1824 prefix
.."oldChatSequenceVar =" .. prefix
..Logic
.chatSequenceVar
..";\n" ..
1825 prefix
.. Logic
.chatSequenceVar
.." = " ..(dialogNb
-1)..";\n")
1826 action
.Name
= "select_dialog"
1830 --create the actions and events necessary to choose
1831 --the dialog while running sequence
1832 Logic
.initDialog
= function(context
)
1833 local event
= r2
.Translator
.createEvent("variable_" ..Logic
.chatSequenceVar
.."_changed", "all_sequence_states", context
.Group
.Name
)
1834 event
.Name
= "change_dialog_event"
1835 Logic
.DialogEvent2
= event
1837 local mAction
= r2
.Translator
.createAction("multi_actions")
1838 action
= r2
.Translator
.createAction("code", "oldChatStepVar = " .. Logic
.chatStepVar
..";\n" .. Logic
.chatStepVar
.." = 0;\n")
1839 action
.Name
= "reset_dialog"
1840 table.insert(mAction
.Children
, action
)
1841 action
= r2
.Translator
.createAction("switch_actions", Logic
.chatSequenceVar
)
1842 action
.Name
= "init_dialog_timer"
1843 table.insert(mAction
.Children
, action
)
1844 Logic
.DialogAction2
= action
1845 table.insert(context
.RtAct
.Events
, event
)
1846 table.insert(context
.RtAct
.Actions
, mAction
)
1847 table.insert(event
.ActionsId
, mAction
.Id
)
1850 event
= r2
.Translator
.createEvent("timer_" ..Logic
.chatTimer
.."_triggered", "all_sequence_states", context
.Group
.Name
)
1851 event
.Name
= "dialog_event"
1852 Logic
.DialogEvent
= event
1853 table.insert(context
.RtAct
.Events
, event
)
1855 Logic
.DialogAction
= r2
.Translator
.createAction("switch_actions", Logic
.chatSequenceVar
)
1856 table.insert(context
.RtAct
.Actions
, Logic
.DialogAction
)
1857 table.insert(event
.ActionsId
, Logic
.DialogAction
.Id
)
1860 Logic
.initSequence
= function(context
, rtNpcGrp
)
1864 event
= r2
.Translator
.createEvent("timer_" ..Logic
.activityStepTimer
.."_triggered", "all_sequence_states", rtNpcGrp
.Name
)
1865 event
.Name
= "sequence_event"
1866 Logic
.SequenceEvent
= event
1867 table.insert(context
.RtAct
.Events
, event
)
1869 Logic
.SequenceAction
= r2
.Translator
.createAction("switch_actions", Logic
.activityStepVar
)
1870 table.insert(context
.RtAct
.Actions
, Logic
.SequenceAction
)
1871 table.insert(event
.ActionsId
, Logic
.SequenceAction
.Id
)
1874 -- ust to implement translateEvents used to implement event created for implementing
1875 Logic
.translateEvent
= function( context
, hlComponent
, activitySequence
, activityStep
, activityStepIndex
, event
, rtNpcGrp
, statesByName
)
1877 -- context, groups, states, actionToAdd)
1878 local eventType
, eventParam
= Logic
.getEvent(event
)
1879 local eventHandler
= nil
1881 if context
.Events
[event
.InstanceId
] == nil
1883 eventHandler
= r2
.Translator
.createEvent(eventType
, states
, groups
)
1884 assert(eventHandler
~= nil)
1886 local stepAction
= Logic
.translateChatStep(context
, event
.Action
, nil)
1888 if actionToAdd
~= nil
1890 table.insert(stepAction
.Children
, actionToAdd
)
1893 assert(stepAction
~= nil)
1895 table.insert(context
.RtAct
.Actions
, stepAction
)
1896 table.insert(eventHandler
.ActionsId
, stepAction
.Id
)
1897 context
.Events
[event
.InstanceId
] = eventHandler
1899 eventHandler
= context
.Events
[event
.InstanceId
]
1901 if string.find(eventHandler
.StatesByName
, states
) == nil
1903 eventHandler
.StatesByName
= eventHandler
.StatesByName
.. "\n" .. states
1906 if string.find(eventHandler
.GroupsByName
, groups
) == nil
1908 eventHandler
.GroupsByName
= eventHandler
.GroupsByName
.. "\n" .. groups
1917 Logic
.translateEvents
= function(context
, hlComponent
, activitySequence
, activityStep
, activityStepIndex
, rtNpcGrp
, statesByName
)
1923 if activityStepIndex
== activitySequence
.Components
.Size
then
1928 local k
, eventId
= next(step
.EventsIds
, nil)
1930 local eventHandler
= r2
:getInstanceFromId(eventId
)
1931 assert(eventHandler
~= nil)
1934 if eventHandler
.Condition
.Type
== "At Destination" then
1935 if step
.Activity
== "Follow Route" and last
~= true then
1936 action
= Logic
.selectActivityStep(activityStepIndex
+ 1)
1940 --the event returned here is a RtNpcEventHandler
1941 event
= translateEvent(context
, groups
, states
, action
)
1942 assert(event
~= nil)
1944 table.insert(context
.RtAct
.Events
, event
)
1945 k
, eventId
= next(step
.EventsIds
, k
)
1949 --translate an activity step
1950 Logic
.translateActivityStep
= function(context
, hlComponent
, activitySequence
, activityStep
, activityStepIndex
, rtNpcGrp
)
1952 --translate this activity activityStep's events
1957 local groupsByName
= rtNpcGrp
.Name
1960 local aiScriptDebug
= false
1962 local activityStep
= activityStep
1964 if activityStep
.Chat
~= "" then
1965 chat
= r2
:getInstanceFromId(activityStep
.Chat
)
1967 printErr("translation error: in the activitySequence " .. activitySequence
.Name
.. " in component " .. hlComponent
.Name
.. ": " .. " the chat sequence associated to this activity sequence can not be found")
1972 local states
= Logic
.States
[activityStep
.InstanceId
]
1974 aiState
= states
[1] -- 1 is first ( a lua object not a instance )
1976 --setting state AiMovement
1977 aiState
.AiMovement
= Logic
.getAiMovement(activityStep
.Activity
)
1978 assert(aiState
.AiMovement
~= "")
1979 --setting state zone or road
1982 local positionalActivity
= {["Patrol"] = "road",
1983 ["Wander"] = "zone",
1984 ["Repeat Road"] = "road",
1985 ["Follow Route"] = "road",
1986 ["Rest In Zone"] = "zone",
1987 ["Feed In Zone"] = "zone",
1988 ["Hunt In Zone"] = "zone",
1989 ["Guard Zone"] = "zone",
1990 ["Go To Zone"] = "zone",
1992 if positionalActivity
[activityStep
.Activity
] then
1993 local zone
= r2
:getInstanceFromId(activityStep
.ActivityZoneId
)
1996 aiState
.AiMovement
= "idle"
1999 if positionalActivity
[activityStep
.Activity
] == "zone" then
2000 if table.getn(zone
.Points
) < 3 then
2002 aiState
.AiMovement
= "idle"
2006 if table.getn(zone
.Points
) < 2 then
2008 aiState
.AiMovement
= "idle"
2018 if activityStep
.Activity
== "Patrol" then
2019 local zone
= r2
:getInstanceFromId(activityStep
.ActivityZoneId
)
2022 printErr("translation error: in the activitySequence " .. activitySequence
.Name
.. " in component " .. hlComponent
.Name
.. ": " .. " the zone associated to the action can not be found")
2026 --un etat aller, un etat retour
2027 aiState2
= states
[2]
2028 aiState2
.AiMovement
= "follow_route"
2029 Logic
.assignZone(aiState
, zone
, false)
2030 Logic
.assignZone(aiState2
, zone
, true)
2032 statesByName
= aiState
.Name
.."\n" .. aiState2
.Name
2033 elseif activityStep
.Activity
== "Repeat Road" or activityStep
.Activity
== "Follow Route" or activityStep
.Activity
== "Wander"
2034 or activityStep
.Activity
== "Rest In Zone" or activityStep
.Activity
== "Feed In Zone" or activityStep
.Activity
== "Hunt In Zone"
2035 or activityStep
.Activity
== "Guard Zone" or activityStep
.Activity
== "Go To Zone" then
2036 local zone
= r2
:getInstanceFromId(activityStep
.ActivityZoneId
)
2037 if (zone
== nil) then
2038 printErr("translation error: in the activitySequence " .. activitySequence
.Name
.. " in component " .. hlComponent
.Name
.. ": " .. " the zone associated to the action can not be found")
2041 Logic
.assignZone(aiState
, zone
, false)
2042 statesByName
= aiState
.Name
2044 statesByName
= aiState
.Name
2048 if activityStep
.Activity
== "Repeat Road" then
2051 --when at end of the road, ...
2052 event
= r2
.Translator
.createEvent("destination_reached_all", statesByName
, groupsByName
)
2053 table.insert(context
.RtAct
.Events
, event
)
2054 --return to the start of the road
2055 local repeatCount
= activityStep
.RoadCountLimit
2056 if not repeatCount
then repeatCount
= 2 end
2058 action
= r2
.Translator
.createAction("next_road", groupsByName
, aiState
.Name
, activityStepIndex
, repeatCount
)
2059 table.insert(context
.RtAct
.Actions
, action
)
2060 table.insert(event
.ActionsId
, action
.Id
)
2062 elseif activityStep
.Activity
== "Patrol" then
2065 local repeatCount
= activityStep
.RoadCountLimit
2066 if not repeatCount
then repeatCount
= 2 end
2067 event
= r2
.Translator
.createEvent("destination_reached_all", aiState
.Name
, groupsByName
)
2068 table.insert(context
.RtAct
.Events
, event
)
2069 action
= r2
.Translator
.createAction("next_road", groupsByName
, aiState2
.Name
, activityStepIndex
, repeatCount
)
2070 action
.Name
= "return"
2071 table.insert(context
.RtAct
.Actions
, action
)
2072 table.insert(event
.ActionsId
, action
.Id
)
2074 event
= r2
.Translator
.createEvent("destination_reached_all", aiState2
.Name
, groupsByName
)
2075 table.insert(context
.RtAct
.Events
, event
)
2076 action
= r2
.Translator
.createAction("next_road", groupsByName
, aiState
.Name
, activityStepIndex
, repeatCount
)
2078 table.insert(context
.RtAct
.Actions
, action
)
2079 table.insert(event
.ActionsId
, action
.Id
)
2081 elseif activityStep
.Activity
== "Follow Route" or activityStep
.Activity
== "Go To Start Point" or activityStep
.Activity
== "Go To Zone" then
2084 event
= r2
.Translator
.createEvent("destination_reached_all", aiState
.Name
, groupsByName
)
2085 table.insert(context
.RtAct
.Events
, event
)
2086 action
= Logic
.selectActivityStep(activityStepIndex
+ 1)
2087 table.insert(context
.RtAct
.Actions
, action
)
2088 table.insert(event
.ActionsId
, action
.Id
)
2089 elseif activityStep
.Activity
== "Rest In Zone" then
2090 local wanderTime
= 100
2091 local restTime
= 300
2092 r2
.Translator
.createActivityInZone(context
, aiState
.Name
, groupsByName
, "Rest", Logic
.activityInternalTimerId
, wanderTime
, restTime
, aiScriptDebug
)
2093 elseif activityStep
.Activity
== "Feed In Zone" then
2094 local wanderTime
= 50
2095 local feedTime
= 150
2096 r2
.Translator
.createActivityInZone(context
, aiState
.Name
, groupsByName
, "Eat", Logic
.activityInternalTimerId
, wanderTime
, feedTime
, aiScriptDebug
)
2097 elseif activityStep
.Activity
== "Hunt In Zone" then
2098 local wanderTime
= 100
2099 local alertTime
= 25
2101 r2
.Translator
.createHuntActivityInZone(context
, aiState
.Name
, groupsByName
, Logic
.activityInternalTimerId
, wanderTime
, alertTime
, eatTime
, aiScriptDebug
)
2102 elseif activityStep
.Activity
== "Guard Zone" then
2103 r2
.Translator
.createSimpleActivityInZone(context
, aiState
.Name
, groupsByName
, "Alert", false, aiScriptDebug
)
2107 if Logic
.isWanderActivity(activityStep
.Activity
) and activityStep
.TimeLimit
== "Few Sec" then
2108 local event
= r2
.Translator
.createEvent("destination_reached_all", aiState
.Name
, groupsByName
)
2109 table.insert(context
.RtAct
.Events
, event
)
2110 local number = tonumber(activityStep
.TimeLimitValue
)
2111 if number == nil then
2114 local action
= r2
.Translator
.createAction("wander_destination_reached", groupsByName
, aiState
.Name
, activityStepIndex
, number)
2115 table.insert(context
.RtAct
.Actions
, action
)
2116 table.insert(event
.ActionsId
, action
.Id
)
2119 local stepAction
= nil
2120 if activityStep
.Activity
== "Stand Up" then
2121 stepAction
= r2
.Translator
.createAction("stand_up", rtNpcGrp
.Id
)
2122 elseif activityStep
.Activity
== "Sit Down" then
2123 stepAction
= r2
.Translator
.createAction("sit_down", rtNpcGrp
.Id
)
2127 -- translate event create by activitySequence (eg patrol)
2128 if activityStep
.EventsIds
.Size
~= 0
2130 Logic
.translateEvents(context
, hlComponent
, activitySequence
, activityStep
, activityStepIndex
, rtNpcGrp
, statesByName
)
2135 --go to next activityStep
2136 local action
= Logic
.createTransition(context
, hlComponent
, activitySequence
, activityStep
, activityStepIndex
, stepAction
)
2137 table.insert(Logic
.SequenceAction
.Children
, action
)
2140 -- if ActivityStep.TimeLimit == "Chat" creates a eventhandler to go to next state
2142 if activityStep
.TimeLimit
== "Chat" then
2147 local number = Logic
.findChatSequenceIdByInstanceId(hlComponent
, chat
.InstanceId
)
2148 if (number == nil or number == -1) then
2149 printWarning("Error in translation: in component '" .. hlComponent
.Name
.. " the chat sequence selected as time limit of Activity Step " .. activityStepIndex
.. " does not exist.")
2155 event
= r2
.Translator
.createEvent("user_event_8", aiState
.Name
, rtNpcGrp
.Id
)
2156 table.insert(context
.RtAct
.Events
, event
)
2160 condition
= r2
.Translator
.createAction("condition_if", "v0 == "..tostring(number-1))
2161 table.insert(context
.RtAct
.Actions
, condition
)
2164 action
= Logic
.selectActivityStep(activityStepIndex
+ 1)
2165 table.insert(condition
.Children
, action
)
2166 table.insert(event
.ActionsId
, condition
.Id
)
2175 ---------------------------------------------------------------------------------------
2176 --helpers functions--
2177 ---------------------------------------------------------------------------------------
2180 Logic
.getAiMovement
= function(activity
)
2181 assert(activity
and type(activity
) == "string")
2182 if (activity
== "Follow Route") or (activity
== "Patrol") or (activity
== "Repeat Road") then
2183 return "follow_route"
2184 elseif activity
== "Deploy" then
2185 return "stand_on_vertices"
2186 elseif activity
== "Wander" or activity
== "Go To Zone" or activity
== "Rest In Zone" or activity
== "Feed In Zone"
2187 or activity
== "Hunt In Zone" or activity
== "Guard Zone" then
2189 elseif activity
== "Stand Still" or activity
== "Inactive" or activity
== "Stand Up" or activity
== "Sit Down" then
2191 elseif activity
== "Stand On Start Point" or activity
== "Go To Start Point" then
2192 return "stand_on_start_point"
2195 printWarning("Undef activity '"..activity
.."'")
2200 Logic
.getAction
= function(action
)
2201 local action_type
= action
.Action
2203 if action_type
== "Sit Down"
2207 if action_type
== "Stand Up"
2211 if action_type
== "Go To Step"
2213 if action
.Parameter
== nil or action
.Parameter
== ""
2219 if action_type
== "Set Activity"
2221 if action
.Parameter
== nil or action
.Parameter
== ""
2225 return "set_activity"
2228 if action_type
== "Stop Actions"
2230 return "stop_actions"
2233 if action_type
== "Start Mission"
2235 return "start_mission"
2241 Logic
.getEvent
= function(Event
)
2242 local i
= Logic
.find(Logic
.EventTypes
, Event
.Condition
.SourceType
)
2256 if Event
.Condition
.Type
== "At Destination"
2258 return "destination_reached_all"
2261 if Event
.Condition
.Type
== "Is Attacked"
2263 return "group_under_attack"
2266 if Event
.Condition
.Type
== "Enters State"
2268 return "start_of_state"
2271 if Event
.Condition
.Type
== "Leaves State"
2273 return "end_of_state"
2275 if Event
.Condition
.Type
== "Activity Is"
2280 --State Machine event type
2285 --Counter event type
2288 local counterName
= Event
.Parameter
2291 if counterName
== nil
2296 if string.find(Event
.Condition
.Type
, "v%d_changed") ~= nil
2298 return "variable_" ..Event
.Condition
.Type
2301 if Event
.Condition
.Type
== "Equals"
2305 if Event
.Condition
.Type
== "Lesser"
2309 if Event
.Condition
.Type
== "Greater"
2321 param
= param
..Event
.Condition
.ConditionParameter
2323 return "variable_changed", param
2327 Logic
.checkEvent
= function(eventMode
, sourceType
, sourceId
, conditionType
, parameter
)
2328 local eventTypeInd
= Logic
.find(Logic
.EventTypes
, sourceType
)
2329 local conditionTypeInd
2330 if eventTypeInd
== nil
2335 --{"Time", "Place", "Entity or Group", "State Machine", "Counter"}
2337 conditionTypeInd
= Logic
.find(Logic
.ConditionTypes
[eventTypeInd
], conditionType
)
2338 if eventTypeInd
== nil
2344 if eventTypeInd
== 0
2349 if eventTypeInd
== 1
2353 --Entity or Group event type
2354 if eventTypeInd
== 2
2356 if parameter
== nil or parameter
== ""
2358 if conditionType
== "At Destination" or conditionType
== "Is Attacked"
2365 if conditionType
== "Enters State" or conditionType
== "Leaves State"
2374 --State Machine event type
2375 if eventTypeInd
== 3
2379 --Counter event type
2380 if eventTypeInd
== 4
2382 if string.find(conditionType
, "v%d_changed") ~= nil
2386 if conditionType
== "Lesser" or conditionType
== "Greater" or conditionType
== "Equals"
2396 Logic
.fillCondition
= function(condition
, sourceType
, sourceId
, conditionType
, conditionParameter
)
2397 condition
.SourceType
= sourceType
2398 condition
.SourceId
= sourceId
2399 condition
.Type
= conditionType
2400 condition
.ConditionParameter
= conditionParameter
2403 Logic
.fillEvent
= function(event
, eventMode
, sourceType
, sourceId
, conditionType
, conditionParameter
)
2404 if Logic
.checkEvent(eventMode
, sourceType
, sourceId
, conditionType
, conditionParameter
) == false
2410 Logic
.fillCondition(event
.Condition
, sourceType
, sourceId
, conditionType
, conditionParameter
)
2411 event
.EventMode
= eventMode
2414 -----------------------------------------
2415 --genere le parametre de l'action set_timer
2416 Logic
.getTimeLimit
= function(step
)
2419 if step
.TimeLimit
== "Few Sec" then
2420 local limit
= tonumber(step
.TimeLimitValue
)
2421 if limit
== nil then
2424 limit
= 1 + limit
* 10
2425 param
= tostring( limit
)
2431 Logic
.getActivityInitialStateName
= function(groupId
, activityNb
, context
)
2432 local group
= context
.Components
[groupId
]
2433 local activity
= group
.Components
[1].Behavior
.Activities
[activityNb
]
2440 local activityStates
= Logic
.ActivitiesStates
[activity
.InstanceId
]
2441 return activityStates
[activity
.InstanceId
][0].Name
2444 --return the states used to represent this step activity
2445 Logic
.getActivityStepStates
= function(activity
, stepNb
)
2446 local activityStates
= Logic
.ActivitiesStates
[activity
.InstanceId
]
2447 local states
= activityStates
[activity
.Components
[stepNb
].InstanceId
]
2451 Logic
.find
= function(array
, elem
)
2453 for k
, v
in pairs(array
)
2469 Logic
.findChatSequenceIdByInstanceIdImpl
= function(instance
, instanceId
)
2470 local behvior
= instance
:getBehavior()
2471 local k
, sequence
= next(behvior
.ChatSequences
, nil)
2472 local nbSequence
= 0
2474 nbSequence
= nbSequence
+ 1
2475 if tostring(sequence
.InstanceId
) == instanceId
then return nbSequence
end
2476 k
, sequence
= next(behvior
.ChatSequences
, k
)
2481 Logic
.findChatSequenceIdByInstanceId
= function(target
, instanceId
)
2482 local instance
=target
2483 return Logic
.findChatSequenceIdByInstanceIdImpl(instance
, instanceId
)
2487 -- target -> hlNpc or hlNpcGrp
2488 Logic
.findChatStepIdByInstanceId
= function(target
, instanceId
)
2489 assert( type(target
) == "userdata")
2490 local nbSequence
= 0
2493 local instance
= target
2494 assert(instance
~= nil)
2495 local behavior
= instance
:getBehavior()
2496 assert(behavior
~= nil)
2497 local k2
, sequence
= next(behavior
.ChatSequences
, nil)
2500 nbSequence
= nbSequence
+ 1
2502 local k
, step
= next(sequence
.Components
, nil)
2505 if tostring(step
.InstanceId
) == instanceId
then return {nbStep
, nbSequence
} end
2506 k
, step
= next(sequence
.Components
, k
)
2508 k2
, sequence
= next(behavior
.ChatSequences
, k2
)
2514 -- target is a NpcGrp or a Npc or a CustomNpc
2515 Logic
.findActivitySequenceIdByInstanceId
= function(target
, instanceId
)
2516 assert( type(target
) == "userdata")
2518 local nbSequence
= 0
2519 local behavior
= nil
2521 behavior
= target
:getBehavior()
2523 if behavior
== nil then
2524 debugInfo("Error: try to find activity Sequence on an unknown entity of type " .. target
.Class
)
2528 local npc
= behavior
.ParentInstance
2529 local grp
= behavior
.ParentInstance
.ParentInstance
2530 if not npc
:isGrouped() then grp
= nil end
2533 local k
, sequence
= next(behavior
.Activities
, nil)
2536 nbSequence
= nbSequence
+ 1
2537 if sequence
.InstanceId
== instanceId
then
2538 if grp
then return {nbSequence
, grp
} end
2539 if npc
then return {nbSequence
, npc
} end
2542 k
, sequence
= next(behavior
.Activities
, k
)
2547 Logic
.findActivityStepIdByInstanceId
= function(target
, instanceId
)
2548 assert( type(target
) == "userdata")
2549 local nbSequence
= 0
2552 local behavior
= comp
:getBehavior()
2554 local k
, sequence
= next(behavior
.Activities
, nil)
2557 if tostring(sequence
.InstanceId
) == instanceId
then
2558 assert(nil) -- use findActivityStep instead of findactivitySequence
2561 nbSequence
= nbSequence
+ 1
2563 local k2
, step
= next(sequence
.Components
, nil)
2566 if tostring(step
.InstanceId
) == instanceId
then return {nbStep
, nbSequence
} end
2567 k2
, step
= next(sequence
.Components
, k2
)
2569 k
, sequence
= next(behavior
.Activities
, k
)
2578 Logic
.selectActivityStep
= function(stepNb
)
2582 action
= r2
.Translator
.createAction("code",
2583 Logic
.activityStepVar
.. " = " .. stepNb
..";\n"
2584 .. "()setTimer(1, " ..Logic
.activityStepTimerId
.. ");\n")
2585 action
.Name
= "select_activity_step " .. stepNb
2592 ----------------------------------------------------------------------------
2593 -- add a line to the event menu
2595 local component
= Logic
.Components
.ChatSequence
2598 ----------------------------------------------------------------------------
2599 -- add a line to the event menu
2600 function component
:getLogicTranslations()
2602 local logicTranslations
= {
2603 ["ApplicableActions"] = {
2604 ["starts dialog"] = { menu
=i18n
.get( "uiR2AA0ChatSeqStart" ):toUtf8(),
2605 text
=i18n
.get( "uiR2AA1ChatSeqStart" ):toUtf8()},
2606 ["stops dialog"] = { menu
=i18n
.get( "uiR2AA0ChatSeqStop" ):toUtf8(),
2607 text
=i18n
.get( "uiR2AA1ChatSeqStop" ):toUtf8()},
2608 ["starts chat"] = { menu
=i18n
.get( "uiR2AA0ChatStepStart" ):toUtf8(),
2609 text
=i18n
.get( "uiR2AA1ChatStepStart" ):toUtf8()},
2610 ["continues dialog"] = { menu
=i18n
.get( "uiR2AA0ChatStepContinue" ):toUtf8(),
2611 text
=i18n
.get( "uiR2AA1ChatStepContinue" ):toUtf8()},
2614 ["start of dialog"] = { menu
=i18n
.get( "uiR2Event0ChatSeqStart" ):toUtf8(),
2615 text
=i18n
.get( "uiR2Event1ChatSeqStart" ):toUtf8()},
2616 ["end of dialog"] = { menu
=i18n
.get( "uiR2Event0ChatSeqEnd" ):toUtf8(),
2617 text
=i18n
.get( "uiR2Event1ChatSeqEnd" ):toUtf8()},
2618 ["start of chat"] = { menu
=i18n
.get( "uiR2Event0ChatStepStart" ):toUtf8(),
2619 text
=i18n
.get( "uiR2Event1ChatStepStart" ):toUtf8()},
2620 ["end of chat"] = { menu
=i18n
.get( "uiR2Event0ChatStepEnd" ):toUtf8(),
2621 text
=i18n
.get( "uiR2Event1ChatStepEnd" ):toUtf8()},
2624 ["is in dialog"] = { menu
=i18n
.get( "uiR2Test0ChatSeq" ):toUtf8(),
2625 text
=i18n
.get( "uiR2Test1ChatSeq" ):toUtf8()},
2626 ["is not in dialog"] = { menu
=i18n
.get( "uiR2Test0ChatNotSeq" ):toUtf8(),
2627 text
=i18n
.get( "uiR2Test1ChatNotSeq" ):toUtf8()},
2628 ["is in chat"] = { menu
=i18n
.get( "uiR2Test0ChatStep" ):toUtf8(),
2629 text
=i18n
.get( "uiR2Test1ChatStep" ):toUtf8()},
2632 return logicTranslations
2636 r2
.Features
["ActivitySequence"] = Logic