/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt You may alternatively use this source under the terms of a specific version of the OpenSpace3D Unrestricted License provided you have obtained such a license from I-maginer. ----------------------------------------------------------------------------- */ struct PlugPandC = [ PAC_xmlDef : XMLfile, PAC_sState : S, PAC_bEnable : I ]mkPlugPandC;; fun deleteOb(inst, confstr)= 0;; fun hideshowsentences(sentencemark, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in ( let XMLgetMarksByValueFromMark sentencemark "showsentence" -> listshowmark in let sizelist listshowmark -> sizeshow in ( let 0 -> i in while i < sizeshow do ( let XMLgetParam (nth_list listshowmark i) "sentenceId" -> idwanted in let XMLgetMarkByValueAndParamValueFromMark xmlroot "sentence" "sentenceId" idwanted -> changedmark in XMLsetParam changedmark "visible" "true"; set i = i + 1; ); ); let XMLgetMarksByValueFromMark sentencemark "hideSentence" -> listhidemark in let sizelist listhidemark -> sizehide in ( let 0 -> j in while j < sizehide do ( let XMLgetParam (nth_list listhidemark j) "sentenceId" -> idwanted in let XMLgetMarkByValueAndParamValueFromMark xmlroot "sentence" "sentenceId" idwanted -> changedmark2 in XMLsetParam changedmark2 "visible" "false"; set j = j + 1; ); ); ); 0;; fun throwinventoryobject(inst, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarksByValueAndParamValueFromMark xmlroot "item" "canTake" "true" -> inventorymarks in let sizelist inventorymarks -> size in let nil -> res in ( let 0 -> i in while (i < size) do ( let nth_list inventorymarks i -> itemMark in set res = strcat res (XMLserializeFromMark itemMark); set i = i + 1; ); _DMSevent this (getPluginInstanceEvent inst "Load Xml") oneLineTransform res "" nil; ); 0;; fun throwevents(xmlfile, inst, param) = let XMLgetMarksByValueFromMark xmlfile "Event" -> xmlEvents in let sizelist xmlEvents -> nbItems in let 0 -> i in ( while i < nbItems do ( let nth_list xmlEvents i -> event in ( let XMLgetParam event "name" -> paramevent in if (paramevent == nil) || (!strcmp "" strtrim paramevent) then nil else ( _DMSevent this (getPluginInstanceEvent inst paramevent) param nil; ); ); set i = i + 1; ); );; fun showsentence(usemark, inst, param, state, pacstr )= let sizelist usemark.XMLsons -> nbsentences in if(nbsentences == 0) then nil else ( if (XMLgetBoolParam usemark "random") then ( let (mod rand nbsentences) -> i in let nth_list usemark.XMLsons i -> sentenceMark in ( let strcatn param::"\n"::(oneLineTransform XMLserializeFromMark sentenceMark "")::nil -> params in _DMSevent this (getPluginInstanceEvent inst state) params nil; hideshowsentences sentenceMark pacstr; let XMLgetMarkByValueFromMarkSons sentenceMark "text" -> textmark in throwevents textmark inst param; ); 0; ) else ( if (XMLgetBoolParam usemark "loop") then ( if (atoi (XMLgetParam usemark "id")) >= (nbsentences - 1) then nil else XMLsetParam usemark "id" "0"; let atoi (XMLgetParam usemark "id") -> i in let if (i == nil) then 0 else i -> i in let nth_list usemark.XMLsons i -> sentenceMark in ( let strcatn param::"\n"::(oneLineTransform XMLserializeFromMark sentenceMark "")::nil -> params in _DMSevent this (getPluginInstanceEvent inst state) params nil; hideshowsentences sentenceMark pacstr; let XMLgetMarkByValueFromMarkSons sentenceMark "text" -> textmark in throwevents textmark inst param; let if (i == (nbsentences - 1)) then 0 else i + 1 -> newidx in XMLsetParam usemark "id" (itoa newidx); ); 0; ) else ( let atoi XMLgetParam usemark "id" -> i in let if (i == nil) then 0 else i -> i in let nth_list usemark.XMLsons i -> sentenceMark in ( hideshowsentences sentenceMark pacstr; let strcatn param::"\n"::(oneLineTransform XMLserializeFromMark sentenceMark "")::nil -> params in _DMSevent this (getPluginInstanceEvent inst state) params nil; let XMLgetMarkByValueFromMarkSons sentenceMark "text" -> textmark in throwevents textmark inst param; let if (i == (nbsentences - 1)) then i else i + 1 -> newidx in XMLsetParam usemark "id" (itoa newidx); ); 0; ); ); ); 0;; fun cbPushEvent(inst, from, action, param, reply, pacstr)= if(!pacstr.PAC_bEnable) then nil else ( _DMSevent this (getPluginInstanceEvent inst param) nil nil; ); 0;; fun cbLoadItems(inst, from, action, param, reply, pacstr)= if(!pacstr.PAC_bEnable) then nil else ( set pacstr.PAC_sState = "normal"; throwinventoryobject inst pacstr; //To throw the init events let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in ( let XMLgetMarkByValueFromMarkSons xmlroot "GameData" -> initmark in ( throwevents initmark inst "Init"; let XMLgetMarkByValueFromMarkSons initmark "Player" -> playermark in ( let XMLgetMarkByValueFromMark playermark "position" -> positionmark in let strcatnSep (XMLgetParam positionmark "x")::(XMLgetParam positionmark "y")::(XMLgetParam positionmark "z")::nil " " -> params in _DMSevent this (getPluginInstanceEvent inst "get position") params nil ; let XMLgetMarkByValueFromMark playermark "rotation" -> rotationmark in let strcatnSep (XMLgetParam rotationmark "qw")::(XMLgetParam rotationmark "qz")::(XMLgetParam rotationmark "qy")::(XMLgetParam rotationmark "qx")::nil " " -> params in _DMSevent this (getPluginInstanceEvent inst "get rotation") params nil ; let XMLgetParam XMLgetMarkByValueFromMark initmark "Timer" "seconds" -> timerwanted in _DMSevent this (getPluginInstanceEvent inst "Time") timerwanted nil ; ); ); let XMLgetMarksByValueFromMark xmlroot "Item" -> listItems in ( let sizelist listItems -> size in let 0 -> i in while i < size do ( let nth_list listItems i -> itemMark in if(!strcmpi (XMLgetParam itemMark "visible") "true") then ( _DMSevent this (getPluginInstanceEvent inst "ShowItem") (XMLgetParam itemMark "name") nil ; 0; ) else ( _DMSevent this (getPluginInstanceEvent inst "HideItem") (XMLgetParam itemMark "name") nil ; ); set i = i + 1; ); ); ); ); 0;; fun cbItemAction(inst, from, action, param, reply, pacstr)= if(!pacstr.PAC_bEnable) then nil else ( let strtrim param -> param in let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" param -> itemmark in //I want to take the piece of xml where the objet we've got on the param is described //let addLogMessage strcat "Xml de l'objet" (XMLserializeFromMark itemmark) -> _ in if (itemmark == nil) then nil else if (!strcmpi pacstr.PAC_sState "look") then ( //I want to take the description contained in the "look" Mark let XMLgetMarkByValueFromMarkSons itemmark "Look" -> lookmark in showsentence lookmark inst param "Look" pacstr; 0; ) else ( if (!strcmpi pacstr.PAC_sState "talk") then ( //I want to take the xml contained in the "talk" Mark let XMLgetMarkByValueFromMarkSons itemmark "talk" -> talkmark in let nth_list talkmark.XMLsons 0 -> firstact in let strcatn param::"\n"::(oneLineTransform XMLserializeFromMark firstact "")::nil -> params in _DMSevent this (getPluginInstanceEvent inst "Talk") params nil ; 0; ) else ( if (!strcmpi pacstr.PAC_sState "use") then ( //I want to take the xml contained in the "Use" Mark let XMLgetMarkByValueAndParamValueFromMarkSons itemmark "use" "with" "alone" -> usemark in showsentence usemark inst param "Use" pacstr; 0; ) else ( if (!strcmpi pacstr.PAC_sState "normal") then ( 0; ) else ( if(!strcmpi itoa sizelist XMLgetMarksByValueAndParamValueFromMark itemmark "use" "with" pacstr.PAC_sState itoa 0) then ( _DMSevent this (getPluginInstanceEvent inst "Push Use With") nil nil; let XMLgetMarkByValueAndParamValueFromMarkSons itemmark "use" "with" "noCombinaison" -> usemark in showsentence usemark inst param "Use" pacstr; 0; ) else ( let XMLgetMarkByValueAndParamValueFromMark itemmark "use" "with" pacstr.PAC_sState -> usemark in showsentence usemark inst param "Use" pacstr; _DMSevent this (getPluginInstanceEvent inst "Push Use With") nil nil; ); ); ); ); ); ); 0;; fun cbContinueDesc(inst, from, action, param, reply, pacstr) = if(!pacstr.PAC_bEnable) then nil else ( let strToListSep param "\n" -> paramlist in let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" (nth_list paramlist 1) -> itemmark in ( let XMLgetMarkByValueAndParamValueFromMark itemmark "sentence" "sentenceId" (nth_list paramlist 0) -> sentencemark in ( let XMLgetMarkByValueFromMarkSons sentencemark "EndEvent" -> eventmark in throwevents eventmark inst (nth_list paramlist 1); ); ); 0; ); 0;; fun cbBeginDial(inst, from, action, param, reply, pacstr) = if(!pacstr.PAC_bEnable) then nil else ( let strToListSep param "\n" -> paramlist in let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" (nth_list paramlist 1) -> itemmark in let XMLgetMarkByValueAndParamValueFromMark itemmark "sentence" "sentenceId" (nth_list paramlist 0) -> sentencemark in let XMLgetMarkByValueFromMarkSons sentencemark "text" -> textmark in throwevents textmark inst (nth_list paramlist 1); ); 0;; fun cbContinueDial(inst, from, action, param, reply, pacstr) = if(!pacstr.PAC_bEnable) then nil else ( let strToListSep param "\n" -> paramlist in let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" (nth_list paramlist 1) -> itemmark in ( let XMLgetMarkByValueAndParamValueFromMark itemmark "sentence" "sentenceId" (nth_list paramlist 0) -> sentencemark in ( let XMLgetMarkByValueFromMarkSons sentencemark "pnjText" -> pnjmark in throwevents pnjmark inst (nth_list paramlist 1); hideshowsentences sentencemark pacstr; let XMLgetParam XMLgetMarkByValueFromMark sentencemark "goTo" "act" -> i in let XMLgetMarkByValueFromMark itemmark "Talk" -> talkmark in let XMLgetMarkByValueAndParamValueFromMarkSons talkmark "Acts" "act" i -> nextmark in let strcatn (nth_list paramlist 1)::"\n"::(oneLineTransform XMLserializeFromMark nextmark "")::nil -> params in _DMSevent this (getPluginInstanceEvent inst "Talk") params nil ; ); ); ); 0;; fun cbSetState(inst, from, action, param, reply, pacstr) = if (param == nil) then nil else ( set pacstr.PAC_sState = param; ); 0;; fun cbEnable(inst, from, action, param, reply, pacstr) = set pacstr.PAC_bEnable = 1; let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueFromMarkSons xmlroot "GameData" -> initmark in let XMLgetMarkByValueFromMark initmark "Scene" -> scenemark in let XMLgetParam scenemark "range" -> idwanted in _DMSevent this (getPluginInstanceEvent inst "Scene ID") idwanted nil ; 0;; fun cbDisable(inst, from, action, param, reply, pacstr) = set pacstr.PAC_bEnable = 0; 0;; fun cbGetData(inst, from, action, param, reply, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let strcatn param::"\n"::(oneLineTransform XMLserializeFromMark xmlroot "")::nil -> params in _DMSevent this (getPluginInstanceEvent inst "Xml data") params nil; 0;; fun cbSetData(inst, from, action, param, reply, pacstr) = let XMLloadString param -> xmlfile in set pacstr.PAC_xmlDef = xmlfile; cbLoadItems inst from action nil reply pacstr; cbEnable inst from action nil reply pacstr; //Make a more correct test of the loading here _DMSevent this (getPluginInstanceEvent inst "Load succeded") nil nil; 0;; fun cbSetTime(inst, from, action, param, reply, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueFromMarkSons xmlroot "GameData" -> initmark in let XMLgetMarkByValueFromMark initmark "Timer" -> timemark in XMLsetParam timemark "seconds" param; 0;; fun cbSetPos(inst, from, action, param, reply, pacstr) = let strToListSep param " " -> paramlist in let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueFromMarkSons xmlroot "GameData" -> initmark in let XMLgetMarkByValueFromMarkSons initmark "Player" -> playermark in let XMLgetMarkByValueFromMark initmark "position" -> posmark in ( XMLsetParam posmark "z" (nth_list paramlist 2); XMLsetParam posmark "y" (nth_list paramlist 1); XMLsetParam posmark "x" (nth_list paramlist 0); ); 0;; fun cbSetRot(inst, from, action, param, reply, pacstr) = let strToListSep param " " -> paramlist in let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueFromMarkSons xmlroot "GameData" -> initmark in let XMLgetMarkByValueFromMarkSons initmark "Player" -> playermark in let XMLgetMarkByValueFromMark initmark "rotation" -> rotmark in ( XMLsetParam rotmark "qw" (nth_list paramlist 3); XMLsetParam rotmark "qz" (nth_list paramlist 2); XMLsetParam rotmark "qy" (nth_list paramlist 1); XMLsetParam rotmark "qx" (nth_list paramlist 0); ); 0;; fun cbdisableItem(inst, from, action, param, reply, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" param -> itemmark in XMLsetParam itemmark "inInventory" "false"; 0;; fun cbaddItem(inst, from, action, param, reply, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" param -> itemmark in XMLsetParam itemmark "inInventory" "true"; 0;; fun cbSetVisible(inst, from, action, param, reply, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" param -> itemmark in XMLsetParam itemmark "visible" "true"; 0;; fun cbSetInvisible(inst, from, action, param, reply, pacstr) = let XMLgetMarkByValue pacstr.PAC_xmlDef "root" -> xmlroot in let XMLgetMarkByValueAndParamValueFromMarkSons xmlroot "item" "name" param -> itemmark in XMLsetParam itemmark "visible" "false"; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "path") -> xmlpath in let atoi (getPluginInstanceParam inst "init") -> playinit in let (getPluginInstanceParam inst "state") -> state in let XMLload xmlpath -> xmlfilestr in let mkPlugPandC [xmlfilestr state 0] -> pacstr in ( PluginRegisterAction inst "Receive click Item" mkfun6 @cbItemAction pacstr; PluginRegisterAction inst "Set state" mkfun6 @cbSetState pacstr; PluginRegisterAction inst "Load the scene" mkfun6 @cbLoadItems pacstr; PluginRegisterAction inst "End of the Sentence" mkfun6 @cbContinueDial pacstr; PluginRegisterAction inst "End of the description" mkfun6 @cbContinueDesc pacstr; PluginRegisterAction inst "Beginning of the Sentence" mkfun6 @cbBeginDial pacstr; PluginRegisterAction inst "add item inventory" mkfun6 @cbaddItem pacstr; PluginRegisterAction inst "disable item inventory" mkfun6 @cbdisableItem pacstr; PluginRegisterAction inst "Enable" mkfun6 @cbEnable pacstr; PluginRegisterAction inst "Disable" mkfun6 @cbDisable pacstr; PluginRegisterAction inst "Get Xml Data" mkfun6 @cbGetData pacstr; PluginRegisterAction inst "Set Xml Data" mkfun6 @cbSetData pacstr; PluginRegisterAction inst "Set Time" mkfun6 @cbSetTime pacstr; PluginRegisterAction inst "Set Position" mkfun6 @cbSetPos pacstr; PluginRegisterAction inst "Set Rotation" mkfun6 @cbSetRot pacstr; PluginRegisterAction inst "Set Item Visible" mkfun6 @cbSetVisible pacstr; PluginRegisterAction inst "Set Item Invisible" mkfun6 @cbSetInvisible pacstr; set pacstr.PAC_bEnable = playinit; setPluginInstanceCbDel inst mkfun2 @deleteOb pacstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;