Bez popisu

load_text_special.c 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 load_text_special.c
  24. * @author Sturmvogel
  25. * @date 05 Jan 2016
  26. * @brief special 0x69 0x6A
  27. *
  28. * Implements a new way to load text for more language compatability and code
  29. * interchangability.
  30. */
  31. /* === INCLUDE === */
  32. #include <types.h>
  33. #include <game_engine.h>
  34. #include <config.h>
  35. /* === STRUCTURES === */
  36. struct lt_point
  37. {
  38. u16 x;
  39. u16 y;
  40. };
  41. struct lt_warpdata
  42. {
  43. u8 bank;
  44. u8 map;
  45. u8 warpid;
  46. u8 unknown;
  47. u16 enter_x;
  48. u16 enter_y;
  49. };
  50. struct sav_struct
  51. {
  52. struct lt_point position;
  53. struct lt_warpdata location;
  54. };
  55. /* === PROTOTYPES === */
  56. /**
  57. * @brief load text according to bank, map and text_id
  58. */
  59. void sp_load_text_map();
  60. /**
  61. * @brief load text according to bank, map, person id and text_id
  62. */
  63. void sp_load_text_person();
  64. /* === GLOBALS === */
  65. extern struct sav_struct* sav_one;
  66. char* str_invalid_text_ref;
  67. char***** text_lookup_table;
  68. void** loadpointer = (void**)((0x03000EB0 + 0x64));
  69. /* === IMPLEMENTATIONS === */
  70. void sp_load_text_map()
  71. {
  72. u8 bank = sav_one->location.bank;
  73. u8 map = sav_one->location.map;
  74. for(int i = 0; i<=bank;++i)
  75. {
  76. if(text_lookup_table[i] == (char****)(0xDEADBEEF))
  77. {
  78. *loadpointer =str_invalid_text_ref;
  79. return;
  80. }
  81. }
  82. for(int i = 0; i<=map; ++i)
  83. {
  84. if(text_lookup_table[bank][i] == (char***)(0xDEADBEEF))
  85. {
  86. *loadpointer = str_invalid_text_ref;
  87. return;
  88. }
  89. }
  90. if(text_lookup_table[bank][map][0] == (char**)(0xDEADBEEF))
  91. {
  92. *loadpointer = str_invalid_text_ref;
  93. return;
  94. }
  95. u16 text_id = var_get(0x500C);
  96. for(int i = 0; i<= text_id; ++i)
  97. {
  98. if(text_lookup_table[bank][map][0][i] == (char*)(0xDEADBEEF))
  99. {
  100. *loadpointer = str_invalid_text_ref;
  101. return;
  102. }
  103. }
  104. *loadpointer = text_lookup_table[bank][map][0][text_id];
  105. return;
  106. }
  107. void sp_load_text_person()
  108. {
  109. u8 bank = sav_one->location.bank;
  110. u8 map = sav_one->location.map;
  111. for(int i = 0; i<= bank; ++i)
  112. {
  113. if(text_lookup_table[i] == (char****)(0xDEADBEEF))
  114. {
  115. *loadpointer = str_invalid_text_ref;
  116. return;
  117. }
  118. }
  119. for(int i = 0; i<= bank; ++i)
  120. {
  121. if(text_lookup_table[bank][i] == (char***) (0xDEADBEEF))
  122. {
  123. *loadpointer = str_invalid_text_ref;
  124. return;
  125. }
  126. }
  127. u16 person_id = var_get(0x800F); // LASTTALKED
  128. for(int i = 0; i<= person_id; ++i)
  129. {
  130. if(text_lookup_table[bank][map][i] == (char**) (0xDEADBEEF))
  131. {
  132. *loadpointer = str_invalid_text_ref;
  133. return;
  134. }
  135. }
  136. u16 text_id = var_get(0x500C); //TEXT_VAR
  137. for(int i = 0; i<= text_id; ++i)
  138. {
  139. if(text_lookup_table[bank][map][person_id][i] == (char*) (0xDEADBEEF))
  140. {
  141. *loadpointer = str_invalid_text_ref;
  142. return;
  143. }
  144. }
  145. *loadpointer = text_lookup_table[bank][map][person_id][text_id];
  146. return;
  147. }