TEAMTYPE.CPP 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /CounterStrike/TEAMTYPE.CPP 1 3/03/97 10:25a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : TEAMTYPE.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 06/28/96 *
  30. * *
  31. * Last Update : July 30, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * TeamMissionClass::Description -- Compose a text description of team mi *
  36. * TeamMissionClass::Draw_It -- Draws a team mission list box entry. *
  37. * TeamMission_Needs -- Determines what extra data is needed by team miss *
  38. * TeamTypeClass::As_Pointer -- gets ptr for team type with given name *
  39. * TeamTypeClass::Build_INI_Entry -- Builds the INI entry for this team type. *
  40. * TeamTypeClass::Create_One_Of -- Creates a team of this type. *
  41. * TeamTypeClass::Description -- Builds a description of the team. *
  42. * TeamTypeClass::Destroy_All_Of -- Destroy all teams of this type. *
  43. * TeamTypeClass::Detach -- Detach the specified target from this team type. *
  44. * TeamTypeClass::Draw_It -- Display the team type in a list box. *
  45. * TeamTypeClass::Edit -- Edit the team type. *
  46. * TeamTypeClass::Fill_In -- fills in trigger from the given INI entry *
  47. * TeamTypeClass::From_Name -- Converts a name into a team type pointer. *
  48. * TeamTypeClass::Init -- pre-scenario initialization *
  49. * TeamTypeClass::Member_Description -- Builds a member description string *
  50. * TeamTypeClass::Mission_From_Name -- returns mission for given name *
  51. * TeamTypeClass::Name_From_Mission -- returns name for given mission *
  52. * TeamTypeClass::Read_INI -- reads INI data *
  53. * TeamTypeClass::Suggested_New_Team -- Suggests a new team to create. *
  54. * TeamTypeClass::TeamTypeClass -- class constructor *
  55. * TeamTypeClass::Write_INI -- Write out the team types to the INI database. *
  56. * TeamTypeClass::operator delete -- 'delete' operator *
  57. * TeamTypeClass::operator new -- 'new' operator *
  58. * TeamTypeClass::~TeamTypeClass -- class destructor *
  59. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  60. #include "function.h"
  61. TeamMissionClass TeamMissions[TMISSION_COUNT] = {
  62. {TMISSION_ATTACK},
  63. {TMISSION_ATT_WAYPT},
  64. {TMISSION_FORMATION},
  65. {TMISSION_MOVE},
  66. {TMISSION_MOVECELL},
  67. {TMISSION_GUARD},
  68. {TMISSION_LOOP},
  69. {TMISSION_ATTACKTARCOM},
  70. {TMISSION_UNLOAD},
  71. {TMISSION_DEPLOY},
  72. {TMISSION_HOUND_DOG},
  73. {TMISSION_DO},
  74. {TMISSION_SET_GLOBAL},
  75. {TMISSION_LOAD},
  76. {TMISSION_SPY},
  77. {TMISSION_PATROL},
  78. };
  79. int atoh(char * str);
  80. #if defined(CHEAT_KEYS) || defined(SCENARIO_EDITOR)
  81. /***********************************************************************************************
  82. * TeamTypeClass::Draw_It -- Display the team type in a list box. *
  83. * *
  84. * This is a helper routine that is used when this team type is stored into a list box *
  85. * and must be displayed. It will display the team type as a single line of text. *
  86. * *
  87. * INPUT: see below... *
  88. * *
  89. * OUTPUT: none *
  90. * *
  91. * WARNINGS: none *
  92. * *
  93. * HISTORY: *
  94. * 07/30/1996 JLB : Created. *
  95. *=============================================================================================*/
  96. void TeamTypeClass::Draw_It(int , int x, int y, int width, int height, bool selected, TextPrintType flags) const
  97. {
  98. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  99. static int _tabs[] = {35, 60, 80, 100};
  100. if ((flags & 0x0F) == TPF_6PT_GRAD || (flags & 0x0F) == TPF_EFNT) {
  101. if (selected) {
  102. flags = flags | TPF_BRIGHT_COLOR;
  103. LogicPage->Fill_Rect(x, y, x + width - 1, y + height - 1, scheme->Shadow);
  104. } else {
  105. if (!(flags & TPF_USE_GRAD_PAL)) {
  106. flags = flags | TPF_MEDIUM_COLOR;
  107. }
  108. }
  109. Conquer_Clip_Text_Print(Description(), x, y, scheme, TBLACK, flags, width, _tabs);
  110. } else {
  111. Conquer_Clip_Text_Print(Description(), x, y, (selected ? &ColorRemaps[PCOLOR_DIALOG_BLUE] : &ColorRemaps[PCOLOR_GREY]), TBLACK, flags, width, _tabs);
  112. }
  113. }
  114. #endif
  115. /*
  116. ********************************** Globals **********************************
  117. */
  118. char const * TeamTypeClass::TMissions[TMISSION_COUNT] = {
  119. "Attack...",
  120. "Attack Waypoint...",
  121. "Change Formation to...",
  122. "Move to waypoint...",
  123. "Move to Cell...",
  124. "Guard area (1/10th min)...",
  125. "Jump to line #...",
  126. "Attack Tarcom",
  127. "Unload",
  128. "Deploy",
  129. "Follow friendlies",
  130. "Do this...",
  131. "Set global...",
  132. "Invulnerable",
  133. "Load onto Transport",
  134. "Spy on bldg @ waypt...",
  135. "Patrol to waypoint..."
  136. };
  137. /***************************************************************************
  138. * TeamTypeClass::TeamTypeClass -- class constructor *
  139. * *
  140. * INPUT: *
  141. * *
  142. * OUTPUT: *
  143. * *
  144. * WARNINGS: *
  145. * *
  146. * HISTORY: *
  147. * 12/07/1994 BR : Created. *
  148. * 11/22/1995 JLB : Uses initializer constructor method. *
  149. *=========================================================================*/
  150. TeamTypeClass::TeamTypeClass(void) :
  151. AbstractTypeClass(RTTI_TEAMTYPE, TeamTypes.ID(this), TXT_NONE, ""),
  152. IsRoundAbout(false),
  153. IsSuicide(false),
  154. IsAutocreate(false),
  155. IsPrebuilt(true),
  156. IsReinforcable(true),
  157. IsTransient(false),
  158. RecruitPriority(7),
  159. InitNum(0),
  160. MaxAllowed(0),
  161. Fear(0),
  162. House(HOUSE_NONE),
  163. Trigger(0),
  164. Origin(-1),
  165. Number(0),
  166. MissionCount(0),
  167. ClassCount(0)
  168. {
  169. for (int i = 0; i < MAX_TEAM_CLASSCOUNT; i++) {
  170. Members[i].Class = NULL;
  171. Members[i].Quantity = 0;
  172. }
  173. }
  174. /***************************************************************************
  175. * TeamTypeClass::Init -- pre-scenario initialization *
  176. * *
  177. * INPUT: *
  178. * *
  179. * OUTPUT: *
  180. * *
  181. * WARNINGS: *
  182. * *
  183. * HISTORY: *
  184. * 12/07/1994 BR : Created. *
  185. *=========================================================================*/
  186. void TeamTypeClass::Init(void)
  187. {
  188. TeamTypes.Free_All();
  189. }
  190. /***************************************************************************
  191. * TeamTypeClass::As_Pointer -- gets ptr for team type with given name *
  192. * *
  193. * INPUT: *
  194. * name name of teamtype *
  195. * *
  196. * OUTPUT: *
  197. * ptr to TeamType with that name *
  198. * *
  199. * WARNINGS: *
  200. * none. *
  201. * *
  202. * HISTORY: *
  203. * 12/07/1994 BR : Created. *
  204. *=========================================================================*/
  205. TeamTypeClass * TeamTypeClass::As_Pointer(char const * name)
  206. {
  207. if (name) {
  208. for (int index = 0; index < TeamTypes.Count(); index++) {
  209. if (!stricmp(name, TeamTypes.Ptr(index)->IniName)) {
  210. return(TeamTypes.Ptr(index));
  211. }
  212. }
  213. }
  214. return(NULL);
  215. }
  216. /***************************************************************************
  217. * TeamTypeClass::Mission_From_Name -- returns team mission for given name *
  218. * *
  219. * INPUT: *
  220. * name name to compare *
  221. * *
  222. * OUTPUT: *
  223. * mission for that name *
  224. * *
  225. * WARNINGS: *
  226. * none. *
  227. * *
  228. * HISTORY: *
  229. * 12/13/1994 BR : Created. *
  230. *=========================================================================*/
  231. TeamMissionType TeamTypeClass::Mission_From_Name(char const * name)
  232. {
  233. if (name) {
  234. for (TeamMissionType order = TMISSION_FIRST; order < TMISSION_COUNT; order++) {
  235. if (stricmp(TMissions[order], name) == 0) {
  236. return(order);
  237. }
  238. }
  239. }
  240. return(TMISSION_NONE);
  241. }
  242. /***************************************************************************
  243. * TeamTypeClass::Name_From_Mission -- returns name for given mission *
  244. * *
  245. * INPUT: *
  246. * order mission to get name for *
  247. * *
  248. * OUTPUT: *
  249. * name of mission *
  250. * *
  251. * WARNINGS: *
  252. * none. *
  253. * *
  254. * HISTORY: *
  255. * 12/13/1994 BR : Created. *
  256. *=========================================================================*/
  257. char const * TeamTypeClass::Name_From_Mission(TeamMissionType order)
  258. {
  259. assert((unsigned)order < TMISSION_COUNT);
  260. return(TMissions[order]);
  261. }
  262. /***************************************************************************
  263. * TeamTypeClass::operator new -- 'new' operator *
  264. * *
  265. * INPUT: *
  266. * none. *
  267. * *
  268. * OUTPUT: *
  269. * pointer to new TeamType *
  270. * *
  271. * WARNINGS: *
  272. * none. *
  273. * *
  274. * HISTORY: *
  275. * 11/28/1994 BR : Created. *
  276. *=========================================================================*/
  277. void * TeamTypeClass::operator new(size_t )
  278. {
  279. void * ptr = TeamTypes.Allocate();
  280. if (ptr) {
  281. ((TeamTypeClass *)ptr)->IsActive = true;
  282. }
  283. return(ptr);
  284. }
  285. /***************************************************************************
  286. * TeamTypeClass::operator delete -- 'delete' operator *
  287. * *
  288. * INPUT: *
  289. * ptr pointer to delete *
  290. * *
  291. * OUTPUT: *
  292. * none. *
  293. * *
  294. * WARNINGS: *
  295. * none. *
  296. * *
  297. * HISTORY: *
  298. * 11/28/1994 BR : Created. *
  299. *=========================================================================*/
  300. void TeamTypeClass::operator delete(void * ptr)
  301. {
  302. if (ptr) {
  303. ((TeamTypeClass *)ptr)->IsActive = false;
  304. }
  305. TeamTypes.Free((TeamTypeClass *)ptr);
  306. }
  307. /***********************************************************************************************
  308. * TeamTypeClass::Create_One_Of -- Creates a team of this type. *
  309. * *
  310. * Use this routine to create a team object from this team type. *
  311. * *
  312. * INPUT: none *
  313. * *
  314. * OUTPUT: Returns with a pointer to the newly created team object. If one could not be *
  315. * created, then NULL is returned. *
  316. * *
  317. * WARNINGS: none *
  318. * *
  319. * HISTORY: *
  320. * 09/21/1995 JLB : Created. *
  321. *=============================================================================================*/
  322. TeamClass * TeamTypeClass::Create_One_Of(void) const
  323. {
  324. if (ScenarioInit || Number < MaxAllowed) {
  325. // if (ScenarioInit || TeamClass::Number[ID] < MaxAllowed) {
  326. return(new TeamClass(this, HouseClass::As_Pointer(House)));
  327. }
  328. return(NULL);
  329. }
  330. /***********************************************************************************************
  331. * TeamTypeClass::Destroy_All_Of -- Destroy all teams of this type. *
  332. * *
  333. * This routine will destroy all teams of this type. Typical use of this is from a trigger *
  334. * event. *
  335. * *
  336. * INPUT: none *
  337. * *
  338. * OUTPUT: none *
  339. * *
  340. * WARNINGS: none *
  341. * *
  342. * HISTORY: *
  343. * 09/21/1995 JLB : Created. *
  344. *=============================================================================================*/
  345. void TeamTypeClass::Destroy_All_Of(void) const
  346. {
  347. for (int index = 0; index < Teams.Count(); index++) {
  348. TeamClass * team = Teams.Ptr(index);
  349. if (team->Class == this) {
  350. delete team;
  351. index--;
  352. }
  353. }
  354. }
  355. /***********************************************************************************************
  356. * TeamTypeClass::Suggested_New_Team -- Suggests a new team to create. *
  357. * *
  358. * This routine will scan through the team types available and create teams of the *
  359. * type that can best utilize the existing unit mix. *
  360. * *
  361. * INPUT: house -- Pointer to the house that this team is to be created for. *
  362. * *
  363. * atypes -- A bit mask of the aircraft types available for this house. *
  364. * *
  365. * utypes -- A bit mask of the unit types available for this house. *
  366. * *
  367. * itypes -- A bit mask of the infantry types available for this house. *
  368. * *
  369. * vtypes -- A bit mask of the vessel types available for this house. *
  370. * *
  371. * alerted -- Is this house alerted? If true, then the Autocreate teams will be *
  372. * considered in the selection process. *
  373. * *
  374. * OUTPUT: Returns with a pointer to the team type that should be created. If no team should *
  375. * be created, then it returns NULL. *
  376. * *
  377. * WARNINGS: none *
  378. * *
  379. * HISTORY: *
  380. * 07/13/1995 JLB : Created. *
  381. * 07/21/1995 JLB : Will autocreate team even if no members in field. *
  382. *=============================================================================================*/
  383. TeamTypeClass const * TeamTypeClass::Suggested_New_Team(HouseClass * house, long , long , long , long , bool alerted)
  384. //TeamTypeClass const * TeamTypeClass::Suggested_New_Team(HouseClass * house, long atypes, long utypes, long itypes, long vtypes, bool alerted)
  385. {
  386. // TeamTypeClass const * best = NULL;
  387. // int bestvalue = 0;
  388. TeamTypeClass const * choices[20];
  389. int choicecount = 0;
  390. for (int index = 0; index < TeamTypes.Count(); index++) {
  391. TeamTypeClass const * ttype = TeamTypes.Ptr(index);
  392. assert(ttype != NULL);
  393. int maxnum = ttype->MaxAllowed;
  394. if ((alerted && !ttype->IsAutocreate) || (!alerted && ttype->IsAutocreate)) {
  395. maxnum = 0;
  396. }
  397. if (choicecount >= ARRAY_SIZE(choices)) break;
  398. if (ttype != NULL && ttype->House == house->Class->House && ttype->Number < maxnum) {
  399. choices[choicecount++] = ttype;
  400. #ifdef OBSOLETE
  401. /*
  402. ** Determine what kind of units this team requires.
  403. */
  404. long uneeded = 0;
  405. long ineeded = 0;
  406. long vneeded = 0;
  407. long aneeded = 0;
  408. for (int ctype = 0; ctype < ttype->ClassCount; ctype++) {
  409. switch (ttype->Members[ctype].Class->What_Am_I()) {
  410. case RTTI_INFANTRYTYPE:
  411. ineeded |= (1 << ((InfantryTypeClass *)ttype->Members[ctype].Class)->Type);
  412. break;
  413. case RTTI_UNITTYPE:
  414. uneeded |= (1 << ((UnitTypeClass *)ttype->Members[ctype].Class)->Type);
  415. break;
  416. case RTTI_VESSELTYPE:
  417. vneeded |= (1 << ((VesselTypeClass *)ttype->Members[ctype].Class)->Type);
  418. break;
  419. case RTTI_AIRCRAFTTYPE:
  420. aneeded |= (1 << ((AircraftTypeClass *)ttype->Members[ctype].Class)->Type);
  421. break;
  422. }
  423. }
  424. /*
  425. ** If this team can use the types required, then consider it a possible
  426. ** team type to create.
  427. */
  428. int value = 0;
  429. if ((aneeded & atypes) != 0 || (ineeded & itypes) != 0 || (uneeded & utypes) != 0 || (vneeded & vtypes) != 0) {
  430. value = ttype->RecruitPriority;
  431. } else {
  432. value = ttype->RecruitPriority/2;
  433. }
  434. if (best == NULL || bestvalue < value) {
  435. bestvalue = value;
  436. best = ttype;
  437. }
  438. #endif
  439. }
  440. }
  441. if (choicecount > 0) {
  442. return(choices[Random_Pick(0, choicecount-1)]);
  443. }
  444. return(NULL);
  445. // return(best);
  446. }
  447. /***********************************************************************************************
  448. * TeamTypeClass::From_Name -- Converts a name into a team type pointer. *
  449. * *
  450. * This routine is used to convert an ASCII name of a team type into the corresponding *
  451. * team type pointer. *
  452. * *
  453. * INPUT: name -- Pointer to the ASCII name of the team type. *
  454. * *
  455. * OUTPUT: Returns with a pointer to the team type that this ASCII name represents. If there *
  456. * is no match, the NULL is returned. *
  457. * *
  458. * WARNINGS: none *
  459. * *
  460. * HISTORY: *
  461. * 01/26/1996 JLB : Created. *
  462. *=============================================================================================*/
  463. TeamTypeClass * TeamTypeClass::From_Name(char const * name)
  464. {
  465. if (name) {
  466. for (int index = 0; index < TeamTypes.Count(); index++) {
  467. if (stricmp(name, TeamTypes.Ptr(index)->IniName) == 0) {
  468. return(TeamTypes.Ptr(index));
  469. }
  470. }
  471. }
  472. return(0);
  473. }
  474. /***********************************************************************************************
  475. * TeamMission_Needs -- Determines what extra data is needed by team mission. *
  476. * *
  477. * This routine will return the required extra data that the specified team mission will *
  478. * need. *
  479. * *
  480. * INPUT: tmtype -- The team mission type to check. *
  481. * *
  482. * OUTPUT: Returns with the data type needed for this team mission. *
  483. * *
  484. * WARNINGS: none *
  485. * *
  486. * HISTORY: *
  487. * 01/26/1996 JLB : Created. *
  488. *=============================================================================================*/
  489. NeedType TeamMission_Needs(TeamMissionType tmtype)
  490. {
  491. switch (tmtype) {
  492. /*
  493. ** Requires a formation type.
  494. */
  495. case TMISSION_FORMATION:
  496. return(NEED_FORMATION);
  497. /*
  498. ** Team mission requires a target quarry value.
  499. */
  500. case TMISSION_ATTACK:
  501. return(NEED_QUARRY);
  502. /*
  503. ** Team mission requires a data value.
  504. */
  505. case TMISSION_MOVECELL:
  506. return(NEED_HEX_NUMBER);
  507. case TMISSION_SET_GLOBAL:
  508. case TMISSION_GUARD:
  509. case TMISSION_LOOP:
  510. return(NEED_NUMBER);
  511. /*
  512. ** Team mission requires a waypoint.
  513. */
  514. case TMISSION_PATROL:
  515. case TMISSION_MOVE:
  516. case TMISSION_ATT_WAYPT:
  517. case TMISSION_SPY:
  518. return(NEED_WAYPOINT);
  519. /*
  520. ** Team mission requires a general mission type.
  521. */
  522. case TMISSION_DO:
  523. return(NEED_MISSION);
  524. default:
  525. break;
  526. }
  527. return(NEED_NONE);
  528. }
  529. #ifdef SCENARIO_EDITOR
  530. /***********************************************************************************************
  531. * TeamMissionClass::Draw_It -- Draws a team mission list box entry. *
  532. * *
  533. * This routine will display a team mission list box entry. It converts the index number *
  534. * into the appropriate text string and then displays the text at the coordinates *
  535. * specified. *
  536. * *
  537. * INPUT: index -- The index number to use when rendering the team mission. *
  538. * *
  539. * x,y -- The X,Y coordinate to use when drawing the team mission entry. *
  540. * *
  541. * width, height -- The dimensions of the area that the description can be *
  542. * rendered into. *
  543. * *
  544. * selected -- Is this entry currently selected? If so, then it should be rendered *
  545. * differently. *
  546. * *
  547. * flags -- Text print control flags used for when the text is printed. *
  548. * *
  549. * OUTPUT: none *
  550. * *
  551. * WARNINGS: none *
  552. * *
  553. * HISTORY: *
  554. * 01/05/1996 JLB : Created. *
  555. *=============================================================================================*/
  556. void TeamMissionClass::Draw_It(int index, int x, int y, int width, int height, bool selected, TextPrintType flags)
  557. {
  558. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  559. static int _tabs[] = {13,40};
  560. if ((flags & 0x0F) == TPF_6PT_GRAD || (flags & 0x0F) == TPF_EFNT) {
  561. if (selected) {
  562. flags = flags | TPF_BRIGHT_COLOR;
  563. LogicPage->Fill_Rect(x, y, x + width - 1, y + height - 1,
  564. scheme->Shadow);
  565. } else {
  566. if (!(flags & TPF_USE_GRAD_PAL)) {
  567. flags = flags | TPF_MEDIUM_COLOR;
  568. }
  569. }
  570. Conquer_Clip_Text_Print(Description(index), x, y, scheme, TBLACK, flags, width, _tabs);
  571. } else {
  572. Conquer_Clip_Text_Print(Description(index), x, y,
  573. (selected ? &ColorRemaps[PCOLOR_DIALOG_BLUE] : &ColorRemaps[PCOLOR_GREY]), TBLACK, flags, width, _tabs);
  574. }
  575. }
  576. /***********************************************************************************************
  577. * TeamTypeClass::Edit -- Edit the team type. *
  578. * *
  579. * This routine handles the editing dialog box for the team type. *
  580. * *
  581. * INPUT: none *
  582. * *
  583. * OUTPUT: Was the team type edited? A FALSE indicates that the dialog was canceled. *
  584. * *
  585. * WARNINGS: none *
  586. * *
  587. * HISTORY: *
  588. * 01/05/1996 JLB : Created. *
  589. *=============================================================================================*/
  590. bool TeamTypeClass::Edit(void)
  591. {
  592. /*
  593. ** Dialog & button dimensions
  594. */
  595. enum {
  596. D_DIALOG_W = 400,
  597. D_DIALOG_H = 250,
  598. D_DIALOG_X = 0,
  599. D_DIALOG_Y = 0,
  600. D_NAME_X=D_DIALOG_X+35,
  601. D_NAME_Y=D_DIALOG_Y+27,
  602. ED_WIDTH=40,
  603. D_CHECK_X=D_DIALOG_X+35, // Start of check box attribute list.
  604. D_CHECK_Y=D_NAME_Y+25,
  605. CB_SPACING_Y=9, // Vertical spacing between check box lines.
  606. CB_SPACING_X=8, // Horizontal spacing for check box description text.
  607. D_SPACING_X=9, // Horizontal spacing between data entry fields.
  608. D_CANCEL_W = 50,
  609. D_CANCEL_H = 9,
  610. D_CANCEL_X = D_DIALOG_X + D_DIALOG_W - (D_CANCEL_W+35),
  611. D_CANCEL_Y = D_DIALOG_Y + D_DIALOG_H - (D_CANCEL_H+20),
  612. D_OK_W = 50,
  613. D_OK_H = 9,
  614. D_OK_X = D_DIALOG_X + D_DIALOG_W - (D_OK_W+18)*2,
  615. D_OK_Y = D_CANCEL_Y
  616. };
  617. /*
  618. ** Button enumerations:
  619. */
  620. enum {
  621. BUTTON_NAME=100,
  622. BUTTON_RECRUIT,
  623. BUTTON_MAXNUM,
  624. BUTTON_INITNUM,
  625. BUTTON_HOUSE,
  626. BUTTON_ROUNDABOUT,
  627. BUTTON_LEARNING,
  628. BUTTON_SUICIDE,
  629. BUTTON_AUTO,
  630. BUTTON_PREBUILT,
  631. BUTTON_REINFORCE,
  632. BUTTON_MISSION1,
  633. BUTTON_MISSION2,
  634. BUTTON_ADD,
  635. BUTTON_INSERT,
  636. BUTTON_DELETE,
  637. BUTTON_REPLACE,
  638. BUTTON_ARG,
  639. BUTTON_FORMATION,
  640. BUTTON_MEMBERS,
  641. BUTTON_MISSION,
  642. BUTTON_TRIGGER,
  643. BUTTON_ORIGIN,
  644. BUTTON_OK,
  645. BUTTON_CANCEL,
  646. BUTTON_QUARRY,
  647. };
  648. /*
  649. ** Dialog variables:
  650. */
  651. ControlClass * commands = 0;
  652. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  653. /*
  654. ** Team name edit field.
  655. */
  656. char name_buf[10];
  657. EditClass name_edt(BUTTON_NAME, name_buf, sizeof(name_buf),
  658. TPF_EFNT | TPF_NOSHADOW,
  659. D_NAME_X, D_NAME_Y, ED_WIDTH, 9, EditClass::ALPHANUMERIC);
  660. strcpy(name_buf, IniName);
  661. commands = &name_edt;
  662. /*
  663. ** House ownership of this team.
  664. */
  665. char housetext[25] = "";
  666. DropListClass housebtn(BUTTON_HOUSE, housetext, sizeof(housetext),
  667. TPF_EFNT | TPF_NOSHADOW,
  668. name_edt.X+name_edt.Width+D_SPACING_X, name_edt.Y, 55, 8*5,
  669. MFCD::Retrieve("EBTN-UP.SHP"),
  670. MFCD::Retrieve("EBTN-DN.SHP"));
  671. for (HousesType house = HOUSE_FIRST; house < HOUSE_COUNT; house++) {
  672. housebtn.Add_Item(HouseTypeClass::As_Reference(house).IniName);
  673. }
  674. if (House == HOUSE_NONE) House = HOUSE_GOOD;
  675. housebtn.Set_Selected_Index(House);
  676. housebtn.Add(*commands);
  677. /*
  678. ** Recruit priority for this team.
  679. */
  680. char recr_buf[4];
  681. EditClass recr_edt(BUTTON_RECRUIT, recr_buf, sizeof(recr_buf),
  682. TPF_EFNT | TPF_NOSHADOW,
  683. housebtn.X+housebtn.Width+5+D_SPACING_X, housebtn.Y, ED_WIDTH, 9, EditClass::NUMERIC);
  684. sprintf(recr_buf, "%d", RecruitPriority);
  685. recr_edt.Add(*commands);
  686. /*
  687. ** Maximum allowed for this team type.
  688. */
  689. char maxnum_buf[4];
  690. EditClass maxnum_edt(BUTTON_MAXNUM, maxnum_buf, sizeof(maxnum_buf),
  691. TPF_EFNT | TPF_NOSHADOW,
  692. recr_edt.X+recr_edt.Width+D_SPACING_X, recr_edt.Y, ED_WIDTH, 9, EditClass::NUMERIC);
  693. sprintf(maxnum_buf, "%d", MaxAllowed);
  694. maxnum_edt.Add(*commands);
  695. /*
  696. ** Initial number for this team type.
  697. */
  698. char initnum_buf[4];
  699. EditClass initnum_edt(BUTTON_INITNUM, initnum_buf, sizeof(initnum_buf),
  700. TPF_EFNT | TPF_NOSHADOW,
  701. maxnum_edt.X+maxnum_edt.Width+D_SPACING_X, maxnum_edt.Y, ED_WIDTH, 9, EditClass::NUMERIC);
  702. sprintf(initnum_buf, "%d", InitNum);
  703. initnum_edt.Add(*commands);
  704. /*
  705. ** Waypoint preference to create/reinforce this team.
  706. */
  707. char origin[4];
  708. EditClass originbtn(BUTTON_ORIGIN, origin, sizeof(origin),
  709. TPF_EFNT | TPF_NOSHADOW,
  710. initnum_edt.X+initnum_edt.Width+D_SPACING_X, initnum_edt.Y, 20, 9, EditClass::ALPHA);
  711. *originbtn.Get_Text() = '\0';
  712. if (Origin != -1) {
  713. if (Origin < 26) {
  714. sprintf(originbtn.Get_Text(), "%c", Origin + 'A');
  715. } else {
  716. sprintf(originbtn.Get_Text(), "%c%c", (Origin/26) + 'A'-1, Origin % 26 + 'A');
  717. }
  718. }
  719. originbtn.Add(*commands);
  720. /*
  721. ** Members of this team control button.
  722. */
  723. TextButtonClass membersbtn(BUTTON_MEMBERS, "Members", TPF_EBUTTON, name_edt.X, name_edt.Y+12, 50);
  724. membersbtn.Add(*commands);
  725. /*
  726. ** Trigger to assign to each member of this team (when object joins team).
  727. */
  728. char trigtext[25] = "";
  729. DropListClass triggerbtn(BUTTON_TRIGGER, trigtext, sizeof(trigtext),
  730. TPF_EFNT | TPF_NOSHADOW,
  731. D_DIALOG_X+D_DIALOG_W-95, membersbtn.Y, 60, 8*5,
  732. MFCD::Retrieve("EBTN-UP.SHP"),
  733. MFCD::Retrieve("EBTN-DN.SHP"));
  734. triggerbtn.Add_Item("<NONE>");
  735. for (int index = 0; index < TriggerTypes.Count(); index++) {
  736. triggerbtn.Add_Item(TriggerTypes.Ptr(index)->IniName);
  737. }
  738. if (Trigger.Is_Valid()) {
  739. triggerbtn.Set_Selected_Index(Trigger->Name());
  740. } else {
  741. triggerbtn.Set_Selected_Index(0);
  742. }
  743. triggerbtn.Add(*commands);
  744. /*
  745. ** Roundabout travel logic attribute for this team.
  746. */
  747. CheckBoxClass roundbtn(BUTTON_ROUNDABOUT, D_CHECK_X, D_CHECK_Y);
  748. if (IsRoundAbout) {
  749. roundbtn.Turn_On();
  750. } else {
  751. roundbtn.Turn_Off();
  752. }
  753. roundbtn.Add(*commands);
  754. /*
  755. ** Suicide travel to target attribute.
  756. */
  757. CheckBoxClass suicidebtn(BUTTON_SUICIDE, D_CHECK_X, roundbtn.Y+CB_SPACING_Y);
  758. if (IsSuicide) {
  759. suicidebtn.Turn_On();
  760. } else {
  761. suicidebtn.Turn_Off();
  762. }
  763. suicidebtn.Add(*commands);
  764. /*
  765. ** Autocreate attribute for this team.
  766. */
  767. CheckBoxClass autocreatebtn(BUTTON_AUTO, D_CHECK_X, suicidebtn.Y+CB_SPACING_Y);
  768. if (IsAutocreate) {
  769. autocreatebtn.Turn_On();
  770. } else {
  771. autocreatebtn.Turn_Off();
  772. }
  773. autocreatebtn.Add(*commands);
  774. /*
  775. ** Prebuild team members attribute for this team.
  776. */
  777. CheckBoxClass prebuildbtn(BUTTON_PREBUILT, D_CHECK_X, autocreatebtn.Y+CB_SPACING_Y);
  778. if (IsPrebuilt) {
  779. prebuildbtn.Turn_On();
  780. } else {
  781. prebuildbtn.Turn_Off();
  782. }
  783. prebuildbtn.Add(*commands);
  784. /*
  785. ** Reinforce this team in progress attribute.
  786. */
  787. CheckBoxClass reinforcebtn(BUTTON_REINFORCE, D_CHECK_X, prebuildbtn.Y+CB_SPACING_Y);
  788. if (IsReinforcable) {
  789. reinforcebtn.Turn_On();
  790. } else {
  791. reinforcebtn.Turn_Off();
  792. }
  793. reinforcebtn.Add(*commands);
  794. /*
  795. ** Create drop box of possible team missions. This is used when building/editing the
  796. ** team mission list.
  797. */
  798. char droptext[45];
  799. DropListClass missionlist1(BUTTON_MISSION1, droptext, sizeof(droptext),
  800. TPF_EFNT | TPF_NOSHADOW,
  801. reinforcebtn.X, reinforcebtn.Y+15, 170, 8*8,
  802. MFCD::Retrieve("EBTN-UP.SHP"),
  803. MFCD::Retrieve("EBTN-DN.SHP"));
  804. for (TeamMissionType tm = TMISSION_FIRST; tm < TMISSION_COUNT; tm++) {
  805. missionlist1.Add_Item(TeamTypeClass::Name_From_Mission(tm));
  806. }
  807. missionlist1.Set_Selected_Index(0);
  808. missionlist1.Add_Tail(*commands);
  809. /*
  810. ** Optional mission argument entry field.
  811. */
  812. char arg_buf[6] = {0};
  813. EditClass arg_edt(BUTTON_ARG, arg_buf, sizeof(arg_buf),
  814. TPF_EFNT | TPF_NOSHADOW,
  815. missionlist1.X + missionlist1.Width + 15, missionlist1.Y, 60, -1, EditClass::ALPHANUMERIC);
  816. // arg_edt.Add(*commands);
  817. char qtext[55];
  818. DropListClass qlist(BUTTON_QUARRY, qtext, sizeof(qtext),
  819. TPF_EFNT | TPF_NOSHADOW,
  820. missionlist1.X + missionlist1.Width + 15, missionlist1.Y, 100, 5*8,
  821. MFCD::Retrieve("EBTN-UP.SHP"),
  822. MFCD::Retrieve("EBTN-DN.SHP"));
  823. for (QuarryType q = QUARRY_FIRST; q < QUARRY_COUNT; q++) {
  824. qlist.Add_Item(QuarryName[q]);
  825. }
  826. qlist.Set_Selected_Index(0);
  827. qlist.Add_Tail(*commands);
  828. char ftext[55];
  829. DropListClass flist(BUTTON_FORMATION, ftext, sizeof(ftext),
  830. TPF_EFNT | TPF_NOSHADOW,
  831. missionlist1.X + missionlist1.Width + 15, missionlist1.Y, 100, 5*8,
  832. MFCD::Retrieve("EBTN-UP.SHP"),
  833. MFCD::Retrieve("EBTN-DN.SHP"));
  834. for (FormationType f = FORMATION_FIRST; f < FORMATION_COUNT; f++) {
  835. flist.Add_Item(FormationName[f]);
  836. }
  837. flist.Set_Selected_Index(0);
  838. flist.Add_Tail(*commands);
  839. char mtext[55];
  840. DropListClass mlist(BUTTON_MISSION, mtext, sizeof(mtext),
  841. TPF_EFNT | TPF_NOSHADOW,
  842. missionlist1.X + missionlist1.Width + 15, missionlist1.Y, 100, 5*8,
  843. MFCD::Retrieve("EBTN-UP.SHP"),
  844. MFCD::Retrieve("EBTN-DN.SHP"));
  845. for (MissionType m = MISSION_FIRST; m < MISSION_COUNT; m++) {
  846. mlist.Add_Item(MissionClass::Mission_Name(m));
  847. }
  848. mlist.Set_Selected_Index(0);
  849. mlist.Add_Tail(*commands);
  850. TListClass<TeamMissionClass *> missionlist2(BUTTON_MISSION2, missionlist1.X+60, missionlist1.Y+22, 240, 8*7,
  851. TPF_EFNT | TPF_NOSHADOW,
  852. MFCD::Retrieve("EBTN-UP.SHP"),
  853. MFCD::Retrieve("EBTN-DN.SHP"));
  854. for (index = 0; index < MissionCount; index++) {
  855. missionlist2.Add_Item(new TeamMissionClass(MissionList[index]));
  856. // missionlist2.Add_Item(&TeamMissions[MissionList[index].Mission]);
  857. }
  858. static int tabs[] = {13, 40}; // list box tab stops
  859. missionlist2.Set_Tabs(tabs);
  860. missionlist2.Add_Tail(*commands);
  861. /*
  862. ** Mission editing command buttons.
  863. */
  864. TextButtonClass addbtn(BUTTON_ADD, "Append", TPF_EBUTTON, D_NAME_X, missionlist1.Y+missionlist1.Height+1, 50);
  865. addbtn.Add(*commands);
  866. TextButtonClass insertbtn(BUTTON_INSERT, "Insert", TPF_EBUTTON, addbtn.X, addbtn.Y+10, 50);
  867. insertbtn.Add(*commands);
  868. TextButtonClass delbtn(BUTTON_DELETE, "Delete", TPF_EBUTTON, insertbtn.X, insertbtn.Y+10, 50);
  869. delbtn.Add(*commands);
  870. TextButtonClass repbtn(BUTTON_REPLACE, "Replace", TPF_EBUTTON, delbtn.X, delbtn.Y+10, 50);
  871. repbtn.Add(*commands);
  872. TextButtonClass okbtn(BUTTON_OK, TXT_OK, TPF_EBUTTON, D_OK_X, D_OK_Y, D_OK_W, D_OK_H);
  873. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_EBUTTON, D_CANCEL_X, D_CANCEL_Y, D_CANCEL_W, D_CANCEL_H);
  874. /*
  875. ** Initialize
  876. */
  877. Set_Logic_Page(SeenBuff);
  878. /*
  879. ** Create the list
  880. */
  881. okbtn.Add(*commands);
  882. cancelbtn.Add_Tail(*commands);
  883. /*
  884. ** Main Processing Loop
  885. */
  886. int lastindex = -1;
  887. int lastcount = -1;
  888. int lastbutton = -1;
  889. bool cancel = false;
  890. bool display = true;
  891. bool process = true;
  892. while (process) {
  893. /*
  894. ** Invoke game callback
  895. */
  896. Call_Back();
  897. /*
  898. ** Refresh display if needed
  899. */
  900. if (display) {
  901. /*
  902. ** Add the optional data entry field as necessary.
  903. */
  904. arg_edt.Remove();
  905. qlist.Remove();
  906. flist.Remove();
  907. mlist.Remove();
  908. switch (TeamMission_Needs(TeamMissionType(missionlist1.Current_Index()))) {
  909. default:
  910. break;
  911. case NEED_MISSION:
  912. mlist.Add(*commands);
  913. break;
  914. case NEED_FORMATION:
  915. flist.Add(*commands);
  916. break;
  917. case NEED_WAYPOINT:
  918. case NEED_NUMBER:
  919. case NEED_HEX_NUMBER:
  920. arg_edt.Add(*commands);
  921. break;
  922. case NEED_QUARRY:
  923. qlist.Add(*commands);
  924. break;
  925. }
  926. /*
  927. ** Display the dialog box
  928. */
  929. Hide_Mouse();
  930. Dialog_Box(D_DIALOG_X, D_DIALOG_Y, D_DIALOG_W, D_DIALOG_H);
  931. Draw_Caption(TXT_TEAM_EDIT, D_DIALOG_X, D_DIALOG_Y, D_DIALOG_W);
  932. /*
  933. ** Draw the captions
  934. */
  935. Fancy_Text_Print("Name:", name_edt.X, name_edt.Y-7, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  936. Fancy_Text_Print("House:", housebtn.X, housebtn.Y-7, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  937. Fancy_Text_Print("Pri:", recr_edt.X, recr_edt.Y-7, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  938. Fancy_Text_Print("Max:", maxnum_edt.X, maxnum_edt.Y-7, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  939. Fancy_Text_Print("Num:", initnum_edt.X, initnum_edt.Y-7, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  940. Fancy_Text_Print("Loc:", originbtn.X, originbtn.Y-7, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  941. Fancy_Text_Print("# Team Mission", missionlist2.X, missionlist2.Y-7, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  942. Fancy_Text_Print("Trigger:", triggerbtn.X-4, triggerbtn.Y+1, scheme, TBLACK, TPF_RIGHT | TPF_EFNT | TPF_NOSHADOW);
  943. Fancy_Text_Print(Member_Description(), membersbtn.X + membersbtn.Width + 3, membersbtn.Y+1, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  944. Fancy_Text_Print("Use safest, possibly longer, route to target?", roundbtn.X+CB_SPACING_X, roundbtn.Y, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  945. Fancy_Text_Print("Charge toward target ignoring distractions?", suicidebtn.X+CB_SPACING_X, suicidebtn.Y, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  946. Fancy_Text_Print("Only 'Autocreate A.I.' uses this team type?", autocreatebtn.X+CB_SPACING_X, autocreatebtn.Y, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  947. Fancy_Text_Print("Prebuild team members before team is created?", prebuildbtn.X+CB_SPACING_X, prebuildbtn.Y, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  948. Fancy_Text_Print("Automatically reinforce team whenever possible?", reinforcebtn.X+CB_SPACING_X, reinforcebtn.Y, scheme, TBLACK, TPF_EFNT | TPF_NOSHADOW);
  949. /*
  950. ** Redraw the buttons
  951. */
  952. commands->Draw_All();
  953. Show_Mouse();
  954. display = false;
  955. }
  956. /*
  957. ** Get user input
  958. */
  959. KeyNumType input = commands->Input();
  960. /*
  961. ** Process input
  962. */
  963. switch (input) {
  964. /*
  965. ** Select a Mission on the right-hand mission list; update the Argument
  966. ** field to reflect the current value. This only serves as an aide to editing
  967. ** the team mission list.
  968. */
  969. case BUTTON_MISSION2 | KN_BUTTON:
  970. if (missionlist2.Count() && lastcount == missionlist2.Count() && lastbutton == BUTTON_MISSION2 && lastindex == missionlist2.Current_Index()) {
  971. missionlist1.Set_Selected_Index(missionlist2.Current_Item()->Mission);
  972. switch (TeamMission_Needs(missionlist2.Current_Item()->Mission)) {
  973. case NEED_MISSION:
  974. mlist.Set_Selected_Index(missionlist2.Current_Item()->Data.Mission);
  975. break;
  976. case NEED_FORMATION:
  977. flist.Set_Selected_Index(missionlist2.Current_Item()->Data.Formation);
  978. break;
  979. case NEED_NUMBER:
  980. sprintf(arg_edt.Get_Text(), "%d", missionlist2.Current_Item()->Data.Value);
  981. break;
  982. case NEED_HEX_NUMBER:
  983. sprintf(arg_edt.Get_Text(), "%x", missionlist2.Current_Item()->Data.Value);
  984. break;
  985. case NEED_QUARRY:
  986. strcpy(qlist.Get_Text(), QuarryName[missionlist2.Current_Item()->Data.Quarry]);
  987. break;
  988. case NEED_WAYPOINT:
  989. if (missionlist2.Current_Item()->Data.Value < 26) {
  990. sprintf(arg_edt.Get_Text(), "%c", missionlist2.Current_Item()->Data.Value + 'A');
  991. } else {
  992. sprintf(arg_edt.Get_Text(), "%c%c", (missionlist2.Current_Item()->Data.Value)/26 + 'A'-1, (missionlist2.Current_Item()->Data.Value % 26) + 'A');
  993. }
  994. break;
  995. }
  996. }
  997. lastindex = missionlist2.Current_Index();
  998. lastcount = missionlist2.Count();
  999. display = true;
  1000. break;
  1001. /*
  1002. ** Add current mission data to current position of team mission list. Any
  1003. ** subsequent missions get moved downward.
  1004. */
  1005. case BUTTON_INSERT | KN_BUTTON:
  1006. if (missionlist2.Count() < MAX_TEAM_MISSIONS) {
  1007. TeamMissionClass * tm = new TeamMissionClass;
  1008. tm->Mission = TeamMissionType(missionlist1.Current_Index());
  1009. tm->Data.Value = 0;
  1010. switch (TeamMission_Needs(tm->Mission)) {
  1011. case NEED_MISSION:
  1012. tm->Data.Mission = MissionType(mlist.Current_Index());
  1013. break;
  1014. case NEED_FORMATION:
  1015. tm->Data.Formation = FormationType(flist.Current_Index());
  1016. break;
  1017. case NEED_QUARRY:
  1018. tm->Data.Quarry = QuarryType(qlist.Current_Index());
  1019. break;
  1020. case NEED_NUMBER:
  1021. tm->Data.Value = atoi(arg_edt.Get_Text());
  1022. break;
  1023. case NEED_HEX_NUMBER:
  1024. tm->Data.Value = atoh(arg_edt.Get_Text());
  1025. break;
  1026. case NEED_WAYPOINT:
  1027. tm->Data.Value = toupper(*arg_edt.Get_Text()) - 'A';
  1028. if ( *((arg_edt.Get_Text())+1)) {
  1029. tm->Data.Value = (tm->Data.Value+1)*26;
  1030. tm->Data.Value += toupper(*((arg_edt.Get_Text())+1)) - 'A';;
  1031. }
  1032. if ((unsigned)tm->Data.Value >= WAYPT_HOME) {
  1033. tm->Data.Value = 0;
  1034. }
  1035. break;
  1036. default:
  1037. tm->Data.Value = 0;
  1038. break;
  1039. }
  1040. missionlist2.Insert_Item(tm);
  1041. }
  1042. display = true;
  1043. break;
  1044. /*
  1045. ** Add mission data to the end of the mission list.
  1046. */
  1047. case BUTTON_ADD | KN_BUTTON:
  1048. if (missionlist2.Count() < MAX_TEAM_MISSIONS) {
  1049. TeamMissionClass * tm = new TeamMissionClass;
  1050. tm->Mission = TeamMissionType(missionlist1.Current_Index());
  1051. tm->Data.Value = 0;
  1052. switch (TeamMission_Needs(tm->Mission)) {
  1053. case NEED_MISSION:
  1054. tm->Data.Mission = MissionType(mlist.Current_Index());
  1055. break;
  1056. case NEED_FORMATION:
  1057. tm->Data.Formation = FormationType(flist.Current_Index());
  1058. break;
  1059. case NEED_QUARRY:
  1060. tm->Data.Quarry = QuarryType(qlist.Current_Index());
  1061. break;
  1062. case NEED_NUMBER:
  1063. tm->Data.Value = atoi(arg_edt.Get_Text());
  1064. break;
  1065. case NEED_HEX_NUMBER:
  1066. tm->Data.Value = atoh(arg_edt.Get_Text());
  1067. break;
  1068. case NEED_WAYPOINT:
  1069. tm->Data.Value = toupper(*arg_edt.Get_Text()) - 'A';;
  1070. if ( *((arg_edt.Get_Text())+1)) {
  1071. tm->Data.Value = (tm->Data.Value+1)*26;
  1072. tm->Data.Value += toupper(*((arg_edt.Get_Text())+1)) - 'A';;
  1073. }
  1074. if ((unsigned)tm->Data.Value >= WAYPT_HOME) {
  1075. tm->Data.Value = 0;
  1076. }
  1077. break;
  1078. default:
  1079. tm->Data.Value = 0;
  1080. break;
  1081. }
  1082. missionlist2.Add_Item(tm);
  1083. display = true;
  1084. }
  1085. break;
  1086. /*
  1087. ** Replace the currently selected mission with the work mission data.
  1088. */
  1089. case BUTTON_REPLACE | KN_BUTTON:
  1090. if (missionlist2.Count()) {
  1091. TeamMissionClass * tm = missionlist2.Current_Item();
  1092. tm->Mission = TeamMissionType(missionlist1.Current_Index());
  1093. tm->Data.Value = 0;
  1094. switch (TeamMission_Needs(tm->Mission)) {
  1095. case NEED_MISSION:
  1096. tm->Data.Mission = MissionType(mlist.Current_Index());
  1097. break;
  1098. case NEED_FORMATION:
  1099. tm->Data.Formation = FormationType(flist.Current_Index());
  1100. break;
  1101. case NEED_QUARRY:
  1102. tm->Data.Quarry = QuarryType(qlist.Current_Index());
  1103. break;
  1104. case NEED_NUMBER:
  1105. tm->Data.Value = atoi(arg_edt.Get_Text());
  1106. break;
  1107. case NEED_HEX_NUMBER:
  1108. tm->Data.Value = atoh(arg_edt.Get_Text());
  1109. break;
  1110. case NEED_WAYPOINT:
  1111. tm->Data.Value = toupper(*arg_edt.Get_Text()) - 'A';
  1112. if ( *((arg_edt.Get_Text())+1)) {
  1113. tm->Data.Value = (tm->Data.Value+1)*26;
  1114. tm->Data.Value += toupper(*((arg_edt.Get_Text())+1)) - 'A';
  1115. }
  1116. if ((unsigned)tm->Data.Value >= WAYPT_HOME) {
  1117. tm->Data.Value = 0;
  1118. }
  1119. break;
  1120. default:
  1121. tm->Data.Value = 0;
  1122. break;
  1123. }
  1124. missionlist2[missionlist2.Current_Index()] = tm;
  1125. }
  1126. display = true;
  1127. break;
  1128. /*
  1129. ** Delete the currently selected mission.
  1130. */
  1131. case BUTTON_DELETE | KN_BUTTON:
  1132. if (missionlist2.Count()) {
  1133. TeamMissionClass * tm = missionlist2.Current_Item();
  1134. missionlist2.Remove_Index(missionlist2.Current_Index());
  1135. delete tm;
  1136. }
  1137. display = true;
  1138. break;
  1139. /*
  1140. ** Invoke the members dialog
  1141. */
  1142. case BUTTON_MEMBERS | KN_BUTTON:
  1143. /*
  1144. ** Take editor focus away
  1145. */
  1146. membersbtn.Turn_Off();
  1147. /*
  1148. ** Invoke the dialog
  1149. */
  1150. Map.Team_Members(HousesType(housebtn.Current_Index()));
  1151. /*
  1152. ** Redraw
  1153. */
  1154. display = true;
  1155. break;
  1156. /*
  1157. ** When the OK button is selected, lift the values from the dialog box
  1158. ** and place them into the team type object.
  1159. */
  1160. case BUTTON_OK | KN_BUTTON:
  1161. strtrim(name_edt.Get_Text());
  1162. if (strlen(name_edt.Get_Text()) != 0) {
  1163. strcpy(IniName, name_edt.Get_Text());
  1164. } else {
  1165. strcpy(IniName, "----");
  1166. }
  1167. IsRoundAbout = roundbtn.IsOn;
  1168. IsSuicide = suicidebtn.IsOn;
  1169. IsAutocreate = autocreatebtn.IsOn;
  1170. IsPrebuilt = prebuildbtn.IsOn;
  1171. IsReinforcable = reinforcebtn.IsOn;
  1172. RecruitPriority = atoi(recr_edt.Get_Text());
  1173. InitNum = atoi(initnum_edt.Get_Text());
  1174. MaxAllowed = atoi(maxnum_edt.Get_Text());
  1175. House = HousesType(housebtn.Current_Index());
  1176. Trigger = NULL;
  1177. if (triggerbtn.Current_Index() > 0) {
  1178. Trigger = TriggerTypes.Ptr(triggerbtn.Current_Index()-1);
  1179. }
  1180. MissionCount = missionlist2.Count();
  1181. for (index = 0; index < MissionCount; index++) {
  1182. MissionList[index].Data.Value = 0; // Clears extra bits.
  1183. MissionList[index] = *missionlist2[index];
  1184. }
  1185. #ifdef TOFIX
  1186. // the mission class objects pointed to in the list should be deleted?
  1187. #endif
  1188. if (strlen(originbtn.Get_Text())) {
  1189. if (strlen(originbtn.Get_Text()) == 1) {
  1190. Origin = toupper(*originbtn.Get_Text()) - 'A';
  1191. } else {
  1192. Origin = (toupper(*originbtn.Get_Text())+1 - 'A' ) * 26;
  1193. Origin += toupper(*(originbtn.Get_Text()+1)) - 'A';
  1194. }
  1195. } else {
  1196. Origin = -1;
  1197. }
  1198. cancel = false;
  1199. process = false;
  1200. break;
  1201. /*
  1202. ** Cancel: return
  1203. */
  1204. case BUTTON_CANCEL | KN_BUTTON:
  1205. cancel = true;
  1206. process = false;
  1207. break;
  1208. /*
  1209. ** Unrecognized events are ignored. If any button related event is
  1210. ** detected, then collapse any drop down list boxes. This keeps the
  1211. ** dialog box clean.
  1212. */
  1213. default:
  1214. if (input & KN_BUTTON) {
  1215. housebtn.Collapse();
  1216. missionlist1.Collapse();
  1217. triggerbtn.Collapse();
  1218. display = true;
  1219. }
  1220. break;
  1221. }
  1222. /*
  1223. ** Record the last dialog control touched so that a double click
  1224. ** can be detected.
  1225. */
  1226. if (input & KN_BUTTON) {
  1227. lastbutton = (input & ~KN_BUTTON);
  1228. }
  1229. }
  1230. return(!cancel);
  1231. }
  1232. int atoh(char * str)
  1233. {
  1234. int retval = 0;
  1235. while (*str) {
  1236. retval *= 16;
  1237. if (*str >= '0' && *str <= '9') {
  1238. retval += *str-'0';
  1239. } else {
  1240. if (*str >= 'a' && *str <= 'f') {
  1241. retval += 10 + (*str - 'a');
  1242. } else {
  1243. if (*str >= 'A' && *str <= 'F') {
  1244. retval += 10 + (*str - 'A');
  1245. }
  1246. }
  1247. }
  1248. str++;
  1249. }
  1250. return(retval);
  1251. }
  1252. #endif
  1253. #if defined(CHEAT_KEYS) || defined(SCENARIO_EDITOR)
  1254. /***********************************************************************************************
  1255. * TeamTypeClass::Member_Description -- Builds a member description string. *
  1256. * *
  1257. * This routine will build a team member description string. The string will be composed *
  1258. * of the team member type and quantity. As many team member types will be listed that *
  1259. * can fit within a reasonable size. *
  1260. * *
  1261. * INPUT: none *
  1262. * *
  1263. * OUTPUT: Returns with a pointer to the text string that contains a description of the team *
  1264. * type members. *
  1265. * *
  1266. * WARNINGS: The return string may be truncated if necessary to fit within reasonable size *
  1267. * limits. *
  1268. * *
  1269. * HISTORY: *
  1270. * 01/05/1996 JLB : Created. *
  1271. *=============================================================================================*/
  1272. char const * TeamTypeClass::Member_Description(void) const
  1273. {
  1274. static char buffer[128];
  1275. buffer[0] = '\0';
  1276. /*
  1277. ** Fill in class & count for all classes
  1278. */
  1279. for (int index = 0; index < ClassCount; index++) {
  1280. char txt[10];
  1281. strcat(buffer, Members[index].Class->IniName);
  1282. strcat(buffer, ":");
  1283. sprintf(txt, "%d", Members[index].Quantity);
  1284. strcat(buffer, txt);
  1285. if (index < ClassCount-1) {
  1286. strcat(buffer, ",");
  1287. }
  1288. }
  1289. if (strlen(buffer) > 25) {
  1290. strcpy(&buffer[25-3], "...");
  1291. }
  1292. return(buffer);
  1293. }
  1294. /***********************************************************************************************
  1295. * TeamTypeClass::Description -- Builds a description of the team. *
  1296. * *
  1297. * This routine will build a brief description of the team type. This description is used *
  1298. * in the team type list. *
  1299. * *
  1300. * INPUT: none *
  1301. * *
  1302. * OUTPUT: Returns with the composed text string that represents the team type. *
  1303. * *
  1304. * WARNINGS: none *
  1305. * *
  1306. * HISTORY: *
  1307. * 01/05/1996 JLB : Created. *
  1308. *=============================================================================================*/
  1309. char const * TeamTypeClass::Description(void) const
  1310. {
  1311. static char _buffer[128];
  1312. char extra = ' ';
  1313. char loc[3];
  1314. loc[0] = loc[1] = loc[2] = 0;
  1315. if (IsAutocreate) extra = '*';
  1316. if (Origin > -1) {
  1317. // if (Origin != -1) {
  1318. if (Origin < 26) {
  1319. loc[0] = 'A' + Origin;
  1320. } else {
  1321. loc[0] = Origin / 26 + 'A'-1;
  1322. loc[1] = Origin % 26 + 'A';
  1323. }
  1324. }
  1325. sprintf(_buffer, "%s\t%s\t%c%s\t%d\t%s", IniName, HouseTypeClass::As_Reference(House).Suffix, extra, loc, MissionCount, Member_Description());
  1326. return(_buffer);
  1327. }
  1328. /***********************************************************************************************
  1329. * TeamMissionClass::Description -- Compose a text description of team mission. *
  1330. * *
  1331. * This routine will create a text representation of a team mission. This description will *
  1332. * be used in the list of team missions for display purposes. *
  1333. * *
  1334. * INPUT: index -- The index to assign to this team. The index is used since some team *
  1335. * missions refer to the another team mission by index number. *
  1336. * *
  1337. * OUTPUT: Returns with a pointer to the team mission text. *
  1338. * *
  1339. * WARNINGS: none *
  1340. * *
  1341. * HISTORY: *
  1342. * 01/05/1996 JLB : Created. *
  1343. *=============================================================================================*/
  1344. char const * TeamMissionClass::Description(int index) const
  1345. {
  1346. static char buffer[64];
  1347. sprintf(buffer, "%d\t%s", index, TeamTypeClass::Name_From_Mission(Mission));
  1348. switch (TeamMission_Needs(Mission)) {
  1349. case NEED_MISSION:
  1350. strcat(buffer, MissionClass::Mission_Name(Data.Mission));
  1351. break;
  1352. case NEED_FORMATION:
  1353. strcat(buffer, FormationName[Data.Quarry]);
  1354. break;
  1355. case NEED_NUMBER:
  1356. sprintf(&buffer[strlen(buffer)], "%d", Data.Value);
  1357. break;
  1358. case NEED_HEX_NUMBER:
  1359. sprintf(&buffer[strlen(buffer)], "%x", Data.Value);
  1360. break;
  1361. case NEED_QUARRY:
  1362. strcat(buffer, QuarryName[Data.Quarry]);
  1363. break;
  1364. case NEED_WAYPOINT:
  1365. if (Data.Value < 26) {
  1366. sprintf(&buffer[strlen(buffer)], "%c", Data.Value + 'A');
  1367. } else {
  1368. sprintf(&buffer[strlen(buffer)], "%c%c", (Data.Value/26) + 'A'-1, (Data.Value % 26) + 'A');
  1369. }
  1370. break;
  1371. }
  1372. return(buffer);
  1373. }
  1374. #endif
  1375. /***********************************************************************************************
  1376. * TeamTypeClass::Detach -- Detach the specified target from this team type. *
  1377. * *
  1378. * This routine is called when some object is about to be removed from the game system and *
  1379. * all references to it must be severed. This will check to see if the specified object *
  1380. * is a trigger that this team refers to. If so, then the reference will be cleared. *
  1381. * *
  1382. * INPUT: target -- The target object to remove references to. *
  1383. * *
  1384. * OUTPUT: none *
  1385. * *
  1386. * WARNINGS: none *
  1387. * *
  1388. * HISTORY: *
  1389. * 07/30/1996 JLB : Created. *
  1390. *=============================================================================================*/
  1391. void TeamTypeClass::Detach(TARGET target, bool)
  1392. {
  1393. if (Is_Target_TriggerType(target) && Trigger.Is_Valid() && Trigger == As_TriggerType(target)) {
  1394. Trigger = NULL;
  1395. }
  1396. }
  1397. /***************************************************************************
  1398. * TeamTypeClass::Read_INI -- reads INI data *
  1399. * *
  1400. * INI entry format: *
  1401. * TeamName = Housename,Roundabout,Learning,Suicide,Spy,Mercenary, *
  1402. * RecruitPriority,MaxAllowed,InitNum,Fear, *
  1403. * ClassCount,Class:Num,Class:Num,..., *
  1404. * MissionCount,Mission:Arg,Mission:Arg,Mission:Arg,... *
  1405. * *
  1406. * INPUT: *
  1407. * buffer buffer to hold the INI data *
  1408. * *
  1409. * OUTPUT: *
  1410. * none. *
  1411. * *
  1412. * WARNINGS: *
  1413. * none. *
  1414. * *
  1415. * HISTORY: *
  1416. * 12/07/1994 BR : Created. *
  1417. * 02/01/1995 BR : No del team if no classes (editor needs empty teams!) *
  1418. *=========================================================================*/
  1419. void TeamTypeClass::Read_INI(CCINIClass & ini)
  1420. {
  1421. TeamTypeClass * team; // Working team pointer.
  1422. char buf[500]; // INI entry buffer
  1423. int len = ini.Entry_Count(INI_Name());
  1424. /*
  1425. ** Loop for all team entries, create and fill in.
  1426. */
  1427. for (int index = 0; index < len; index++) {
  1428. team = new TeamTypeClass();
  1429. if (team != NULL) {
  1430. char const * entry = ini.Get_Entry(INI_Name(), index);
  1431. ini.Get_String(INI_Name(), entry, NULL, buf, sizeof(buf));
  1432. team->Fill_In((char *)entry, buf);
  1433. }
  1434. }
  1435. }
  1436. /***********************************************************************************************
  1437. * TeamTypeClass::Fill_In -- fills in trigger from the given INI entry *
  1438. * *
  1439. * This routine fills in the given teamtype with the given name, and values from *
  1440. * the given INI entry. *
  1441. * *
  1442. * (This routine is used by the scenario editor, to import teams from the MASTER.INI file.) *
  1443. * *
  1444. * INI entry format: *
  1445. * TeamName = Housename,Roundabout,Learning,Suicide,Spy,Mercenary, *
  1446. * RecruitPriority,MaxAllowed,InitNum,Fear, *
  1447. * ClassCount,Class:Num,Class:Num,..., *
  1448. * MissionCount,Mission:Arg,Mission:Arg,Mission:Arg,... *
  1449. * *
  1450. * INPUT: *
  1451. * name mnemonic for the desired trigger *
  1452. * entry INI entry to parse *
  1453. * *
  1454. * OUTPUT: *
  1455. * none. *
  1456. * *
  1457. * WARNINGS: *
  1458. * none. *
  1459. * *
  1460. * HISTORY: *
  1461. * 11/28/1994 BR : Created. *
  1462. * 11/29/1995 JLB : Revamped to use new team class. *
  1463. *=============================================================================================*/
  1464. void TeamTypeClass::Fill_In(char * name, char * entry)
  1465. {
  1466. assert(TeamTypes.ID(this) == ID);
  1467. /*
  1468. ** Set its name
  1469. */
  1470. Set_Name(name);
  1471. House = HousesType(atoi(strtok(entry, ",")));
  1472. int code;
  1473. switch (NewINIFormat) {
  1474. default:
  1475. code = atoi(strtok(NULL, ","));
  1476. IsRoundAbout = ((code & 0x0001) != 0);
  1477. IsSuicide = ((code & 0x0002) != 0);
  1478. IsAutocreate = ((code & 0x0004) != 0);
  1479. IsPrebuilt = ((code & 0x0008) != 0);
  1480. IsReinforcable = ((code & 0x0010) != 0);
  1481. break;
  1482. case 0:
  1483. case 1:
  1484. IsRoundAbout = atoi(strtok(NULL, ","));
  1485. IsSuicide = atoi(strtok(NULL, ","));
  1486. IsAutocreate = atoi(strtok(NULL, ","));
  1487. IsPrebuilt = atoi(strtok(NULL, ","));
  1488. IsReinforcable = atoi(strtok(NULL, ","));
  1489. break;
  1490. }
  1491. RecruitPriority = atoi(strtok(NULL, ","));
  1492. InitNum = atoi(strtok(NULL, ","));
  1493. MaxAllowed = atoi(strtok(NULL, ","));
  1494. Origin = atoi(strtok(NULL, ","));
  1495. switch (NewINIFormat) {
  1496. default:
  1497. Trigger.Set_Raw(atoi(strtok(NULL, ",")));
  1498. break;
  1499. case 0:
  1500. case 1:
  1501. // Throw this token away -- it isn't used.
  1502. strtok(NULL, ",");
  1503. break;
  1504. }
  1505. /*
  1506. ** Fetch the team member types and quantity values.
  1507. */
  1508. ClassCount = atoi(strtok(NULL, ","));
  1509. for (int index = 0; index < ClassCount; index++) {
  1510. char * p1 = strtok(NULL, ",:");
  1511. char * p2 = strtok(NULL, ",:");
  1512. TechnoTypeClass const * otype = NULL;
  1513. /*
  1514. ** See if this is an infantry name
  1515. */
  1516. InfantryType i_id = InfantryTypeClass::From_Name(p1);
  1517. if (i_id != INFANTRY_NONE) {
  1518. otype = &InfantryTypeClass::As_Reference(i_id);
  1519. } else {
  1520. /*
  1521. ** See if this is a unit name
  1522. */
  1523. UnitType u_id = UnitTypeClass::From_Name(p1);
  1524. if (u_id != UNIT_NONE) {
  1525. otype = &UnitTypeClass::As_Reference(u_id);
  1526. } else {
  1527. /*
  1528. ** See if this is an aircraft name
  1529. */
  1530. AircraftType a_id = AircraftTypeClass::From_Name(p1);
  1531. if (a_id != AIRCRAFT_NONE) {
  1532. otype = &AircraftTypeClass::As_Reference(a_id);
  1533. } else {
  1534. /*
  1535. ** See if this is a vessel name.
  1536. */
  1537. VesselType v_id = VesselTypeClass::From_Name(p1);
  1538. if (v_id != VESSEL_NONE) {
  1539. otype = &VesselTypeClass::As_Reference(v_id);
  1540. }
  1541. }
  1542. }
  1543. }
  1544. /*
  1545. ** If the name was resolved, add this class
  1546. */
  1547. if (otype) {
  1548. Members[index].Class = otype;
  1549. Members[index].Quantity = atoi(p2);
  1550. } else {
  1551. ClassCount--;
  1552. if (index == 0) break;
  1553. index--;
  1554. }
  1555. }
  1556. /*
  1557. ** Fetch the missions assigned to this team type.
  1558. */
  1559. MissionCount = atoi(strtok(NULL, ","));
  1560. for (index = 0; index < MissionCount; index++) {
  1561. MissionList[index].Mission = TeamMissionType(atoi(strtok(NULL, ",:")));
  1562. MissionList[index].Data.Value = atoi(strtok(NULL, ",:"));
  1563. }
  1564. if (NewINIFormat < 2) {
  1565. /*
  1566. ** Fetch the trigger ID.
  1567. */
  1568. Trigger.Set_Raw(atoi(strtok(NULL, ",")));
  1569. }
  1570. }
  1571. /***********************************************************************************************
  1572. * TeamTypeClass::Write_INI -- Write out the team types to the INI database. *
  1573. * *
  1574. * This routine will take all team types and write them out to the INI database specified. *
  1575. * *
  1576. * INPUT: ini -- Reference to the INI database that will hold al the teams. *
  1577. * *
  1578. * OUTPUT: none *
  1579. * *
  1580. * WARNINGS: All preexisting team data in the database will be erased by this routine. *
  1581. * *
  1582. * HISTORY: *
  1583. * 07/30/1996 JLB : Created. *
  1584. *=============================================================================================*/
  1585. void TeamTypeClass::Write_INI(CCINIClass & ini)
  1586. {
  1587. ini.Clear("TeamTypes");
  1588. ini.Clear(INI_Name());
  1589. /*
  1590. ** Now write all the team data out
  1591. */
  1592. for (int index = 0; index < TeamTypes.Count(); index++) {
  1593. // for (int index = TeamTypes.Count()-1; index >= 0; index--) {
  1594. TeamTypeClass * team = TeamTypes.Ptr(index);
  1595. char buf[256];
  1596. buf[0] = 0;
  1597. team->Build_INI_Entry(buf);
  1598. ini.Put_String(INI_Name(), team->IniName, buf);
  1599. }
  1600. }
  1601. /***********************************************************************************************
  1602. * TeamTypeClass::Build_INI_Entry -- Builds the INI entry for this team type. *
  1603. * *
  1604. * This routine is used to build the text string that will go into the INI database for *
  1605. * a team of this type. This text string will be parsed back into a team object when the *
  1606. * scenario INI is read in. *
  1607. * *
  1608. * INPUT: buf -- Pointer to a buffer that will hold the team text entry. *
  1609. * *
  1610. * OUTPUT: none *
  1611. * *
  1612. * WARNINGS: Be sure that the buffer can hold the string build. A size of 80 or so is *
  1613. * usually sufficient. *
  1614. * *
  1615. * HISTORY: *
  1616. * 07/30/1996 JLB : Created. *
  1617. *=============================================================================================*/
  1618. void TeamTypeClass::Build_INI_Entry(char * buf)
  1619. {
  1620. int code = 0;
  1621. code |= IsRoundAbout ? 0x0001 : 0;
  1622. code |= IsSuicide ? 0x0002 : 0;
  1623. code |= IsAutocreate ? 0x0004 : 0;
  1624. code |= IsPrebuilt ? 0x0008 : 0;
  1625. code |= IsReinforcable ? 0x0010 : 0;
  1626. /*
  1627. ** Output the general data for this team type.
  1628. */
  1629. sprintf(buf, "%d,%d,%d,%d,%d,%d,%d",
  1630. House,
  1631. code,
  1632. RecruitPriority,
  1633. InitNum,
  1634. MaxAllowed,
  1635. Origin,
  1636. TriggerTypes.Logical_ID(Trigger)
  1637. );
  1638. buf += strlen(buf);
  1639. /*
  1640. ** For every class in the team, record the class's name & desired count
  1641. */
  1642. sprintf (buf, ",%d", ClassCount);
  1643. buf += strlen(buf);
  1644. for (int i = 0; i < ClassCount; i++) {
  1645. sprintf (buf, ",%s:%d", Members[i].Class->IniName, Members[i].Quantity);
  1646. buf += strlen(buf);
  1647. }
  1648. /*
  1649. ** Record the # of missions, and each mission name & argument value.
  1650. */
  1651. sprintf(buf, ",%d", MissionCount);
  1652. buf += strlen(buf);
  1653. for (i = 0; i < MissionCount; i++) {
  1654. sprintf (buf, ",%d:%d", MissionList[i].Mission, MissionList[i].Data.Value);
  1655. buf += strlen(buf);
  1656. }
  1657. }