OGRPSEL.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #include <memory.h>
  21. #include <OGRPSEL.h>
  22. #include <OPOWER.h>
  23. #include <OUNIT.h>
  24. #include <ONATION.h>
  25. //--------------- begin of function GroupSelect::GroupSelect ----------------//
  26. GroupSelect::GroupSelect()
  27. {
  28. //memset(this, 0, sizeof(GroupSelect));
  29. }
  30. //--------------- end of function GroupSelect::GroupSelect ----------------//
  31. //--------------- begin of function GroupSelect::~GroupSelect ----------------//
  32. GroupSelect::~GroupSelect()
  33. {
  34. deinit();
  35. }
  36. //--------------- end of function GroupSelect::~GroupSelect ----------------//
  37. //--------------- begin of function GroupSelect::init ----------------//
  38. void GroupSelect::init()
  39. {
  40. }
  41. //--------------- end of function GroupSelect::init ----------------//
  42. //--------------- begin of function GroupSelect::deinit ----------------//
  43. void GroupSelect::deinit()
  44. {
  45. }
  46. //--------------- end of function GroupSelect::deinit ----------------//
  47. //--------------- begin of function GroupSelect::group_units ----------------//
  48. // <int> groupNum = 1 - MAX_SELECT_GROUP_NUM
  49. //
  50. void GroupSelect::group_units(int groupNum)
  51. {
  52. err_when(groupNum<1 || groupNum>MAX_SELECT_GROUP_NUM);
  53. Unit *unitPtr;
  54. int playerNation;
  55. if(!unit_array.selected_recno)
  56. return; // invalid call
  57. else
  58. {
  59. playerNation = nation_array.player_recno;
  60. unitPtr = unit_array[unit_array.selected_recno];
  61. if(unitPtr->nation_recno!=playerNation)
  62. return;
  63. }
  64. //---------- group selected units ----------//
  65. int arraySize = unit_array.size();
  66. for(int i=arraySize; i>0; --i)
  67. {
  68. if(unit_array.is_deleted(i))
  69. continue;
  70. unitPtr = unit_array[i];
  71. if(unitPtr->nation_recno!=playerNation)
  72. continue;
  73. if(unitPtr->selected_flag)
  74. unitPtr->group_select_id = groupNum; // new selected unit
  75. else if(unitPtr->group_select_id==groupNum) // old member in this group
  76. unitPtr->group_select_id = 0;
  77. }
  78. }
  79. //--------------- end of function GroupSelect::group_units ----------------//
  80. //--------------- begin of function GroupSelect::select_grouped_units ----------------//
  81. // <int> groupNum = 1 - MAX_SELECT_GROUP_NUM
  82. //
  83. void GroupSelect::select_grouped_units(int groupNum)
  84. {
  85. err_when(groupNum<1 || groupNum>MAX_SELECT_GROUP_NUM);
  86. int arraySize = unit_array.size();
  87. Unit *unitPtr;
  88. int playerNation = nation_array.player_recno;
  89. //---------- count selected units ----------//
  90. int groupUnitCount = 0;
  91. int i;
  92. for(i=arraySize; i>0; --i)
  93. {
  94. if(unit_array.is_deleted(i))
  95. continue;
  96. unitPtr = unit_array[i];
  97. if(unitPtr->nation_recno!=playerNation)
  98. continue;
  99. if(!unitPtr->is_visible())
  100. continue;
  101. if(unitPtr->group_select_id==groupNum)
  102. {
  103. groupUnitCount++;
  104. break;
  105. }
  106. }
  107. if(!groupUnitCount)
  108. return;
  109. power.reset_selection();
  110. //---------- select units in this group ----------//
  111. Unit *showSelectedUnitPtr = NULL;
  112. unit_array.selected_count = 0;
  113. for(i=arraySize; i>0; --i)
  114. {
  115. if(unit_array.is_deleted(i))
  116. continue;
  117. unitPtr = unit_array[i];
  118. if(unitPtr->nation_recno!=playerNation)
  119. continue;
  120. if(!unitPtr->is_visible())
  121. continue;
  122. if(unitPtr->group_select_id==groupNum)
  123. {
  124. unitPtr->selected_flag = 1;
  125. unit_array.selected_count++;
  126. if(showSelectedUnitPtr==NULL || unitPtr->hit_points>showSelectedUnitPtr->hit_points)
  127. showSelectedUnitPtr = unitPtr;
  128. }
  129. }
  130. if(showSelectedUnitPtr)
  131. {
  132. unit_array.selected_recno = showSelectedUnitPtr->sprite_recno;
  133. info.disp();
  134. }
  135. }
  136. //--------------- end of function GroupSelect::select_grouped_units ----------------//