2
0

BattleUnitsChanged.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * api/netpacks/BattleUnitsChanged.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "BattleUnitsChanged.h"
  12. #include "../../LuaStack.h"
  13. #include "../Registry.h"
  14. namespace scripting
  15. {
  16. namespace api
  17. {
  18. namespace netpacks
  19. {
  20. VCMI_REGISTER_SCRIPT_API(BattleUnitsChangedProxy, "netpacks.BattleUnitsChanged");
  21. const std::vector<BattleUnitsChangedProxy::RegType> BattleUnitsChangedProxy::REGISTER =
  22. {
  23. {
  24. "toNetpackLight",
  25. &PackForClientProxy<BattleUnitsChangedProxy>::toNetpackLight
  26. },
  27. {
  28. "add",
  29. &BattleUnitsChangedProxy::add
  30. },
  31. {
  32. "update",
  33. &BattleUnitsChangedProxy::update
  34. },
  35. {
  36. "resetState",
  37. &BattleUnitsChangedProxy::resetState
  38. },
  39. {
  40. "remove",
  41. &BattleUnitsChangedProxy::remove
  42. }
  43. };
  44. const std::vector<BattleUnitsChangedProxy::CustomRegType> BattleUnitsChangedProxy::REGISTER_CUSTOM =
  45. {
  46. {"new", &Wrapper::constructor, true}
  47. };
  48. int BattleUnitsChangedProxy::add(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
  49. {
  50. LuaStack S(L);
  51. uint32_t id;
  52. if(!S.tryGet(1, id))
  53. return S.retVoid();
  54. UnitChanges changes(id, BattleChanges::EOperation::ADD);
  55. if(!S.tryGet(2, changes.data))
  56. return S.retVoid();
  57. if(!S.tryGet(3, changes.healthDelta))
  58. changes.healthDelta = 0;
  59. object->changedStacks.push_back(changes);
  60. return S.retVoid();
  61. }
  62. int BattleUnitsChangedProxy::update(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
  63. {
  64. LuaStack S(L);
  65. uint32_t id;
  66. if(!S.tryGet(1, id))
  67. return S.retVoid();
  68. UnitChanges changes(id, BattleChanges::EOperation::UPDATE);
  69. if(!S.tryGet(2, changes.data))
  70. return S.retVoid();
  71. if(!S.tryGet(3, changes.healthDelta))
  72. changes.healthDelta = 0;
  73. object->changedStacks.push_back(changes);
  74. return S.retVoid();
  75. }
  76. int BattleUnitsChangedProxy::resetState(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
  77. {
  78. LuaStack S(L);
  79. return S.retVoid();
  80. }
  81. int BattleUnitsChangedProxy::remove(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
  82. {
  83. LuaStack S(L);
  84. return S.retVoid();
  85. }
  86. }
  87. }
  88. }