暫無描述

overworld.c 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /****************************************************************************
  2. * Copyright (C) 2015-2016 by the SotS Team *
  3. * *
  4. * This file is part of Sovereign of the Skies. *
  5. * *
  6. * Sovereign of the Skies is free software: you can redistribute it *
  7. * and/or modify it *
  8. * under the terms of the GNU Lesser General Public License as published *
  9. * by the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version provided you include a copy of the *
  11. * licence and this header. *
  12. * *
  13. * Sovereign of the Skies is distributed in the hope that it will be *
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with Sovereign of the Skies. *
  20. * If not, see <http://www.gnu.org/licenses/>. *
  21. ****************************************************************************/
  22. /**
  23. * @file overworld.c
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Routines to work with the new overworld npc table
  27. */
  28. /* === INCLUDES === */
  29. #include <game_engine.h>
  30. /* === DEFINES === */
  31. #define OW_REPLACE_VAR 0x500A
  32. #define OW_REPLACE_TO_VAR 0x500B
  33. /* === STRUCTURES === */
  34. struct ow_point {
  35. u16 x;
  36. u16 y;
  37. };
  38. struct npc_type {
  39. u16 tiles_tag;
  40. u16 pal_num;
  41. u16 pal_tag_2;
  42. u16 field_6;
  43. struct ow_point pos_neg_center;
  44. u8 pal_slot_unk;
  45. u8 field_D;
  46. u16 pal_table;
  47. u32 oam;
  48. u32 field_14;
  49. u32 image_anims;
  50. u32 gfx_table;
  51. u32 rot_scale_anims;
  52. };
  53. /* === PROTOTYPES === */
  54. /**
  55. * @brief get the npc type struct by given 16 bit npc id
  56. * @param npc_id short npc id
  57. * @return pointer to corresponding npc_type structure
  58. */
  59. struct npc_type* npc_get_type(u16 npc_id);
  60. /* === EXTERN STATICS ===*/
  61. struct npc_type** ow_main_table;
  62. struct npc_type** ow_second_table;
  63. struct npc_type** ow_third_table;
  64. /* === IMPLEMENTATIONS === */
  65. struct npc_type* npc_get_type(u16 npc_id) {
  66. /* Not possible in a global scope because of gcc cow magic */
  67. struct npc_type** npc_tables[3] = {ow_main_table, ow_second_table, ow_third_table};
  68. //struct npc_type** npc_tables[] = {ow_main_table, ow_second_table, ow_third_table};
  69. u8 table_id = npc_id >> 8;
  70. if (table_id > 2)
  71. npc_id = (u8) npc_id;
  72. u16 replace_ow = var_get(OW_REPLACE_VAR);
  73. if (replace_ow > 0 && replace_ow - 1 == npc_id) {
  74. npc_id = var_get(OW_REPLACE_TO_VAR);
  75. }
  76. u8 table = (npc_id >> 8);
  77. return (npc_tables[table][npc_id & 0xFF]);
  78. }