You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.2KB

  1. /* ---------------------------------------------------------------------------|
  2. *
  3. * Distributed under the CC0 public domain license.
  4. * By Alison G. Watson. Attribution is encouraged, though not required.
  5. * See licenses/cc0.txt for more information.
  6. *
  7. * ---------------------------------------------------------------------------|
  8. *
  9. * Player shop handling.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "common.h"
  14. #include "p_player.h"
  15. /* Types ------------------------------------------------------------------- */
  16. struct shopitem
  17. {
  18. anonymous struct shopdef shopdef;
  19. i32 pclass;
  20. i32 count;
  21. str classname;
  22. bool weapon;
  23. };
  24. /* Static Objects ---------------------------------------------------------- */
  25. static struct shopitem shopitems[] = {
  26. /* {{"Name-----------", "BIP------------", Cost---}, Class, Cnt-, "Class---------------", [Flags]}, */
  27. {{s"RocketAmmo", snil, 9000}, gA, 5, sOBJ "RocketAmmo"},
  28. {{s"PlasmaAmmo", snil, 75750}, gA, 1000, sOBJ "PlasmaAmmo"},
  29. {{s"ChargeFist", s"ChargeFist", 100000}, pM, 1, sOBJ "ChargeFist", true},
  30. {{s"Revolver", s"Revolver", 500000}, pM, 1, sOBJ "Revolver", true},
  31. {{s"LazShotgun", s"LazShotgun", 1800000}, pM, 1, sOBJ "LazShotgun", true},
  32. {{s"SniperRifle", s"SniperRifle", 1800000}, pM, 1, sOBJ "SniperRifle", true},
  33. {{s"MissileLauncher", s"MissileLauncher", 2500000}, gO, 1, sOBJ "MissileLauncher", true},
  34. {{s"PlasmaDiffuser", s"PlasmaDiffuser", 2500000}, gO, 1, sOBJ "PlasmaDiffuser", true},
  35. {{s"Allmap", snil, 100000}, gA, 1, s"Allmap"},
  36. {{s"Infrared", snil, 70000}, gA, 1, s"Infrared"},
  37. {{s"RadSuit", snil, 100000}, gA, 1, s"RadSuit"},
  38. };
  39. /* Static Functions -------------------------------------------------------- */
  40. static bool Shop_CanBuy(struct player *p, struct shopdef const *, void *item_)
  41. {
  42. struct shopitem *item = item_;
  43. i32 cur = InvNum(item->classname);
  44. i32 max = InvMax(item->classname);
  45. return max == 0 || cur < max;
  46. }
  47. static void Shop_Buy(struct player *p, struct shopdef const *, void *item_)
  48. {
  49. struct shopitem *item = item_;
  50. p->itemsbought++;
  51. InvGive(item->classname, item->count);
  52. }
  53. static bool Shop_Give(struct player *p, struct shopdef const *, void *item_, i32 tid)
  54. {
  55. struct shopitem *item = item_;
  56. p->itemsbought++;
  57. if(item->weapon) {
  58. PtrInvGive(p->tid, item->classname, item->count);
  59. return false;
  60. } else {
  61. PtrInvGive(tid, item->classname, item->count);
  62. return true;
  63. }
  64. }
  65. /* Extern Functions -------------------------------------------------------- */
  66. void Shop_MInit(void)
  67. {
  68. for(i32 i = 0; i < countof(shopitems); i++)
  69. {
  70. struct shopitem *info = &shopitems[i];
  71. info->ShopBuy = Shop_Buy;
  72. info->ShopCanBuy = Shop_CanBuy;
  73. info->ShopGive = Shop_Give;
  74. }
  75. }
  76. void P_CBI_TabShop(struct gui_state *g, struct player *p)
  77. {
  78. i32 nitems = 0;
  79. for(i32 i = 0; i < countof(shopitems); i++) {
  80. if(shopitems[i].pclass & p->pclass)
  81. nitems++;
  82. }
  83. G_ScrBeg(g, &CBIState(g)->shopscr, 15, 36, gui_p.btnlist.w, 186, gui_p.btnlist.h * nitems);
  84. for(i32 i = 0, y = 0; i < countof(shopitems); i++)
  85. {
  86. if(G_ScrOcc(g, &CBIState(g)->shopscr, y, gui_p.btnlistsel.h) || !(shopitems[i].pclass & p->pclass))
  87. continue;
  88. cstr name = LanguageC(LANG "SHOP_TITLE_%S", shopitems[i].name);
  89. i32 *shopsel = &CBIState(g)->shopsel;
  90. if(G_Button_HId(g, i, name, 0, y, i == *shopsel, Pre(btnlistsel)))
  91. *shopsel = i;
  92. y += gui_p.btnlistsel.h;
  93. }
  94. G_ScrEnd(g, &CBIState(g)->shopscr);
  95. struct shopitem *item = &shopitems[CBIState(g)->shopsel];
  96. SetClipW(111, 30, 184, 150, 184);
  97. PrintTextFmt("%s %s\Cnscr", LC(LANG "COST"), scoresep(P_Shop_Cost(p, &item->shopdef)));
  98. PrintText(s_smallfnt, g->defcr, 111,1, 30,1);
  99. PrintText_str(Language(LANG "SHOP_DESCR_%S", item->name), s_smallfnt, g->defcr, 111,1, 40,1);
  100. ClearClip();
  101. if(G_Button(g, LC(LANG "BUY"), 259, 170, !P_Shop_CanBuy(p, &item->shopdef, item), .fill = {&CBIState(g)->buyfill, p->getCVarI(sc_gui_buyfiller)}))
  102. P_Shop_Buy(p, &item->shopdef, item, LANG "SHOP_TITLE_%S", false);
  103. }
  104. /* EOF */