home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / Dema / ankh_demo_en.exe / media / lua / PinaAPI.lua < prev    next >
Encoding:
Text File  |  2005-09-14  |  23.8 KB  |  508 lines

  1. ---------------------------------------------------------------------------
  2. ---------------------- API functions --------------------------------------
  3. ---------------------------------------------------------------------------
  4. -- The functions defined here simplify the access to (some of)           --
  5. -- the C++ classes and methods exported by the PinaCore C++ dll.         --
  6. ---------------------------------------------------------------------------
  7.  
  8. -- the (empty) table that will store the functions
  9. api={}
  10.  
  11. function api:playMusic(p_File)
  12.    --local soundMgr = getFMODSoundManager()
  13.    --soundMgr:playMusic(p_File)
  14. end
  15.  
  16. function api:playEffect(p_File)
  17.    --local soundMgr = getFMODSoundManager()
  18.    --soundMgr:playSample(p_File)
  19.    SoundMgr:playFile(p_File)
  20. end
  21.  
  22. function sound(p_File)
  23.    SoundMgr:playFile(p_File .. ".ogg")
  24. end
  25.  
  26. function api:playEffect_(p_File, p_Volume)
  27.    --local soundMgr = getFMODSoundManager()
  28.    --local channel = soundMgr:playSample(p_File)
  29.    --soundMgr:setVolume(channel, p_Volume)
  30. end
  31.  
  32. function api:animateMusicVolume(p_TargetVolume)
  33.    --local soundMgr = getFMODSoundManager()
  34.    --soundMgr:animateMusicVolume(p_TargetVolume)
  35. end
  36.  
  37. ---------------------------------------------------------------------------
  38. -- fades the screen to black
  39. ---------------------------------------------------------------------------
  40. function api:fadeOut()
  41.    GameStateMgr:fadeOut(1.0)
  42. end
  43. ---------------------------------------------------------------------------
  44.  
  45. ---------------------------------------------------------------------------
  46. -- fades the screen to black in the given amount of time (in seconds)
  47. ---------------------------------------------------------------------------
  48. function api:fadeOut_(p_BlendTime)
  49.    GameStateMgr:fadeOut(p_BlendTime)
  50. end
  51. ---------------------------------------------------------------------------
  52.  
  53. ---------------------------------------------------------------------------
  54. -- fades the screen from black
  55. ---------------------------------------------------------------------------
  56. function api:fadeIn()
  57.    GameStateMgr:fadeIn(1.0)
  58. end
  59. ---------------------------------------------------------------------------
  60.  
  61. ---------------------------------------------------------------------------
  62. -- sets the visibility of the plate covering the whole screen
  63. ---------------------------------------------------------------------------
  64. function api:setPlateVisible(p_Visible)
  65.    if p_Visible then
  66.       GameStateMgr:showPlate()
  67.    else
  68.       GameStateMgr:hidePlate()
  69.    end
  70. end
  71. ---------------------------------------------------------------------------
  72.  
  73. ---------------------------------------------------------------------------
  74. -- shows the plate covering the whole screen
  75. ---------------------------------------------------------------------------
  76. function api:showPlate()
  77.    api:setPlateVisible(true)
  78. end
  79. ---------------------------------------------------------------------------
  80.  
  81. ---------------------------------------------------------------------------
  82. -- hides the plate covering the whole screen
  83. ---------------------------------------------------------------------------
  84. function api:hidePlate()
  85.    api:setPlateVisible(false)
  86. end
  87. ---------------------------------------------------------------------------
  88.  
  89. ---------------------------------------------------------------------------
  90. -- fades the screen from black in the given amount of time (in seconds)
  91. ---------------------------------------------------------------------------
  92. function api:fadeIn_(p_BlendTime)
  93.    GameStateMgr:fadeIn(p_BlendTime)
  94. end
  95. ---------------------------------------------------------------------------
  96.  
  97. ---------------------------------------------------------------------------
  98. -- starts the conversation with the given name using a blend time of 1 second
  99. -- if the conversation does not exist, it will be created
  100. ---------------------------------------------------------------------------
  101. function api:conversation(p_ConversationName)
  102.    -- check if the conversation already exists - create it if this is not the case
  103.    if ConversationMgr:queryConversation(p_ConversationName) == ConversationManager.CS_NON_EXISTENT then
  104.       ConversationMgr:createConversation(p_ConversationName)
  105.    end
  106.    -- we made sure the conversation exists, so we can safely start it
  107.    ConversationMgr:startConversation(p_ConversationName,1.0)
  108. end
  109. ---------------------------------------------------------------------------
  110.  
  111. ---------------------------------------------------------------------------
  112. -- starts the conversation with the given name using the given blend time
  113. -- if the conversation does not exist, it will be created
  114. ---------------------------------------------------------------------------
  115. function api:conversation_(p_ConversationName, p_BlendTime)
  116.    -- check if the conversation already exists - create it if this is not the case
  117.    if ConversationMgr:queryConversation(p_ConversationName) == ConversationManager.CS_NON_EXISTENT then
  118.       ConversationMgr:createConversation(p_ConversationName)
  119.    end
  120.    -- we made sure the conversation exists, so we can safely start it
  121.    ConversationMgr:startConversation(p_ConversationName,p_BlendTime)
  122. end
  123. ---------------------------------------------------------------------------
  124.  
  125. ---------------------------------------------------------------------------
  126. -- starts the conversation with the given name using a blend time of 1 second
  127. -- if the conversation does not exist, it will be created
  128. -- In addition, the given lua function will be executed when the conversation
  129. -- has come to an end
  130. ---------------------------------------------------------------------------
  131. function api:conversation__(p_ConversationName, p_LuaFunctionOnConversationFinished)
  132.    -- check if the conversation already exists - create it if this is not the case
  133.    if ConversationMgr:queryConversation(p_ConversationName) == ConversationManager.CS_NON_EXISTENT then
  134.       ConversationMgr:createConversation(p_ConversationName)
  135.    end
  136.    -- we made sure the conversation exists, so we can safely start it
  137.    ConversationMgr:startConversation(p_ConversationName,1.0)
  138.    subscribeConversationFinished(p_ConversationName, p_LuaFunctionOnConversationFinished)
  139. end
  140. ---------------------------------------------------------------------------
  141.  
  142. ---------------------------------------------------------------------------
  143. -- starts the conversation with the given name using the given blend time
  144. -- if the conversation does not exist, it will be created
  145. ---------------------------------------------------------------------------
  146. function api:conversation___(p_ConversationName, p_BlendTime, p_LuaFunctionOnFinished)
  147.    -- check if the conversation already exists - create it if this is not the case
  148.    if ConversationMgr:queryConversation(p_ConversationName) == ConversationManager.CS_NON_EXISTENT then
  149.       ConversationMgr:createConversation(p_ConversationName)
  150.    end
  151.    -- we made sure the conversation exists, so we can safely start it
  152.    ConversationMgr:startConversation(p_ConversationName,p_BlendTime)
  153.    subscribeConversationFinished(p_ConversationName, p_LuaFunctionOnFinished)
  154. end
  155. ---------------------------------------------------------------------------
  156.    
  157. ---------------------------------------------------------------------------
  158. -- cancels the given conversation (if it is running)
  159. ---------------------------------------------------------------------------
  160. function api:cancelConversation(p_ConversationName)
  161.    ConversationMgr:cancelConversation(p_ConversationName)
  162. end
  163. ---------------------------------------------------------------------------
  164.  
  165. ---------------------------------------------------------------------------
  166. -- starts the cutscene with the given name using a blend time of 1 second
  167. -- if the cutscene does not exist, it will be created
  168. ---------------------------------------------------------------------------
  169. function api:cutscene(p_CutsceneName)
  170.    -- check if the cutscene already exists - create it if this is not the case
  171.    if CutsceneMgr:queryCutscene(p_CutsceneName) == CutsceneManager.CS_NON_EXISTENT then
  172.       CutsceneMgr:createCutscene(p_CutsceneName)
  173.    end
  174.    -- we made sure the cutscene exists, so we can safely start it
  175.    CutsceneMgr:startCutscene(p_CutsceneName,1.0)
  176. end
  177. ---------------------------------------------------------------------------
  178.  
  179. ---------------------------------------------------------------------------
  180. -- starts the cutscene with the given name using the given blend time
  181. -- if the cutscene does not exist, it will be created
  182. ---------------------------------------------------------------------------
  183. function api:cutscene_(p_CutsceneName, p_BlendTime)
  184.    -- check if the cutscene already exists - create it if this is not the case
  185.    if CutsceneMgr:queryCutscene(p_CutsceneName) == CutsceneManager.CS_NON_EXISTENT then
  186.       CutsceneMgr:createCutscene(p_CutsceneName)
  187.    end
  188.    -- we made sure the cutscene exists, so we can safely start it
  189.    CutsceneMgr:startCutscene(p_CutsceneName,p_BlendTime)
  190. end
  191. ---------------------------------------------------------------------------
  192.  
  193. ---------------------------------------------------------------------------
  194. -- starts the cutscene with the given name using a blend time of 1 second
  195. -- if the cutscene does not exist, it will be created
  196. ---------------------------------------------------------------------------
  197. function api:cutscene__(p_CutsceneName, p_LuaFunctionOnFinished)
  198.    -- check if the cutscene already exists - create it if this is not the case
  199.    if CutsceneMgr:queryCutscene(p_CutsceneName) == CutsceneManager.CS_NON_EXISTENT then
  200.       CutsceneMgr:createCutscene(p_CutsceneName)
  201.    end
  202.    -- we made sure the cutscene exists, so we can safely start it
  203.    CutsceneMgr:startCutscene(p_CutsceneName,1.0)
  204.    subscribeCutsceneFinished(p_CutsceneName, p_LuaFunctionOnFinished)
  205. end
  206. ---------------------------------------------------------------------------
  207.  
  208. ---------------------------------------------------------------------------
  209. -- starts the cutscene with the given name using the given blend time
  210. -- if the cutscene does not exist, it will be created
  211. ---------------------------------------------------------------------------
  212. function api:cutscene___(p_CutsceneName, p_BlendTime, p_LuaFunctionOnFinished)
  213.    -- check if the cutscene already exists - create it if this is not the case
  214.    if CutsceneMgr:queryCutscene(p_CutsceneName) == CutsceneManager.CS_NON_EXISTENT then
  215.       CutsceneMgr:createCutscene(p_CutsceneName)
  216.    end
  217.    -- we made sure the cutscene exists, so we can safely start it
  218.    CutsceneMgr:startCutscene(p_CutsceneName, p_BlendTime)
  219.    subscribeCutsceneFinished(p_CutsceneName, p_LuaFunctionOnFinished)
  220. end
  221. ---------------------------------------------------------------------------
  222.  
  223. ---------------------------------------------------------------------------
  224. -- creates the converation with the given name
  225. ---------------------------------------------------------------------------
  226. function api:createConversation(p_ConversationName)
  227.    -- check if the conversation already exists, log a warning if that is the case
  228.    if ConversationMgr:queryConversation(p_ConversationName) == ConversationManager.CS_NON_EXISTENT then
  229.       ConversationMgr:createConversation(p_ConversationName)
  230.    else
  231.       _LogWarning(p_ConversationName,"conversation already exists")
  232.    end
  233. end
  234. ---------------------------------------------------------------------------
  235.  
  236. ---------------------------------------------------------------------------
  237. -- creates the cutscene with the given name
  238. ---------------------------------------------------------------------------
  239. function api:createCutscene(p_CutsceneName)
  240.    -- check if the conversation already exists, log a warning if that is the case
  241.    if CutsceneMgr:queryCutscene(p_CutsceneName) == CutsceneManager.CS_NON_EXISTENT then
  242.       CutsceneMgr:createCutscene(p_CutsceneName)
  243.    else
  244.       _LogWarning(p_CutsceneName,"cutscene already exists")
  245.    end
  246. end
  247. ---------------------------------------------------------------------------
  248.  
  249. ---------------------------------------------------------------------------
  250. -- subscribes the given lua function to the EventFinished event of the
  251. -- given conversation
  252. ---------------------------------------------------------------------------
  253. function api:subscribeConversationFinished(p_ConversationName, p_FunctionName)
  254.    -- check if the conversation already exists, log a warning if that is not the case
  255.    if ConversationMgr:queryConversation(p_ConversationName) == ConversationManager.CS_NON_EXISTENT then
  256.       _LogWarning(p_ConversationName,"api:subscribeConversationFinished: conversation does not exist")
  257.       ConversationMgr:createConversation(p_ConversationName)
  258.    end
  259.    ConversationMgr:subscribeConversationEvent(p_ConversationName,
  260.                           "ConversationFinished",
  261.                           p_FunctionName,
  262.                           true)
  263. end
  264. ---------------------------------------------------------------------------
  265.  
  266. ---------------------------------------------------------------------------
  267. -- subscribes the given lua function to the EventFinished event of the
  268. -- given cutscene
  269. ---------------------------------------------------------------------------
  270. function api:subscribeCutsceneFinished(p_CutsceneName, p_FunctionName)
  271.    -- check if the cutscene already exists, log a warning if that is not the case
  272.    if CutsceneMgr:queryCutscene(p_CutsceneName) == CutsceneManager.CS_NON_EXISTENT then
  273.       _LogWarning(p_CutsceneName,"api:subscribeCutsceneFinished: cutscene does not exist")
  274.       CutsceneMgr:createCutscene(p_CutsceneName)
  275.    end
  276.    CutsceneMgr:subscribeCutsceneEvent(p_CutsceneName,
  277.                       "EventCutsceneFinished",
  278.                       p_FunctionName,
  279.                       true)
  280. end
  281. ---------------------------------------------------------------------------
  282.  
  283. ---------------------------------------------------------------------------
  284. -- subscribes the given lua function to the named event of the given cutscene
  285. ---------------------------------------------------------------------------
  286. function api:subscribeConversationEvent(p_ConversationName, p_EventName, p_FunctionName)
  287.    -- check if the conversation already exists, log a warning if that is not the case
  288.    if ConversationMgr:queryConversation(p_ConversationName) == ConversationManager.CS_NON_EXISTENT then
  289.       _LogWarning(p_ConversationName,"subscribeConversationFinished: conversation does not exist")
  290.       createConversation(p_ConversationName)
  291.    end
  292.    ConversationMgr:subscribeConversationEvent(p_ConversationName,
  293.                           p_EventName,
  294.                           p_FunctionName,
  295.                           true)
  296. end
  297. ---------------------------------------------------------------------------
  298.  
  299. ---------------------------------------------------------------------------
  300. -- subscribes the given lua function to the named event of the given cutscene
  301. ---------------------------------------------------------------------------
  302. function api:subscribeCutsceneEvent(p_CutsceneName, p_EventName, p_FunctionName)
  303.    -- check if the cutscene already exists, log a warning if that is not the case
  304.    if CutsceneMgr:queryCutscene(p_CutsceneName) == CutsceneManager.CS_NON_EXISTENT then
  305.       _LogWarning(p_CutsceneName,"subscribeCutsceneFinished: cutscene does not exist")
  306.       createCutscene(p_CutsceneName)
  307.    end
  308.    CutsceneMgr:subscribeCutsceneEvent(p_CutsceneName,
  309.                       p_EventName,
  310.                       p_FunctionName,
  311.                       true)
  312. end
  313. ---------------------------------------------------------------------------
  314.  
  315. ---------------------------------------------------------------------------
  316. -- reinitializes the game meta data from the database
  317. ---------------------------------------------------------------------------
  318. function api:reinitializeFromDatabase()
  319.    _LogInfo("api:reinitializeFromDatabase", "InteractionMgr...")
  320.    InteractionMgr:initializeFromDatabase()
  321.    _LogInfo("api:reinitializeFromDatabase", "InteractorConfigurationMgr...")
  322.    InteractorConfigurationMgr:initializeFromDatabase()
  323.    if App:isUsingLocalizedStringTables() then
  324.       _LogInfo("api:reinitializeFromDatabase", "StringTable...")
  325.       StringTable:initializeFromDatabase()
  326.    end
  327.    _LogInfo("api:reinitializeFromDatabase", "Resetting Configs...")
  328.    GameEntityMgr:resetInteractorConfigurations()
  329. end
  330. ---------------------------------------------------------------------------
  331.  
  332. ---------------------------------------------------------------------------
  333. -- sets the visibility of the current's location objects by type
  334. ---------------------------------------------------------------------------
  335. function api:setObjectsVisibleByType(p_ObjectType, p_Visible)
  336.    local location=LocationMgr:getLocation(LocationMgr:getCurrentLocation())
  337.    location:setInteractorsVisible(p_ObjectType, p_Visible)
  338. end
  339. ---------------------------------------------------------------------------
  340.  
  341. ---------------------------------------------------------------------------
  342. -- activates the camera with the given name
  343. ---------------------------------------------------------------------------
  344. function api:camera(p_CameraName)
  345.    CameraMgr:activateCamera(p_CameraName,0.0)
  346. end
  347. ---------------------------------------------------------------------------
  348.  
  349. ---------------------------------------------------------------------------
  350. -- lua does not support function overloading, so we add an underscore
  351. ---------------------------------------------------------------------------
  352. function api:camera_(p_CameraName, p_BlendTime)
  353.    CameraMgr:activateCamera(p_CameraName, p_BlendTime)
  354. end
  355. ---------------------------------------------------------------------------
  356.  
  357. ---------------------------------------------------------------------------
  358. -- executes the (lua) script with the given file name
  359. ---------------------------------------------------------------------------
  360. function api:script(p_ScriptName)
  361.    LuaInterpreter:executeScript(p_ScriptName)
  362. end
  363. ---------------------------------------------------------------------------
  364.  
  365. ---------------------------------------------------------------------------
  366. -- attaches the Controller named @a p_AnimName to the Controllable object
  367. -- named @a p_Controllable and plays the animation
  368. ---------------------------------------------------------------------------
  369. function api:animation(p_Controllable, p_AnimName)
  370.    local controller=ControllerMgr:getController(p_AnimName)
  371.    controller:setCycleType(AnimationController.Detach)
  372.    controller:reset()
  373.    controller:setAnimationLocality(AnimationController.Global)
  374.    local obj=GameEntityMgr:getGameEntity(p_Controllable)
  375.    obj:attachController(p_AnimName)
  376.    ControllerMgr:resumeController(p_AnimName)
  377. end
  378. ---------------------------------------------------------------------------
  379.  
  380. ---------------------------------------------------------------------------
  381. -- attaches the Controller named @a p_AnimName to the Controllable object
  382. -- named @a p_Controllable and plays the animation
  383. ---------------------------------------------------------------------------
  384. function api:_animation(p_Controllable, p_AnimName, p_BlockTime)
  385.    local ctrlName = p_Controllable .. "/" .. p_AnimName
  386.    local controller=ControllerMgr:getController(ctrlName)
  387.    controller:setCycleType(AnimationController.Detach)
  388.    controller:reset()
  389.    controller:setAnimationLocality(AnimationController.Global)
  390.    local obj=GameEntityMgr:getGameEntity(p_Controllable)
  391.    obj:attachController(ctrlName)
  392.    ControllerMgr:resumeController(ctrlName)
  393.    MouseIface:blockInput(p_BlockTime)
  394. end
  395. ---------------------------------------------------------------------------
  396.  
  397. ---------------------------------------------------------------------------
  398. -- attaches the Animated Object named @a p_AnimObj to the Character
  399. -- named @a p_Character on the Bone named @a p_Bone only if not already
  400. -- attached
  401. ---------------------------------------------------------------------------
  402. function api:attachToBoneSafely(p_Character, p_AnimObj, p_Bone)
  403.    local character = GameEntityMgr:getCharacter(p_Character)
  404.    if not character:isAttachedToBone(p_AnimObj) then
  405.       character:attachToBone(p_AnimObj,p_Bone)
  406.    end
  407. end
  408. ---------------------------------------------------------------------------
  409.  
  410. ---------------------------------------------------------------------------
  411. -- detaches the Animated Object named @a p_AnimObj from the Character
  412. -- named @a p_Character only if it is really attached
  413. ---------------------------------------------------------------------------
  414. function api:detachFromBoneSafely(p_Character, p_AnimObj)
  415.    local character = GameEntityMgr:getCharacter(p_Character)
  416.    if character:isAttachedToBone(p_AnimObj) then
  417.       character:detachFromBone(p_AnimObj)
  418.    end
  419. end
  420. ---------------------------------------------------------------------------
  421.  
  422. ---------------------------------------------------------------------------
  423. ---------------------------------------------------------------------------
  424. function api:checkIactors(p_Interactor, p_InteractedInteractor,
  425.               p_InteractorString, p_InteractedInteractorString)
  426.    if (p_Interactor == p_InteractorString and 
  427.        p_InteractedInteractor == p_InteractedInteractorString) or
  428.       (p_Interactor == p_InteractedInteractorString and
  429.        p_InteractedInteractor == p_InteractorString) then
  430.       return true
  431.    else
  432.       return false
  433.    end
  434. end
  435. ---------------------------------------------------------------------------
  436.  
  437. ---------------------------------------------------------------------------
  438. ---------------------------------------------------------------------------
  439. function iaction(p_Interactor, p_InteractedInteractor,
  440.          p_InteractorString, p_InteractedInteractorString)
  441.    if (p_Interactor == p_InteractorString and 
  442.        p_InteractedInteractor == p_InteractedInteractorString) or
  443.       (p_Interactor == p_InteractedInteractorString and
  444.        p_InteractedInteractor == p_InteractorString) then
  445.       return true
  446.    else
  447.       return false
  448.    end
  449. end
  450. ---------------------------------------------------------------------------
  451.  
  452. ---------------------------------------------------------------------------
  453. -- toggles the control gui window visibility
  454. ---------------------------------------------------------------------------
  455. function api:toggleGUIWindow(p_GUIWindow)
  456.    if GUIWindowMgr:isVisible(p_GUIWindow) then
  457.       GUIWindowMgr:setVisible(p_GUIWindow, false)
  458.    else
  459.       GUIWindowMgr:setVisible(p_GUIWindow, true)
  460.    end
  461. end
  462. ---------------------------------------------------------------------------
  463.  
  464. ---------------------------------------------------------------------------
  465. -- adds the given item to the inventory (if it is not there alredy)
  466. ---------------------------------------------------------------------------
  467. function give(p_Item)
  468.    Inventory:addItemSafely("item_" .. p_Item)
  469. end
  470. ---------------------------------------------------------------------------
  471. ---------------------------------------------------------------------------
  472. -- removes the given item to the inventory (if it is not there already)
  473. ---------------------------------------------------------------------------
  474. function takeAway(p_Item)
  475.    Inventory:removeItemSafely("item_" .. p_Item)
  476. end
  477. ---------------------------------------------------------------------------
  478.  
  479. ---------------------------------------------------------------------------
  480. -- calls the function after the given amount of time
  481. ---------------------------------------------------------------------------
  482. function api:callDelayed(p_Function, p_Time)
  483.    TimedEventMgr:createTimedEvent(p_Function, p_Time)
  484. end
  485. ---------------------------------------------------------------------------
  486.  
  487. ---------------------------------------------------------------------------
  488. --
  489. ---------------------------------------------------------------------------
  490. function msg(p_Text)
  491.    App:showDebugText(p_Text, 2.0)
  492. end
  493. ---------------------------------------------------------------------------
  494.  
  495. function api:setMainCharacter(p_Character)
  496.    if GameEntityMgr:getMainCharacter() ~= p_Character then
  497.       Ankh:toggleMainChar()
  498.    end
  499. end
  500. ---------------------------------------------------------------------------
  501. function api:getDistanceSqr(p_Vec1,p_Vec2)
  502.    local x = p_Vec1.x-p_Vec2.x
  503.    local y = p_Vec1.y-p_Vec2.y
  504.    local z = p_Vec1.z-p_Vec2.z
  505.    return PinaVector3(x,y,z):getNormSqr()
  506. end
  507. ---------------------------------------------------------------------------
  508.