aivars.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // aivars.cpp
  19. // Project: Postal
  20. //
  21. // History:
  22. // 05/19/97 BRH Started.
  23. //
  24. // 05/19/97 BRH Added the first few logic variables.
  25. //
  26. // 05/20/97 BRH Changed real states to suggested Actions. Also added
  27. // Pylon availability variables.
  28. //
  29. // 05/26/97 BRH Added IsTriggered variable so that you can distinguish
  30. // between a Dude nearby and a Dude nearby who is also
  31. // standing on the trigger area for your pylon based logic.
  32. //
  33. // 05/27/97 BRH Added Recently Shot variable. Tuned the distances.
  34. //
  35. // 05/31/97 JMI Changed usage from CDoofus::m_pDude to CDoofus::m_idDude
  36. // (see doofus.cpp comment with same date for info).
  37. // PLEASE NOTE: I could not help but notice that
  38. // CLogTabVar_DudeHealth::GetVal() calls pPerson->SelectDude()
  39. // without first checking if that person was already
  40. // tracking a dude. I just though this was bad as it could
  41. // cause inconsistent behavior between the same states with
  42. // different logic tables and/or values for logic tables.
  43. //
  44. // 06/05/97 JMI Changed m_sHitPoints to m_stockpile.m_sHitPoints to
  45. // accommodate new m_stockpile in base class, CThing3d (which
  46. // used to contain the m_sHitPoints).
  47. //
  48. // 07/06/97 BRH Added panic variable so the logic table can decide if
  49. // a person should panic based on other people choosing to
  50. // panic.
  51. //
  52. // 08/09/97 BRH Made a minor change to the IsPanic variable.
  53. //
  54. // 08/29/97 BRH Added a Statis user variable for the people so that
  55. // a logic table for one person can set this variable
  56. // that others can then use. This will be used for the
  57. // kids where one kid will trigger the others into doing
  58. // their group attack logic.
  59. //
  60. ////////////////////////////////////////////////////////////////////////////////
  61. #include "RSPiX.h"
  62. #include "logtab.h"
  63. #include "person.h"
  64. #include "Thing3d.h"
  65. #include "doofus.h"
  66. // Action input variable
  67. class CLogTabVar_GetAction : CLogTabVar<CPerson*>
  68. {
  69. public:
  70. CLogTabVar_GetAction()
  71. {
  72. m_pszName = "GET_ACTION";
  73. m_sMaxVal = CDoofus::NumActions;
  74. m_bSettable = false;
  75. m_sOutputWidth = 13;
  76. // This var is number-based, so turn off string stuff
  77. m_sNumStrings = CDoofus::NumActions;
  78. m_papszStrings = CDoofus::ms_apszActionNames;
  79. }
  80. short GetVal(CPerson* pPerson)
  81. {
  82. return pPerson->m_eCurrentAction;
  83. }
  84. void SetVal(CPerson* pPerson, short sVal)
  85. {
  86. }
  87. } givename_getaction;
  88. // Action output variable
  89. class CLogTabVar_SetAction : CLogTabVar<CPerson*>
  90. {
  91. public:
  92. CLogTabVar_SetAction()
  93. {
  94. m_pszName = "SET_ACTION";
  95. m_sMaxVal = CDoofus::NumActions;
  96. m_bSettable = true;
  97. m_sOutputWidth = 13;
  98. // This var is number-based, so turn off string stuff
  99. m_sNumStrings = CDoofus::NumActions;
  100. m_papszStrings = CDoofus::ms_apszActionNames;
  101. }
  102. short GetVal(CPerson* pPerson)
  103. {
  104. return pPerson->m_eSuggestedAction;
  105. }
  106. void SetVal(CPerson* pPerson, short sVal)
  107. {
  108. pPerson->m_eSuggestedAction = (CDoofus::Action) sVal;
  109. }
  110. } givename_setaction;
  111. // Distance to target input variable
  112. class CLogTabVar_TargetDist : CLogTabVar<CPerson*>
  113. {
  114. public:
  115. CLogTabVar_TargetDist()
  116. {
  117. m_pszName = "TARGET_DIST";
  118. m_sMaxVal = 2;
  119. m_bSettable = false;
  120. m_sOutputWidth = 13;
  121. // This var is number-based, so turn off string stuff
  122. // IMPORTANT: these enums all represent distance RANGES!
  123. // Each one means "between myself and the next highest value"
  124. //
  125. static char* ms_sz[] = {"VeryClose", "Close", "Medium", "Far","OffScreen"};
  126. m_sNumStrings = 5;
  127. m_papszStrings = ms_sz;
  128. }
  129. short GetVal(CPerson* pPerson)
  130. {
  131. // Define local arguements which may become inputs:
  132. // (They are the squared distances...)
  133. // NOTE THAT THESE ARE RANGES BETWEEN MYSELF AND THE NEXT HIGHEST!
  134. // THE FINAL ENUM HAS NO UPPER BOUND!
  135. // You cannot evaluate < lowest or > highest!
  136. // LOWER BOUNDS OF RANGE!
  137. #define DIST_VERY_CLOSE_2 (0 * 0) // the lowest measure
  138. #define DIST_CLOSE_2 (80 * 80)
  139. #define DIST_MEDIUM_2 (180 * 180)
  140. #define DIST_FAR_2 (400 * 400)
  141. #define DIST_OFF_SCREEN_2 (800 * 800)
  142. double dSqDist = pPerson->SQDistanceToDude();
  143. if (dSqDist > DIST_OFF_SCREEN_2)
  144. return 4;
  145. if (dSqDist > DIST_FAR_2)
  146. return 3;
  147. if (dSqDist > DIST_MEDIUM_2)
  148. return 2;
  149. if (dSqDist > DIST_CLOSE_2)
  150. return 1;
  151. else // DIST_VERY_CLOSE_2
  152. return 0;
  153. }
  154. void SetVal(CPerson* pPerson, short sVal)
  155. {
  156. }
  157. } givename_targetdist;
  158. // Availability of Popout pylon
  159. class CLogTabVar_PopoutAvailable : CLogTabVar<CPerson*>
  160. {
  161. public:
  162. CLogTabVar_PopoutAvailable()
  163. {
  164. m_pszName = "POPOUT_AVAIL";
  165. m_sMaxVal = 1;
  166. m_bSettable = false;
  167. m_sOutputWidth = 13;
  168. // This var is number-based, so turn off string stuff
  169. static char* ms_sz[] = {"false", "true"};
  170. m_sNumStrings = 2;
  171. m_papszStrings = ms_sz;
  172. }
  173. short GetVal(CPerson* pPerson)
  174. {
  175. pPerson->Logic_PylonDetect();
  176. return pPerson->m_bPylonPopoutAvailable;
  177. }
  178. void SetVal(CPerson* pPerson, short sVal)
  179. {
  180. }
  181. } givename_popoutavailable;
  182. // Availability of Run and Shoot pylon
  183. class CLogTabVar_RunShootAvailable : CLogTabVar<CPerson*>
  184. {
  185. public:
  186. CLogTabVar_RunShootAvailable()
  187. {
  188. m_pszName = "RUNSHOOT_AVAIL";
  189. m_sMaxVal = 1;
  190. m_bSettable = false;
  191. m_sOutputWidth = 13;
  192. // This var is number-based, so turn off string stuff
  193. static char* ms_sz[] = {"false", "true"};
  194. m_sNumStrings = 2;
  195. m_papszStrings = ms_sz;
  196. }
  197. short GetVal(CPerson* pPerson)
  198. {
  199. pPerson->Logic_PylonDetect();
  200. return pPerson->m_bPylonRunShootAvailable;
  201. }
  202. void SetVal(CPerson* pPerson, short sVal)
  203. {
  204. }
  205. } givename_runshootavailable;
  206. // Availability of Safety pylon
  207. class CLogTabVar_SafetyAvailable : CLogTabVar<CPerson*>
  208. {
  209. public:
  210. CLogTabVar_SafetyAvailable()
  211. {
  212. m_pszName = "SAFETY_AVAIL";
  213. m_sMaxVal = 1;
  214. m_bSettable = false;
  215. m_sOutputWidth = 13;
  216. // This var is number-based, so turn off string stuff
  217. static char* ms_sz[] = {"false", "true"};
  218. m_sNumStrings = 2;
  219. m_papszStrings = ms_sz;
  220. }
  221. short GetVal(CPerson* pPerson)
  222. {
  223. pPerson->Logic_PylonDetect();
  224. return pPerson->m_bPylonSafeAvailable;
  225. }
  226. void SetVal(CPerson* pPerson, short sVal)
  227. {
  228. }
  229. } givename_safetyavailable;
  230. // Availability of Pylon
  231. class CLogTabVar_PylonAvailable : CLogTabVar<CPerson*>
  232. {
  233. public:
  234. CLogTabVar_PylonAvailable()
  235. {
  236. m_pszName = "PYLON_AVAIL";
  237. m_sMaxVal = 3;
  238. m_bSettable = false;
  239. m_sOutputWidth = 13;
  240. // This var is number-based, so turn off string stuff
  241. static char* ms_sz[] = {"none", "popout", "runshoot", "safety"};
  242. m_sNumStrings = 4;
  243. m_papszStrings = ms_sz;
  244. }
  245. short GetVal(CPerson* pPerson)
  246. {
  247. short sResult = 0;
  248. pPerson->Logic_PylonDetect();
  249. if (pPerson->m_bPylonPopoutAvailable)
  250. {
  251. sResult = 1;
  252. }
  253. else
  254. {
  255. if (pPerson->m_bPylonRunShootAvailable)
  256. {
  257. sResult = 2;
  258. }
  259. else
  260. {
  261. if (pPerson->m_bPylonSafeAvailable)
  262. sResult = 3;
  263. }
  264. }
  265. return sResult;
  266. }
  267. void SetVal(CPerson* pPerson, short sVal)
  268. {
  269. }
  270. } givename_pylonavailable;
  271. // The this character's health
  272. class CLogTabVar_MyHealth : CLogTabVar<CPerson*>
  273. {
  274. public:
  275. CLogTabVar_MyHealth()
  276. {
  277. m_pszName = "MY_HEALTH";
  278. m_sMaxVal = 2;
  279. m_bSettable = false;
  280. m_sOutputWidth = 13;
  281. // This var is number-based, so turn off string stuff
  282. static char* ms_sz[] = {"low", "med", "high"};
  283. m_sNumStrings = 3;
  284. m_papszStrings = ms_sz;
  285. }
  286. short GetVal(CPerson* pPerson)
  287. {
  288. return pPerson->m_stockpile.m_sHitPoints / 34;
  289. }
  290. void SetVal(CPerson* pPerson, short sVal)
  291. {
  292. }
  293. } givename_myhealth;
  294. // The target CDude's health
  295. class CLogTabVar_DudeHealth : CLogTabVar<CPerson*>
  296. {
  297. public:
  298. CLogTabVar_DudeHealth()
  299. {
  300. m_pszName = "DUDE_HEALTH";
  301. m_sMaxVal = 3;
  302. m_bSettable = false;
  303. m_sOutputWidth = 13;
  304. // This var is number-based, so turn off string stuff
  305. static char* ms_sz[] = {"dead", "low", "med", "high"};
  306. m_sNumStrings = 4;
  307. m_papszStrings = ms_sz;
  308. }
  309. short GetVal(CPerson* pPerson)
  310. {
  311. short sResult = 0;
  312. if (pPerson->SelectDude() == SUCCESS)
  313. {
  314. CDude* pdude;
  315. if (pPerson->m_pRealm->m_idbank.GetThingByID((CThing**)&pdude, pPerson->m_idDude) == 0)
  316. {
  317. short sHitPoints = pdude->GetHealth();
  318. if (sHitPoints > 80)
  319. {
  320. sResult = 3;
  321. }
  322. else
  323. {
  324. if (sHitPoints > 40)
  325. sResult = 2;
  326. else
  327. sResult = 1;
  328. }
  329. }
  330. }
  331. return sResult;
  332. }
  333. void SetVal(CPerson* pPerson, short sVal)
  334. {
  335. }
  336. } givename_dudehealth;
  337. // Is the pylon area being triggered right now?
  338. class CLogTabVar_IsTriggered : CLogTabVar<CPerson*>
  339. {
  340. public:
  341. CLogTabVar_IsTriggered()
  342. {
  343. m_pszName = "IS_TRIGGERED";
  344. m_sMaxVal = 1;
  345. m_bSettable = false;
  346. m_sOutputWidth = 13;
  347. // This var is number-based, so turn off string stuff
  348. static char* ms_sz[] = {"false", "true"};
  349. m_sNumStrings = 2;
  350. m_papszStrings = ms_sz;
  351. }
  352. short GetVal(CPerson* pPerson)
  353. {
  354. return (pPerson->m_pPylonStart != NULL && pPerson->m_pPylonStart->Triggered());
  355. }
  356. void SetVal(CPerson* pPerson, short sVal)
  357. {
  358. }
  359. } givename_istriggered;
  360. // This is the first high level state variable available to the logic table
  361. class CLogTabVar_UserState1 : CLogTabVar<CPerson*>
  362. {
  363. public:
  364. CLogTabVar_UserState1()
  365. {
  366. m_pszName = "USER1";
  367. m_sMaxVal = 32767;
  368. m_bSettable = true;
  369. m_sOutputWidth = 5;
  370. // Feel free to add as many states as you need, but remember that the
  371. // WHOLE table assumes only ONE of these varables right now
  372. static char* ms_sz[] = {"default","active"};
  373. m_sNumStrings = 2;
  374. m_papszStrings = ms_sz;
  375. }
  376. short GetVal(CPerson* pPerson)
  377. {
  378. return pPerson->m_sUserState1;
  379. }
  380. void SetVal(CPerson* pPerson, short sVal)
  381. {
  382. pPerson->m_sUserState1 = sVal;
  383. }
  384. } givename_userstate1;
  385. // Did the enemy just get shot?
  386. class CLogTabVar_RecentlyShot : CLogTabVar<CPerson*>
  387. {
  388. public:
  389. CLogTabVar_RecentlyShot()
  390. {
  391. m_pszName = "RECENTLY_SHOT";
  392. m_sMaxVal = 1;
  393. m_bSettable = false;
  394. m_sOutputWidth = 13;
  395. // This var is number-based, so turn off string stuff
  396. static char* ms_sz[] = {"false", "true"};
  397. m_sNumStrings = 2;
  398. m_papszStrings = ms_sz;
  399. }
  400. short GetVal(CPerson* pPerson)
  401. {
  402. return (pPerson->m_pRealm->m_time.GetGameTime() < pPerson->m_lShotTimeout);
  403. }
  404. void SetVal(CPerson* pPerson, short sVal)
  405. {
  406. }
  407. } givename_recentlyshot;
  408. // Did the anamy get stuck on terrain?
  409. class CLogTabVar_RecentlyStuck : CLogTabVar<CPerson*>
  410. {
  411. public:
  412. CLogTabVar_RecentlyStuck()
  413. {
  414. m_pszName = "RECENTLY_STUCK";
  415. m_sMaxVal = 1;
  416. m_bSettable = true;
  417. m_sOutputWidth = 14;
  418. // This var is a bool
  419. static char* ms_sz[] = {"false", "true"};
  420. m_sNumStrings = 2;
  421. m_papszStrings = ms_sz;
  422. }
  423. short GetVal(CPerson* pPerson)
  424. {
  425. return (pPerson->m_pRealm->m_time.GetGameTime() < pPerson->m_lStuckTimeout);
  426. }
  427. void SetVal(CPerson* pPerson, short sVal)
  428. {
  429. // Set to false
  430. if (sVal == 0)
  431. pPerson->m_lStuckTimeout = pPerson->m_pRealm->m_time.GetGameTime();
  432. // Set to true
  433. else
  434. pPerson->m_lStuckTimeout = pPerson->m_pRealm->m_time.GetGameTime() + pPerson->ms_lStuckRecoveryTime;
  435. }
  436. } givename_recentlystuck;
  437. // Check to see if panic has begun
  438. class CLogTabVar_IsPanic : CLogTabVar<CPerson*>
  439. {
  440. public:
  441. CLogTabVar_IsPanic()
  442. {
  443. m_pszName = "IS_PANIC";
  444. m_sMaxVal = 1;
  445. m_bSettable = false;
  446. m_sOutputWidth = 8;
  447. // This var is true/false
  448. static char* ms_sz[] = {"false", "true"};
  449. m_sNumStrings = 2;
  450. m_papszStrings = ms_sz;
  451. }
  452. short GetVal(CPerson* pPerson)
  453. {
  454. return pPerson->m_bPanic;
  455. }
  456. void SetVal(CPerson* pPerson, short sVal)
  457. {
  458. }
  459. } givename_ispanic;
  460. // Check to see if someone yelled for help in your area
  461. class CLogTabVar_HelpCall : CLogTabVar<CPerson*>
  462. {
  463. public:
  464. CLogTabVar_HelpCall()
  465. {
  466. m_pszName = "HELPCALL";
  467. m_sMaxVal = 1;
  468. m_bSettable = false;
  469. m_sOutputWidth = 8;
  470. // This var is true/false
  471. static char* ms_sz[] = {"false", "true"};
  472. m_sNumStrings = 2;
  473. m_papszStrings = ms_sz;
  474. }
  475. short GetVal(CPerson* pPerson)
  476. {
  477. if (pPerson->m_pRealm->m_time.GetGameTime() < pPerson->m_lLastHelpCallTime + pPerson->ms_lHelpTimeout && pPerson->m_lLastHelpCallTime > 0)
  478. return 1;
  479. else
  480. return 0;
  481. }
  482. void SetVal(CPerson* pPerson, short sVal)
  483. {
  484. }
  485. } givename_helpcall;
  486. // This is the first high level state variable available to the logic table
  487. class CLogTabVar_UserGlobal : CLogTabVar<CPerson*>
  488. {
  489. public:
  490. CLogTabVar_UserGlobal()
  491. {
  492. m_pszName = "USER_GLOBAL";
  493. m_sMaxVal = 32767;
  494. m_bSettable = true;
  495. m_sOutputWidth = 5;
  496. // Feel free to add as many states as you need, but remember that the
  497. // WHOLE table assumes only ONE of these varables right now
  498. static char* ms_sz[] = {"normal","attack"};
  499. m_sNumStrings = 2;
  500. m_papszStrings = ms_sz;
  501. }
  502. short GetVal(CPerson* pPerson)
  503. {
  504. return pPerson->ms_sLogTabUserGlobal;
  505. }
  506. void SetVal(CPerson* pPerson, short sVal)
  507. {
  508. pPerson->ms_sLogTabUserGlobal = sVal;
  509. }
  510. } givename_userglobal;
  511. ////////////////////////////////////////////////////////////////////////////////
  512. // EOF
  513. ////////////////////////////////////////////////////////////////////////////////