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.

2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
3 年之前
3 年之前
2 年之前
3 年之前
2 年之前
2 年之前
3 年之前
2 年之前
2 年之前
3 年之前
3 年之前
3 年之前
3 年之前
2 年之前
3 年之前
3 年之前
2 年之前
3 年之前
3 年之前
2 年之前
2 年之前
2 年之前
2 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. * Magic upgrade.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "u_common.h"
  14. #include "w_world.h"
  15. #define UData p->upgrdata.magic
  16. /* Types ------------------------------------------------------------------- */
  17. struct magic_info {
  18. i32 st;
  19. i32 x, y;
  20. cstr name;
  21. };
  22. /* Static Objects ---------------------------------------------------------- */
  23. static struct magic_info const minf[] = {
  24. {-1, 130, 180, "Blade" },
  25. {-1, 60, 140, "Delear" },
  26. {cupg_c_slot3spell, 60, 60, "Feuer" },
  27. {cupg_c_slot4spell, 130, 10, "Rend" },
  28. {cupg_c_slot5spell, 205, 60, "Hulgyon" },
  29. {cupg_c_slot6spell, 205, 140, "StarShot"},
  30. {cupg_c_slot7spell, 130, 100, "Cercle" },
  31. };
  32. /* Static Functions -------------------------------------------------------- */
  33. script
  34. static void GiveMagic(struct magic_info const *m)
  35. {
  36. ACS_SetWeapon(StrParam(OBJ "%s", m->name));
  37. }
  38. script
  39. static void UpdateMagicUI(struct player *p, struct upgrade *upgr)
  40. {
  41. struct gui_state *g = &UData.gst;
  42. G_Begin(g, 320, 240);
  43. G_UpdateState(g, p);
  44. PrintSprite(sp_UI_MagicSelectBack, 0,1, 0,1);
  45. bool any = false;
  46. for(i32 i = 0; i < countof(minf); i++)
  47. {
  48. struct magic_info const *m = &minf[i];
  49. if(m->st != -1 && !cbiupgr[m->st]) continue;
  50. char gfx[32] = ":UI:"; strcat(gfx, m->name);
  51. char hot[32] = ":UI:"; strcat(hot, m->name); strcat(hot, "Sel");
  52. struct gui_pre_btn pre = {
  53. .gfx = gfx,
  54. .hot = hot,
  55. .cdef = "d",
  56. .cact = "r",
  57. .chot = "k",
  58. .cdis = "m",
  59. .font = s"smallfnt",
  60. .snd = s"player/cbi/buttonpress",
  61. .external = true,
  62. .w = 64,
  63. .h = 64
  64. };
  65. char name[128]; LanguageCV(name, LANG "INFO_SHORT_%s", m->name);
  66. if(G_Button_FId(g, i + 1, name, m->x, m->y, .preset = &pre))
  67. GiveMagic(m);
  68. }
  69. G_End(g, gui_curs_outline);
  70. }
  71. script
  72. static void GivePlayerZ(i32 tid, struct player *p)
  73. {
  74. while(ACS_ThingCount(T_NONE, tid)) {
  75. SetMembI(tid, sm_UserZ, p->z);
  76. ACS_Delay(1);
  77. }
  78. }
  79. static void SetMagicUI(struct player *p, bool on)
  80. {
  81. if(p->dead) return;
  82. if(on)
  83. {
  84. UData.ui = true;
  85. p->semifrozen++;
  86. UData.gst.gfxprefix = ":UI:";
  87. UData.gst.cx = 320/2;
  88. UData.gst.cy = 240/2;
  89. G_Init(&UData.gst);
  90. }
  91. else if(!on && UData.ui)
  92. {
  93. if(UData.gst.hot) GiveMagic(&minf[UData.gst.hot - 1]);
  94. UData.ui = false;
  95. p->semifrozen--;
  96. fastmemset(&UData.gst, 0, sizeof UData.gst);
  97. }
  98. }
  99. /* Extern Functions -------------------------------------------------------- */
  100. script
  101. void Upgr_Magic_Update(struct player *p, struct upgrade *upgr)
  102. {
  103. k32 manaperc = p->mana / (k32)p->manamax;
  104. if(UData.manaperc < 1 && manaperc == 1)
  105. ACS_LocalAmbientSound(ss_player_manafull, 127);
  106. UData.manaperc = manaperc;
  107. if(p->buttons & BT_USER4 && !(p->old.buttons & BT_USER4))
  108. SetMagicUI(p, true);
  109. else if(!(p->buttons & BT_USER4) && p->old.buttons & BT_USER4)
  110. SetMagicUI(p, false);
  111. if(UData.ui)
  112. UpdateMagicUI(p, upgr);
  113. if(manaperc >= 0.7)
  114. for(i32 i = 0; i < 5 * manaperc; i++)
  115. {
  116. k32 dst = ACS_RandomFixed(32, 56);
  117. k32 ang = ACS_RandomFixed(0, 1);
  118. i32 tid = ACS_UniqueTID();
  119. i32 x = ACS_Cos(ang) * dst;
  120. i32 y = ACS_Sin(ang) * dst;
  121. i32 z = ACS_Random(8, 48);
  122. ACS_Spawn(so_ManaLeak, p->x + x, p->y + y, p->z + z, tid);
  123. SetMembI(tid, sm_UserX, x);
  124. SetMembI(tid, sm_UserY, y);
  125. SetPropK(tid, APROP_Alpha, manaperc / 2);
  126. PtrSet(tid, AAPTR_DEFAULT, AAPTR_MASTER, p->tid);
  127. GivePlayerZ(tid, p);
  128. }
  129. }
  130. void Upgr_Magic_Render(struct player *p, struct upgrade *upgr)
  131. {
  132. if(!p->hudenabled) return;
  133. i32 hprc = ceilk(min(UData.manaperc, 0.5) * 2 * 62);
  134. i32 fprc = ceilk(max(UData.manaperc - 0.5, 0.0) * 2 * 62);
  135. PrintSprite(sp_HUD_C_MagicIcon, 1,1, 213,2);
  136. PrintSprite(sp_HUD_C_BarSmall2, 1,1, 220,2);
  137. SetClip(2, 219-5, hprc, 5);
  138. PrintSprite(sp_HUD_C_ManaBar1, 2,1, 219,2);
  139. ClearClip();
  140. SetClip(2, 219-5, fprc, 5);
  141. PrintSprite(sp_HUD_C_ManaBar2, 2,1, 219,2);
  142. ClearClip();
  143. }
  144. /* Scripts ----------------------------------------------------------------- */
  145. script_str ext("ACS") addr(OBJ "SetMagicUI")
  146. void Sc_SetMagicUI(bool on)
  147. {
  148. with_player(LocalPlayer) SetMagicUI(p, on);
  149. }
  150. /* EOF */