FACTORY.CPP 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: F:\projects\c&c\vcs\code\factory.cpv 2.18 16 Oct 1995 16:51:26 JOE_BOSTIC $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : FACTORY.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 12/26/94 *
  26. * *
  27. * Last Update : May 22, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * FactoryClass::AI -- Process factory production logic. *
  32. * FactoryClass::Abandon -- Abandons current construction with money refunded. *
  33. * FactoryClass::Completed -- Clears factory object after a completed production process. *
  34. * FactoryClass::Completion -- Fetchs the completion step for this factory. *
  35. * FactoryClass::Cost_Per_Tick -- Breaks entire production cost into managable chunks. *
  36. * FactoryClass::FactoryClass -- Default constructor for factory objects. *
  37. * FactoryClass::Get_Object -- Fetches pointer to object being constructed. *
  38. * FactoryClass::Get_Special_Item -- gets factorys spc prod item *
  39. * FactoryClass::Has_Changed -- Checks to see if a production step has occurred? *
  40. * FactoryClass::Has_Completed -- Checks to see if object has completed production. *
  41. * FactoryClass::Set -- Assigns a factory to produce an object. *
  42. * FactoryClass::Set -- Fills a factory with an already completed object. *
  43. * FactoryClass::Set -- Force factory to "produce" special object. *
  44. * FactoryClass::Start -- Resumes production after suspension or creation. *
  45. * FactoryClass::Suspend -- Temporarily stop production. *
  46. * FactoryClass::operator delete -- Returns a factory to the free factory pool. *
  47. * FactoryClass::operator new -- Allocates a factory object from the free factory pool. *
  48. * FactoryClass::~FactoryClass -- Default destructor for factory objects. *
  49. * FactoryClass::Validate -- validates factory pointer *
  50. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  51. #include "function.h"
  52. /***********************************************************************************************
  53. * FactoryClass::Validate -- validates factory pointer *
  54. * *
  55. * INPUT: *
  56. * none. *
  57. * *
  58. * OUTPUT: *
  59. * 1 = ok, 0 = error *
  60. * *
  61. * WARNINGS: *
  62. * none. *
  63. * *
  64. * HISTORY: *
  65. * 08/09/1995 BRR : Created. *
  66. *=============================================================================================*/
  67. #ifdef CHEAT_KEYS
  68. int FactoryClass::Validate(void) const
  69. {
  70. int num;
  71. num = Factories.ID(this);
  72. if (num < 0 || num >= FACTORY_MAX) {
  73. Validate_Error("FACTORY");
  74. return (0);
  75. }
  76. else
  77. return (1);
  78. }
  79. #else
  80. #define Validate()
  81. #endif
  82. /***********************************************************************************************
  83. * FactoryClass::FactoryClass -- Default constructor for factory objects. *
  84. * *
  85. * This brings the factory into a null state. It is called when a factory object is *
  86. * created. *
  87. * *
  88. * INPUT: none *
  89. * *
  90. * OUTPUT: none *
  91. * *
  92. * WARNINGS: none *
  93. * *
  94. * HISTORY: *
  95. * 12/26/1994 JLB : Created. *
  96. *=============================================================================================*/
  97. FactoryClass::FactoryClass(void)
  98. {
  99. IsSuspended = false;
  100. IsDifferent = false;
  101. IsBlocked = false;
  102. Balance = 0;
  103. SpecialItem = SPC_NONE;
  104. Object = NULL;
  105. House = NULL;
  106. Set_Rate(0);
  107. Set_Stage(0);
  108. }
  109. /***********************************************************************************************
  110. * FactoryClass::~FactoryClass -- Default destructor for factory objects. *
  111. * *
  112. * This cleans up a factory object in preparation for deletion. If there is currently *
  113. * an object in production, it is abandoned and money is refunded. *
  114. * *
  115. * INPUT: none *
  116. * *
  117. * OUTPUT: none *
  118. * *
  119. * WARNINGS: none *
  120. * *
  121. * HISTORY: *
  122. * 12/26/1994 JLB : Created. *
  123. *=============================================================================================*/
  124. FactoryClass::~FactoryClass(void)
  125. {
  126. if (GameActive) {
  127. Abandon();
  128. }
  129. }
  130. /***********************************************************************************************
  131. * FactoryClass::Init -- Clears all units for scenario preparation. *
  132. * *
  133. * This routine will zero out the factory list and objects. This routine is typically *
  134. * used in preparation for a new scenario load. All factorys are guaranteed to be eliminated*
  135. * by this routine. *
  136. * *
  137. * INPUT: none *
  138. * *
  139. * OUTPUT: none *
  140. * *
  141. * WARNINGS: none *
  142. * *
  143. * HISTORY: *
  144. * 08/15/1994 JLB : Created. *
  145. *=============================================================================================*/
  146. void FactoryClass::Init(void)
  147. {
  148. Factories.Free_All();
  149. }
  150. /***********************************************************************************************
  151. * FactoryClass::operator new -- Allocates a factory object from the free factory pool. *
  152. * *
  153. * This routine allocates a factory from the free factory pool. If there is no more room *
  154. * to allocate a factory, then NULL is returned. *
  155. * *
  156. * INPUT: none *
  157. * *
  158. * OUTPUT: Returns with pointer to the newly allocated factory object. *
  159. * *
  160. * WARNINGS: none *
  161. * *
  162. * HISTORY: *
  163. * 12/26/1994 JLB : Created. *
  164. *=============================================================================================*/
  165. void * FactoryClass::operator new(size_t)
  166. {
  167. void * ptr = Factories.Allocate();
  168. if (ptr) {
  169. ((FactoryClass *)ptr)->IsActive = true;
  170. }
  171. return(ptr);
  172. }
  173. /***********************************************************************************************
  174. * FactoryClass::operator delete -- Returns a factory to the free factory pool. *
  175. * *
  176. * This returns the factory object back to the factory allocation pool. The factory is then *
  177. * available to be allocated. *
  178. * *
  179. * INPUT: ptr -- Pointer to the factory object to delete. *
  180. * *
  181. * OUTPUT: none *
  182. * *
  183. * WARNINGS: none *
  184. * *
  185. * HISTORY: *
  186. * 12/26/1994 JLB : Created. *
  187. *=============================================================================================*/
  188. void FactoryClass::operator delete(void *ptr)
  189. {
  190. if (ptr) {
  191. ((FactoryClass *)ptr)->IsActive = false;
  192. }
  193. Factories.Free((FactoryClass *)ptr);
  194. }
  195. /***********************************************************************************************
  196. * FactoryClass::AI -- Process factory production logic. *
  197. * *
  198. * This routine should be called once per game tick. It handles the production process. *
  199. * As production proceeds, money is deducted from the owner object's house. When production *
  200. * completes, the factory stop processing. A call to Abandon, Delete, or Completed is *
  201. * required after that point. *
  202. * *
  203. * INPUT: none *
  204. * *
  205. * OUTPUT: none *
  206. * *
  207. * WARNINGS: none *
  208. * *
  209. * HISTORY: *
  210. * 12/26/1994 JLB : Created. *
  211. * 01/04/1995 JLB : Uses exact installment payment method. *
  212. *=============================================================================================*/
  213. void FactoryClass::AI(void)
  214. {
  215. Validate();
  216. if (!IsSuspended && (Object != NULL || SpecialItem)) {
  217. int stages = 1;
  218. /*
  219. ** Determine the acceleration factor for factory production.
  220. ** This applies only to human players. The computer builds
  221. ** units on a building by building basis -- quantity of building
  222. ** factory types doesn't affect individual factories.
  223. */
  224. if (Object && House->IsHuman) {
  225. switch (Object->What_Am_I()) {
  226. case RTTI_AIRCRAFT:
  227. stages = House->AircraftFactories;
  228. break;
  229. case RTTI_INFANTRY:
  230. stages = House->InfantryFactories;
  231. break;
  232. case RTTI_UNIT:
  233. stages = House->UnitFactories;
  234. break;
  235. case RTTI_BUILDING:
  236. stages = House->BuildingFactories;
  237. break;
  238. }
  239. stages = MAX(stages, 1);
  240. }
  241. for (int index = 0; index < stages; index++) {
  242. if (!Has_Completed() && Graphic_Logic()) {
  243. IsDifferent = true;
  244. int cost = Cost_Per_Tick();
  245. cost = MIN(cost, Balance);
  246. /*
  247. ** Enough time has expired so that another production step can occur.
  248. ** If there is insufficient funds, then go back one production step and
  249. ** continue the countdown. The idea being that by the time the next
  250. ** production step occurs, there may be sufficient funds available.
  251. */
  252. if (cost > House->Available_Money()) {
  253. Set_Stage(Fetch_Stage()-1);
  254. } else {
  255. House->Spend_Money(cost);
  256. Balance -= cost;
  257. }
  258. if ( Debug_Instant_Build ) {
  259. Set_Stage(STEP_COUNT);
  260. }
  261. /*
  262. ** If the production has completed, then suspend further production.
  263. */
  264. if (Fetch_Stage() == STEP_COUNT) {
  265. IsSuspended = true;
  266. Set_Rate(0);
  267. House->Spend_Money(Balance);
  268. Balance = 0;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. /***********************************************************************************************
  275. * FactoryClass::Force_Complete -- Force the factory to finish what it's building *
  276. * *
  277. * For debugging/testing support *
  278. * *
  279. * *
  280. * INPUT: none *
  281. * *
  282. * OUTPUT: none *
  283. * *
  284. * WARNINGS: *
  285. * *
  286. * HISTORY: *
  287. * 8/23/2019 3:54PM ST : Created. *
  288. *=============================================================================================*/
  289. void FactoryClass::Force_Complete(void)
  290. {
  291. Validate();
  292. if (!IsSuspended && (Object != NULL || SpecialItem)) {
  293. Set_Stage(STEP_COUNT);
  294. IsSuspended = true;
  295. Set_Rate(0);
  296. Balance = 0;
  297. IsDifferent = true;
  298. }
  299. }
  300. /***********************************************************************************************
  301. * FactoryClass::Has_Changed -- Checks to see if a production step has occurred? *
  302. * *
  303. * Use this routine to determine if production has advanced at least one step. By using *
  304. * this function, intelligent rendering may be performed. *
  305. * *
  306. * INPUT: none *
  307. * *
  308. * OUTPUT: bool; Has the production process advanced one step since the last time this *
  309. * function was called? *
  310. * *
  311. * WARNINGS: This function clears the changed status flag as a side effect. *
  312. * *
  313. * HISTORY: *
  314. * 12/26/1994 JLB : Created. *
  315. *=============================================================================================*/
  316. bool FactoryClass::Has_Changed(void)
  317. {
  318. Validate();
  319. bool changed = IsDifferent;
  320. IsDifferent = false;
  321. return(changed);
  322. }
  323. /***********************************************************************************************
  324. * FactoryClass::Set -- Assigns a factory to produce an object. *
  325. * *
  326. * This routine initializes a factory to produce the object specified. The desired object *
  327. * type is created and placed in suspended animation (limbo) until such time as production *
  328. * completes. Production is not actually started by this routine. An explicit call to *
  329. * Start() is required to begin production. *
  330. * *
  331. * INPUT: object -- Reference to the object type class that is to be produced. *
  332. * *
  333. * house -- Reference to the owner of the object to be produced. *
  334. * *
  335. * OUTPUT: bool; Was production successfully prepared for this factory object. Failure means *
  336. * that the object could not be created. This is catastrophic and in such *
  337. * cases, the factory object should be deleted. *
  338. * *
  339. * WARNINGS: Be sure to examine the return value from this function. Failure to initialize *
  340. * the factory means that the factory is useless and should be deleted. *
  341. * *
  342. * HISTORY: *
  343. * 12/26/1994 JLB : Created. *
  344. *=============================================================================================*/
  345. bool FactoryClass::Set(TechnoTypeClass const & object, HouseClass & house)
  346. {
  347. Validate();
  348. /*
  349. ** If there is any production currently in progress, abandon it.
  350. */
  351. Abandon();
  352. /*
  353. ** Set up the factory for the new production process.
  354. */
  355. IsDifferent = true;
  356. IsSuspended = true;
  357. Set_Rate(0);
  358. Set_Stage(0);
  359. /*
  360. ** Create an object of the type requested.
  361. */
  362. Object = (TechnoClass *)object.Create_One_Of(&house);
  363. if (Object) {
  364. House = Object->House;
  365. Balance = object.Cost_Of() * house.CostBias;
  366. Object->PurchasePrice = Balance;
  367. }
  368. /*
  369. ** If all was set up successfully, then return true.
  370. */
  371. return(Object != NULL);
  372. }
  373. /***********************************************************************************************
  374. * FactoryClass::Set -- Force factory to "produce" special object. *
  375. * *
  376. * Use this routine to force the factory into special production mode. Such production is *
  377. * used for the ion cannon and other timed special weapon events. *
  378. * *
  379. * INPUT: type -- The special weapon type to begin "production" of. *
  380. * *
  381. * house -- The owner of this production object. *
  382. * *
  383. * OUTPUT: Was the assignment successful? *
  384. * *
  385. * WARNINGS: none *
  386. * *
  387. * HISTORY: *
  388. * 05/22/1995 JLB : Created. *
  389. *=============================================================================================*/
  390. bool FactoryClass::Set(int const & type, HouseClass & house)
  391. {
  392. Validate();
  393. /*
  394. ** If there is any production currently in progress, abandon it.
  395. */
  396. Abandon();
  397. /*
  398. ** Set up the factory for the new production process.
  399. */
  400. IsDifferent = true;
  401. IsSuspended = true;
  402. Set_Rate(0);
  403. Set_Stage(0);
  404. /*
  405. ** Create an object of the type requested.
  406. */
  407. SpecialItem = type;
  408. House = &house;
  409. Balance = 0;
  410. /*
  411. ** If all was set up successfully, then return true.
  412. */
  413. return(SpecialItem != SPC_NONE);
  414. }
  415. /***********************************************************************************************
  416. * FactoryClass::Set -- Fills a factory with an already completed object. *
  417. * *
  418. * This routine is called when a produced object is in placement mode but then placement *
  419. * is suspended. The object must then return to the factory as if it were newly completed *
  420. * and awaiting removal. *
  421. * *
  422. * INPUT: object -- The object to return to the factory. *
  423. * *
  424. * OUTPUT: none *
  425. * *
  426. * WARNINGS: This will abandon any current object being produced at the factory in order *
  427. * to set the new object into it. *
  428. * *
  429. * HISTORY: *
  430. * 12/26/1994 JLB : Created. *
  431. *=============================================================================================*/
  432. void FactoryClass::Set(TechnoClass & object)
  433. {
  434. Validate();
  435. Abandon();
  436. Object = &object;
  437. House = Object->House;
  438. Balance = 0;
  439. Set_Rate(0);
  440. Set_Stage(STEP_COUNT);
  441. IsDifferent = true;
  442. IsSuspended = true;
  443. }
  444. /***********************************************************************************************
  445. * FactoryClass::Suspend -- Temporarily stop production. *
  446. * *
  447. * This routine will suspend production until a subsiquent call to Start() or Abandon(). *
  448. * Typical use of this function is when the player puts production on hold or when there *
  449. * is insufficient funds. *
  450. * *
  451. * INPUT: none *
  452. * *
  453. * OUTPUT: bool; Was production actually stopped? A false return value indicates that the *
  454. * factory was empty or production was already stopped (or never started). *
  455. * *
  456. * WARNINGS: none *
  457. * *
  458. * HISTORY: *
  459. * 12/26/1994 JLB : Created. *
  460. *=============================================================================================*/
  461. bool FactoryClass::Suspend(void)
  462. {
  463. Validate();
  464. if (!IsSuspended) {
  465. IsSuspended = true;
  466. Set_Rate(0);
  467. return(true);
  468. }
  469. return(false);
  470. }
  471. /***********************************************************************************************
  472. * FactoryClass::Start -- Resumes production after suspension or creation. *
  473. * *
  474. * This function will start the production process. It works for newly created factory *
  475. * objects, as well as if production had been suspended previously. *
  476. * *
  477. * INPUT: none *
  478. * *
  479. * OUTPUT: bool; Was production started? A false return value means that the factory is *
  480. * empty or there is unsufficient credits to begin production. *
  481. * *
  482. * WARNINGS: none *
  483. * *
  484. * HISTORY: *
  485. * 12/26/1994 JLB : Created. *
  486. *=============================================================================================*/
  487. bool FactoryClass::Start(void)
  488. {
  489. Validate();
  490. if ((Object || SpecialItem) && IsSuspended && !Has_Completed()) {
  491. if (House->IsHuman || House->Available_Money() >= Cost_Per_Tick()) {
  492. int time;
  493. if (Object) {
  494. time = Object->Class_Of().Time_To_Build(House->Class->House);
  495. } else {
  496. time = TICKS_PER_MINUTE * 5;
  497. }
  498. time /= STEP_COUNT;
  499. time = Bound(time, 1, 255);
  500. Set_Rate(time);
  501. IsSuspended = false;
  502. return(true);
  503. }
  504. }
  505. return(false);
  506. }
  507. /***********************************************************************************************
  508. * FactoryClass::Abandon -- Abandons current construction with money refunded. *
  509. * *
  510. * This routine is used when construction is to be abandoned and current money spend is *
  511. * to be refunded. This function effectively clears out this factory of all record of the *
  512. * producing object so that it may either be deleted or started anew with the Set() *
  513. * function. *
  514. * *
  515. * INPUT: none *
  516. * *
  517. * OUTPUT: bool; Was an object actually abandoned? A false return value indicates that the *
  518. * factory was not producing any object. *
  519. * *
  520. * WARNINGS: none *
  521. * *
  522. * HISTORY: *
  523. * 12/26/1994 JLB : Created. *
  524. *=============================================================================================*/
  525. bool FactoryClass::Abandon(void)
  526. {
  527. Validate();
  528. if (Object) {
  529. if (Object) {
  530. /*
  531. ** Refund all money expended so far, back to the owner of the object under construction.
  532. */
  533. int money = Object->Class_Of().Cost_Of() * Object->House->CostBias;
  534. House->Refund_Money(money - Balance);
  535. Balance = 0;
  536. /*
  537. ** Delete the object under construction.
  538. */
  539. ScenarioInit++;
  540. delete Object;
  541. Object = NULL;
  542. ScenarioInit--;
  543. }
  544. if (SpecialItem) {
  545. SpecialItem = SPC_NONE;
  546. }
  547. /*
  548. ** Set the factory back to the idle and empty state.
  549. */
  550. Set_Rate(0);
  551. Set_Stage(0);
  552. IsSuspended = true;
  553. IsDifferent = true;
  554. return(true);
  555. }
  556. return(false);
  557. }
  558. /***********************************************************************************************
  559. * FactoryClass::Completion -- Fetchs the completion step for this factory. *
  560. * *
  561. * Use this routine to determine what animation (or completion step) the factory is *
  562. * currently on. *
  563. * *
  564. * INPUT: none *
  565. * *
  566. * OUTPUT: Returns a completion step number beteen 0 (uncompleted), to STEP_COUNT (completed) *
  567. * *
  568. * WARNINGS: none *
  569. * *
  570. * HISTORY: *
  571. * 12/26/1994 JLB : Created. *
  572. *=============================================================================================*/
  573. int FactoryClass::Completion(void)
  574. {
  575. Validate();
  576. return(Fetch_Stage());
  577. }
  578. /***********************************************************************************************
  579. * FactoryClass::Has_Completed -- Checks to see if object has completed production. *
  580. * *
  581. * Use this routine to examine the factory object in order to determine if the associated *
  582. * object has completed production and is awaiting placement. *
  583. * *
  584. * INPUT: none *
  585. * *
  586. * OUTPUT: bool; Is the associated object to the factory completed and ready for placement? *
  587. * *
  588. * WARNINGS: none *
  589. * *
  590. * HISTORY: *
  591. * 12/26/1994 JLB : Created. *
  592. *=============================================================================================*/
  593. bool FactoryClass::Has_Completed(void)
  594. {
  595. Validate();
  596. if (Object && Fetch_Stage() == STEP_COUNT) {
  597. return(true);
  598. }
  599. if (SpecialItem && Fetch_Stage() == STEP_COUNT) {
  600. return(true);
  601. }
  602. return(false);
  603. }
  604. /***********************************************************************************************
  605. * FactoryClass::Get_Object -- Fetches pointer to object being constructed. *
  606. * *
  607. * This routine gets the pointer to the currently constructing object. *
  608. * *
  609. * INPUT: none *
  610. * *
  611. * OUTPUT: Returns with a pointer to the object undergoing construction. *
  612. * *
  613. * WARNINGS: none *
  614. * *
  615. * HISTORY: *
  616. * 12/26/1994 JLB : Created. *
  617. *=============================================================================================*/
  618. TechnoClass * FactoryClass::Get_Object(void) const
  619. {
  620. Validate();
  621. return(Object);
  622. }
  623. /***************************************************************************
  624. * FactoryClass::Get_Special_Item -- gets factorys spc prod item *
  625. * *
  626. * INPUT: none *
  627. * *
  628. * OUTPUT: int the item the factory is currently working on *
  629. * *
  630. * HISTORY: *
  631. * 05/05/1995 PWG : Created. *
  632. *=========================================================================*/
  633. int FactoryClass::Get_Special_Item(void) const
  634. {
  635. Validate();
  636. return(SpecialItem);
  637. }
  638. /***********************************************************************************************
  639. * FactoryClass::Cost_Per_Tick -- Breaks entire production cost into managable chunks. *
  640. * *
  641. * Use this routine to determine the cost per game "tick" to produce the object. *
  642. * *
  643. * INPUT: none *
  644. * *
  645. * OUTPUT: Returns the number of credits necessary to advance production one game tick. *
  646. * *
  647. * WARNINGS: none *
  648. * *
  649. * HISTORY: *
  650. * 12/26/1994 JLB : Created. *
  651. *=============================================================================================*/
  652. int FactoryClass::Cost_Per_Tick(void)
  653. {
  654. Validate();
  655. if (Object) {
  656. int steps = STEP_COUNT - Fetch_Stage();
  657. if (steps) {
  658. return(Balance / steps);
  659. }
  660. return(Balance);
  661. }
  662. return(0);
  663. }
  664. /***********************************************************************************************
  665. * FactoryClass::Completed -- Clears factory object after a completed production process. *
  666. * *
  667. * This routine is called after production completes, and the object produced has been *
  668. * placed into the game. It resets the factory for deletion or starting of new production. *
  669. * *
  670. * INPUT: none *
  671. * *
  672. * OUTPUT: bool; Did any resetting occur? Failure is the result of the factory not having *
  673. * any completed object. An immediate second call to this routine will also *
  674. * yield false. *
  675. * *
  676. * WARNINGS: none *
  677. * *
  678. * HISTORY: *
  679. * 12/26/1994 JLB : Created. *
  680. *=============================================================================================*/
  681. bool FactoryClass::Completed(void)
  682. {
  683. Validate();
  684. if (Object && Fetch_Stage() == STEP_COUNT) {
  685. Object = NULL;
  686. IsSuspended = true;
  687. IsDifferent = true;
  688. Set_Stage(0);
  689. Set_Rate(0);
  690. return(true);
  691. }
  692. if (SpecialItem && Fetch_Stage() == STEP_COUNT) {
  693. SpecialItem = SPC_NONE;
  694. IsSuspended = true;
  695. IsDifferent = true;
  696. Set_Stage(0);
  697. Set_Rate(0);
  698. return(true);
  699. }
  700. return(false);
  701. }