Handle UI Plan.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "Tactical All.h"
  3. #else
  4. #include "Handle UI Plan.h"
  5. #include "overhead.h"
  6. #include "Isometric Utils.h"
  7. #include "pathai.h"
  8. #include "Handle UI.h"
  9. #include "points.h"
  10. #include "weapons.h"
  11. #include "renderworld.h"
  12. #include "Animation Control.h"
  13. #include "message.h"
  14. #include "soldier create.h"
  15. #include "interface.h"
  16. #endif
  17. UINT8 gubNumUIPlannedMoves = 0;
  18. SOLDIERTYPE *gpUIPlannedSoldier = NULL;
  19. SOLDIERTYPE *gpUIStartPlannedSoldier = NULL;
  20. BOOLEAN gfInUIPlanMode = FALSE;
  21. void SelectPausedFireAnimation( SOLDIERTYPE *pSoldier );
  22. BOOLEAN BeginUIPlan( SOLDIERTYPE *pSoldier )
  23. {
  24. gubNumUIPlannedMoves = 0;
  25. gpUIPlannedSoldier = pSoldier;
  26. gpUIStartPlannedSoldier = pSoldier;
  27. gfInUIPlanMode = TRUE;
  28. gfPlotNewMovement = TRUE;
  29. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Entering Planning Mode" );
  30. return( TRUE );
  31. }
  32. BOOLEAN AddUIPlan( UINT16 sGridNo, UINT8 ubPlanID )
  33. {
  34. SOLDIERTYPE *pPlanSoldier;
  35. INT16 sXPos, sYPos;
  36. INT16 sAPCost = 0;
  37. INT8 bDirection;
  38. INT32 iLoop;
  39. SOLDIERCREATE_STRUCT MercCreateStruct;
  40. UINT8 ubNewIndex;
  41. // Depeding on stance and direction facing, add guy!
  42. // If we have a planned action here, ignore!
  43. // If not OK Dest, ignore!
  44. if ( !NewOKDestination( gpUIPlannedSoldier, sGridNo, FALSE, (INT8)gsInterfaceLevel ) )
  45. {
  46. return( FALSE );
  47. }
  48. if ( ubPlanID == UIPLAN_ACTION_MOVETO )
  49. {
  50. // Calculate cost to move here
  51. sAPCost = PlotPath( gpUIPlannedSoldier, sGridNo, COPYROUTE, NO_PLOT, TEMPORARY, (UINT16) gpUIPlannedSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, gpUIPlannedSoldier->bActionPoints );
  52. // Adjust for running if we are not already running
  53. if ( gpUIPlannedSoldier->usUIMovementMode == RUNNING )
  54. {
  55. sAPCost += AP_START_RUN_COST;
  56. }
  57. if ( EnoughPoints( gpUIPlannedSoldier, sAPCost, 0, FALSE ) )
  58. {
  59. memset( &MercCreateStruct, 0, sizeof( MercCreateStruct ) );
  60. MercCreateStruct.bTeam = SOLDIER_CREATE_AUTO_TEAM;
  61. MercCreateStruct.ubProfile = NO_PROFILE;
  62. MercCreateStruct.fPlayerPlan = TRUE;
  63. MercCreateStruct.bBodyType = gpUIPlannedSoldier->ubBodyType;
  64. MercCreateStruct.sInsertionGridNo = sGridNo;
  65. // Get Grid Corrdinates of mouse
  66. if ( TacticalCreateSoldier( &MercCreateStruct, &ubNewIndex ) )
  67. {
  68. // Get pointer to soldier
  69. GetSoldier( &pPlanSoldier, (UINT16)ubNewIndex );
  70. pPlanSoldier->sPlannedTargetX = -1;
  71. pPlanSoldier->sPlannedTargetY = -1;
  72. // Compare OPPLISTS!
  73. // Set ones we don't know about but do now back to old ( ie no new guys )
  74. for (iLoop = 0; iLoop < MAX_NUM_SOLDIERS; iLoop++ )
  75. {
  76. if ( gpUIPlannedSoldier->bOppList[ iLoop ] < 0 )
  77. {
  78. pPlanSoldier->bOppList[ iLoop ] = gpUIPlannedSoldier->bOppList[ iLoop ];
  79. }
  80. }
  81. // Get XY from Gridno
  82. ConvertGridNoToCenterCellXY( sGridNo, &sXPos, &sYPos );
  83. EVENT_SetSoldierPosition( pPlanSoldier, sXPos, sYPos );
  84. EVENT_SetSoldierDestination( pPlanSoldier, sGridNo );
  85. pPlanSoldier->bVisible = 1;
  86. pPlanSoldier->usUIMovementMode = gpUIPlannedSoldier->usUIMovementMode;
  87. pPlanSoldier->bActionPoints = gpUIPlannedSoldier->bActionPoints - sAPCost;
  88. pPlanSoldier->ubPlannedUIAPCost = (UINT8)pPlanSoldier->bActionPoints;
  89. // Get direction
  90. bDirection = (INT8)gpUIPlannedSoldier->usPathingData[ gpUIPlannedSoldier->usPathDataSize - 1 ];
  91. // Set direction
  92. pPlanSoldier->bDirection = bDirection;
  93. pPlanSoldier->bDesiredDirection = bDirection;
  94. // Set walking animation
  95. ChangeSoldierState( pPlanSoldier, pPlanSoldier->usUIMovementMode, 0, FALSE );
  96. // Change selected soldier
  97. gusSelectedSoldier = (UINT16)pPlanSoldier->ubID;
  98. // Change global planned mode to this guy!
  99. gpUIPlannedSoldier = pPlanSoldier;
  100. gubNumUIPlannedMoves++;
  101. gfPlotNewMovement = TRUE;
  102. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Adding Merc Move to Plan" );
  103. }
  104. }
  105. else
  106. {
  107. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Merc will not have enough action points" );
  108. }
  109. }
  110. else if ( ubPlanID == UIPLAN_ACTION_FIRE )
  111. {
  112. sAPCost = CalcTotalAPsToAttack( gpUIPlannedSoldier, sGridNo, TRUE, (INT8)(gpUIPlannedSoldier->bShownAimTime /2) );
  113. // Get XY from Gridno
  114. ConvertGridNoToCenterCellXY( sGridNo, &sXPos, &sYPos );
  115. // If this is a player guy, show message about no APS
  116. if ( EnoughPoints( gpUIPlannedSoldier, sAPCost, 0, FALSE ) )
  117. {
  118. // CHECK IF WE ARE A PLANNED SOLDIER OR NOT< IF SO< CREATE!
  119. if ( gpUIPlannedSoldier->ubID < MAX_NUM_SOLDIERS )
  120. {
  121. memset( &MercCreateStruct, 0, sizeof( MercCreateStruct ) );
  122. MercCreateStruct.bTeam = SOLDIER_CREATE_AUTO_TEAM;
  123. MercCreateStruct.ubProfile = NO_PROFILE;
  124. MercCreateStruct.fPlayerPlan = TRUE;
  125. MercCreateStruct.bBodyType = gpUIPlannedSoldier->ubBodyType;
  126. MercCreateStruct.sInsertionGridNo = sGridNo;
  127. // Get Grid Corrdinates of mouse
  128. if ( TacticalCreateSoldier( &MercCreateStruct, &ubNewIndex ) )
  129. {
  130. // Get pointer to soldier
  131. GetSoldier( &pPlanSoldier, (UINT16)ubNewIndex );
  132. pPlanSoldier->sPlannedTargetX = -1;
  133. pPlanSoldier->sPlannedTargetY = -1;
  134. // Compare OPPLISTS!
  135. // Set ones we don't know about but do now back to old ( ie no new guys )
  136. for (iLoop = 0; iLoop < MAX_NUM_SOLDIERS; iLoop++ )
  137. {
  138. if ( gpUIPlannedSoldier->bOppList[ iLoop ] < 0 )
  139. {
  140. pPlanSoldier->bOppList[ iLoop ] = gpUIPlannedSoldier->bOppList[ iLoop ];
  141. }
  142. }
  143. EVENT_SetSoldierPosition( pPlanSoldier, gpUIPlannedSoldier->dXPos, gpUIPlannedSoldier->dYPos );
  144. EVENT_SetSoldierDestination( pPlanSoldier, gpUIPlannedSoldier->sGridNo );
  145. pPlanSoldier->bVisible = 1;
  146. pPlanSoldier->usUIMovementMode = gpUIPlannedSoldier->usUIMovementMode;
  147. pPlanSoldier->bActionPoints = gpUIPlannedSoldier->bActionPoints - sAPCost;
  148. pPlanSoldier->ubPlannedUIAPCost = (UINT8)pPlanSoldier->bActionPoints;
  149. // Get direction
  150. bDirection = (INT8)gpUIPlannedSoldier->usPathingData[ gpUIPlannedSoldier->usPathDataSize - 1 ];
  151. // Set direction
  152. pPlanSoldier->bDirection = bDirection;
  153. pPlanSoldier->bDesiredDirection = bDirection;
  154. // Set walking animation
  155. ChangeSoldierState( pPlanSoldier, pPlanSoldier->usUIMovementMode, 0, FALSE );
  156. // Change selected soldier
  157. gusSelectedSoldier = (UINT16)pPlanSoldier->ubID;
  158. // Change global planned mode to this guy!
  159. gpUIPlannedSoldier = pPlanSoldier;
  160. gubNumUIPlannedMoves++;
  161. }
  162. }
  163. gpUIPlannedSoldier->bActionPoints = gpUIPlannedSoldier->bActionPoints - sAPCost;
  164. gpUIPlannedSoldier->ubPlannedUIAPCost = (UINT8)gpUIPlannedSoldier->bActionPoints;
  165. // Get direction from gridno
  166. bDirection = (INT8)GetDirectionFromGridNo( sGridNo, gpUIPlannedSoldier );
  167. // Set direction
  168. gpUIPlannedSoldier->bDirection = bDirection;
  169. gpUIPlannedSoldier->bDesiredDirection = bDirection;
  170. // Set to shooting animation
  171. SelectPausedFireAnimation( gpUIPlannedSoldier );
  172. gpUIPlannedSoldier->sPlannedTargetX = sXPos;
  173. gpUIPlannedSoldier->sPlannedTargetY = sYPos;
  174. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Adding Merc Shoot to Plan" );
  175. }
  176. else
  177. {
  178. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Merc will not have enough action points" );
  179. }
  180. }
  181. return( TRUE );
  182. }
  183. void EndUIPlan( )
  184. {
  185. int cnt;
  186. SOLDIERTYPE *pSoldier;
  187. // Zero out any planned soldiers
  188. for( cnt = MAX_NUM_SOLDIERS; cnt < TOTAL_SOLDIERS; cnt++ )
  189. {
  190. pSoldier = MercPtrs[ cnt ];
  191. if ( pSoldier->bActive )
  192. {
  193. if ( pSoldier->sPlannedTargetX != -1 )
  194. {
  195. SetRenderFlags(RENDER_FLAG_FULL );
  196. }
  197. TacticalRemoveSoldier( pSoldier->ubID );
  198. }
  199. }
  200. gfInUIPlanMode = FALSE;
  201. gusSelectedSoldier = gpUIStartPlannedSoldier->ubID;
  202. gfPlotNewMovement = TRUE;
  203. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Leaving Planning Mode" );
  204. }
  205. BOOLEAN InUIPlanMode( )
  206. {
  207. return( gfInUIPlanMode );
  208. }
  209. void SelectPausedFireAnimation( SOLDIERTYPE *pSoldier )
  210. {
  211. // Determine which animation to do...depending on stance and gun in hand...
  212. switch ( gAnimControl[ pSoldier->usAnimState ].ubEndHeight )
  213. {
  214. case ANIM_STAND:
  215. if ( pSoldier->bDoBurst > 0 )
  216. {
  217. ChangeSoldierState( pSoldier, STANDING_BURST, 2 , FALSE );
  218. }
  219. else
  220. {
  221. ChangeSoldierState( pSoldier, SHOOT_RIFLE_STAND, 2 , FALSE );
  222. }
  223. break;
  224. case ANIM_PRONE:
  225. ChangeSoldierState( pSoldier, SHOOT_RIFLE_PRONE, 2 , FALSE );
  226. break;
  227. case ANIM_CROUCH:
  228. ChangeSoldierState( pSoldier, SHOOT_RIFLE_CROUCH, 2 , FALSE );
  229. break;
  230. }
  231. }