TeapotEvents.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #pragma once
  2. //========================================================================
  3. // TeapotEvents.h : defines game-specific events for TeapotWars
  4. //
  5. // Part of the GameCode4 Application
  6. //
  7. // GameCode4 is the sample application that encapsulates much of the source code
  8. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  9. // "Rez" Graham, published by Charles River Media.
  10. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  11. //
  12. // If this source code has found it's way to you, and you think it has helped you
  13. // in any way, do the authors a favor and buy a new copy of the book - there are
  14. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  15. // by clicking here:
  16. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  17. //
  18. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  19. //
  20. // The source code is managed and maintained through Google Code:
  21. // http://code.google.com/p/gamecode4/
  22. //
  23. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  24. //
  25. // This program is free software; you can redistribute it and/or
  26. // modify it under the terms of the GNU Lesser GPL v3
  27. // as published by the Free Software Foundation.
  28. //
  29. // This program is distributed in the hope that it will be useful,
  30. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  32. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  33. //
  34. // You should have received a copy of the GNU Lesser GPL v3
  35. // along with this program; if not, write to the Free Software
  36. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  37. //
  38. //========================================================================
  39. #include "../GCC4/EventManager/EventManager.h"
  40. #include "../GCC4/EventManager/Events.h"
  41. #include "../GCC4/LUAScripting/ScriptEvent.h"
  42. //---------------------------------------------------------------------------------------------------------------------
  43. // class EvtData_Set_Controlled_Actor - Chapter 10, 279
  44. //---------------------------------------------------------------------------------------------------------------------
  45. class EvtData_Set_Controlled_Actor : public ScriptEvent
  46. {
  47. ActorId m_id;
  48. public:
  49. static const EventType sk_EventType;
  50. EvtData_Set_Controlled_Actor(void) { }
  51. EvtData_Set_Controlled_Actor(ActorId actorId)
  52. : m_id(actorId)
  53. {
  54. }
  55. virtual const EventType& VGetEventType(void) const
  56. {
  57. return sk_EventType;
  58. }
  59. virtual IEventDataPtr VCopy() const
  60. {
  61. return IEventDataPtr(GCC_NEW EvtData_Set_Controlled_Actor(m_id));
  62. }
  63. virtual void VSerialize(std::ostrstream& out) const
  64. {
  65. out << m_id;
  66. }
  67. virtual void VDeserialize(std::istrstream& in)
  68. {
  69. in >> m_id;
  70. }
  71. const ActorId& GetActorId(void) const
  72. {
  73. return m_id;
  74. }
  75. virtual const char* GetName(void) const
  76. {
  77. return "EvtData_Set_Controlled_Actor";
  78. }
  79. virtual bool VBuildEventFromScript(void);
  80. EXPORT_FOR_SCRIPT_EVENT(EvtData_Set_Controlled_Actor);
  81. };
  82. //---------------------------------------------------------------------------------------------------------------------
  83. // class EvtData_ScriptEventTest - Chapter 10, 279
  84. //---------------------------------------------------------------------------------------------------------------------
  85. class EvtData_ScriptEventTest_ToLua : public ScriptEvent
  86. {
  87. int m_num;
  88. public:
  89. static const EventType sk_EventType;
  90. EvtData_ScriptEventTest_ToLua(void) { m_num = 0; }
  91. EvtData_ScriptEventTest_ToLua(int num) { m_num = num; }
  92. virtual const EventType& VGetEventType(void) const { return sk_EventType; }
  93. virtual IEventDataPtr VCopy(void) const
  94. {
  95. std::shared_ptr<EvtData_ScriptEventTest_ToLua> pCopy(GCC_NEW EvtData_ScriptEventTest_ToLua(m_num));
  96. pCopy->m_eventData = m_eventData;
  97. return pCopy;
  98. }
  99. virtual const char* GetName(void) const { return "EvtData_ScriptEventTest_ToLua"; }
  100. protected:
  101. virtual void VBuildEventData(void);
  102. //virtual bool VBuildEventFromScript(void);
  103. EXPORT_FOR_SCRIPT_EVENT(EvtData_ScriptEventTest_ToLua);
  104. };
  105. class EvtData_ScriptEventTest_FromLua : public ScriptEvent
  106. {
  107. int m_num;
  108. public:
  109. static const EventType sk_EventType;
  110. EvtData_ScriptEventTest_FromLua(void) { m_num = 0; }
  111. EvtData_ScriptEventTest_FromLua(int num) { m_num = num; }
  112. virtual const EventType& VGetEventType(void) const { return sk_EventType; }
  113. virtual IEventDataPtr VCopy(void) const
  114. {
  115. std::shared_ptr<EvtData_ScriptEventTest_FromLua> pCopy(GCC_NEW EvtData_ScriptEventTest_FromLua(m_num));
  116. pCopy->m_eventData = m_eventData;
  117. return pCopy;
  118. }
  119. virtual const char* GetName(void) const { return "EvtData_ScriptEventTest_FromLua"; }
  120. int GetNum(void) { return m_num; }
  121. protected:
  122. //virtual void VBuildEventData(void);
  123. virtual bool VBuildEventFromScript(void);
  124. EXPORT_FOR_SCRIPT_EVENT(EvtData_ScriptEventTest_FromLua);
  125. };
  126. void RegisterTeapotScriptEvents(void);