Ei kuvausta

overworld.c 2.9KB

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