Açıklama Yok

overworld.c 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <npc.h>
  31. /* === DEFINES === */
  32. #define OW_REPLACE_VAR 0x500A
  33. #define OW_REPLACE_TO_VAR 0x500B
  34. #define MAX_NPC_TABLES 4
  35. /* === PROTOTYPES === */
  36. /**
  37. * @brief get the npc type struct by given 16 bit npc id
  38. * @param npc_id short npc id
  39. * @return pointer to corresponding npc_type structure
  40. */
  41. struct npc_type *npc_get_type(u16 npc_id);
  42. /* === EXTERN STATICS ===*/
  43. extern struct npc_type **ow_main_table;
  44. extern struct npc_type **ow_second_table;
  45. extern struct npc_type **ow_third_table;
  46. extern struct npc_type **ow_fourth_table;
  47. /* === IMPLEMENTATIONS === */
  48. struct npc_type *npc_get_type(u16 npc_id)
  49. {
  50. /* Not possible in a global scope because of gcc cow magic */
  51. struct npc_type **npc_tables[MAX_NPC_TABLES] = {ow_main_table, ow_second_table, ow_third_table, ow_fourth_table};
  52. //struct npc_type** npc_tables[] = {ow_main_table, ow_second_table, ow_third_table};
  53. u8 table_id = npc_id >> 8;
  54. if (table_id > (MAX_NPC_TABLES -1))
  55. npc_id = (u8)npc_id;
  56. u16 replace_ow = var_get(OW_REPLACE_VAR);
  57. if (replace_ow > 0 && replace_ow - 1 == npc_id)
  58. {
  59. npc_id = var_get(OW_REPLACE_TO_VAR);
  60. }
  61. u8 table = (npc_id >> 8);
  62. return (npc_tables[table][npc_id & 0xFF]);
  63. }