prod_template.diff

Return to the initial folder
  1. # HG changeset patch
  2. # Parent 2aa3a7ed277765fe7cc083c7a2c6d16ed5bcfd9d
  3. Add: Production template for secondary industries
  4.  
  5. diff --git a/sprites/nml/defines.pnml b/sprites/nml/defines.pnml
  6. --- a/sprites/nml/defines.pnml
  7. +++ b/sprites/nml/defines.pnml
  8. @@ -1,3 +1,10 @@
  9. +/*
  10. + * This file is part of FIRS industry set.
  11. + * FIRS industry set is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
  12. + * FIRS industry set is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FIRS industry set. If not, see <http://www.gnu.org/licenses/>.
  14. + */
  15. +
  16.  #define SPRITE_TREE 1593
  17.  #define SPRITE_TREE_DEAD 1596
  18.  
  19. @@ -8,7 +15,32 @@
  20.  /* Persistant storage for industries */
  21.  #define store_produced_1      0
  22.  
  23. +/* persistant storage for secondary industries (template produce_secondary_C) */
  24.  #define var_waiting_cargo_1   13
  25.  #define var_waiting_cargo_2   14
  26.  
  27. -#define store_closure_counter 15
  28. \ No newline at end of file
  29. +/* persistant storage for secondary industries (template produce_secondary) */
  30. +//                                  0 // unused
  31. +
  32. +#define var_ratio_cargo_1           1 // output per 8 units input of cargo 1; can be made temporary
  33. +#define var_ratio_cargo_2           2 // output per 8 units input of cargo 2; can be made temporary
  34. +#define var_ratio_cargo_3           3 // output per 8 units input of cargo 3; can be made temporary
  35. +
  36. +#define var_leftover_cargo_1        4 // non-processed cargo 1
  37. +#define var_leftover_cargo_2        5 // non-processed cargo 2
  38. +#define var_leftover_cargo_3        6 // non-processed cargo 3
  39. +
  40. +#define var_input_cargo_1           7 // stores only last processed input; for debugging only
  41. +#define var_input_cargo_2           8 // stores only last processed input; for debugging only
  42. +#define var_input_cargo_3           9 // stores only last processed input; for debugging only
  43. +
  44. +#define var_date_received_1        10 // date of last cargo 1 delivered
  45. +#define var_date_received_2        11 // date of last cargo 2 delivered
  46. +#define var_date_received_3        12 // date of last cargo 3 delivered
  47. +#define var_production_span        13 // time to consider a cargo usable for production boost (not yet used)
  48. +
  49. +//                                 14 // unused
  50. +
  51. +// for all industries (?)
  52. +
  53. +#define store_closure_counter      15 
  54. \ No newline at end of file
  55. diff --git a/sprites/nml/templates/produce_secondary.pnml b/sprites/nml/templates/produce_secondary.pnml
  56. new file mode 100644
  57. --- /dev/null
  58. +++ b/sprites/nml/templates/produce_secondary.pnml
  59. @@ -0,0 +1,147 @@
  60. +/*
  61. + * This file is part of FIRS industry set.
  62. + * FIRS industry set is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
  63. + * FIRS industry set is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  64. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FIRS industry set. If not, see <http://www.gnu.org/licenses/>.
  65. + */
  66. +
  67. +/* Production template for secondary industries with equal output to all output cargos
  68. + *
  69. + * Delivery period to consider a cargo for production ratios is the the last var_production_span days
  70. + * 
  71. + * It accepts up to three input cargos and produes up to two output cargos
  72. + * It uses the following permanent storages:
  73. + *
  74. + * var_date_received_1, var_date_received_2, var_date_received_3
  75. + * var_input_cargo_1, var_input_cargo_2, var_input_cargo_3
  76. + * var_ratio_cargo_1, var_ratio_cargo_2, var_ratio_cargo_3
  77. + * var_production_by_cargo_1, var_production_by_cargo_2, var_production_by_cargo_3
  78. + * var_production_span
  79. + *
  80. + * Needed defines in the industry's pnml which uses this template.
  81. + * NUM_OUTPUT_CARGOS             number of output cargos
  82. + *
  83. + * The sum of the following should not exceed MAX_SUM_PROD_RATIO (see below):
  84. + * IND_PROD_RATIO_CARGO1         output per MAX_SUM_PROD_RATIO units input
  85. + * IND_PROD_RATIO_CARGO2         output per MAX_SUM_PROD_RATIO units input
  86. + * IND_PROD_RATIO_CARGO3         output per MAX_SUM_PROD_RATIO units input
  87. + *
  88. + * How cargos boost eachother (give in units of 1/MAX_SUM_PROD_RATIO)
  89. + * It should be noted that IND_PROD_RATIO_CARGO1 + IND_BOOST_21 + IND_BOOST_31 never should exceed MAX_SUM_PROD_RATIO
  90. + * and similar for the other two cargos
  91. + * IND_BOOST_12
  92. + * IND_BOOST_13
  93. + * IND_BOOST_21
  94. + * IND_BOOST_23
  95. + * IND_BOOST_31
  96. + * IND_BOOST_32
  97. + *
  98. + * IND_PRODUCTION_SPAN           time span which is considered for production ratios
  99. + *
  100. + */
  101. +
  102. +/ * granularity of production. That amount of input (per cargo) is needed in order to be processed */
  103. +#define MAX_SUM_PROD_RATIO 8
  104. +
  105. +/* Temporary variables used within this template */
  106. +#define var_received_timely_1       0
  107. +#define var_received_timely_2       1
  108. +#define var_received_timely_3       2
  109. +#define var_amount_input_cargo_1    4
  110. +#define var_amount_input_cargo_2    5
  111. +#define var_amount_input_cargo_3    6
  112. +#define var_production_by_cargo_1   7
  113. +#define var_production_by_cargo_2   8
  114. +#define var_production_by_cargo_3   9
  115. +#define var_output_cargo_1          10
  116. +#define var_output_cargo_2          11
  117. +
  118. +produce (IND_ID(simple_produce), waiting_cargo_1, waiting_cargo_2, waiting_cargo_3, LOAD_TEMP(var_output_cargo_1), LOAD_TEMP(var_output_cargo_2))
  119. +
  120. +switch (FEAT_INDUSTRIES, IND_ID(produce), 
  121. +			[
  122. +			/* Update the 'last delivery date' for the three input cargos */
  123. +			STORE_PERM( max(LOAD_PERM(var_date_received_1),(waiting_cargo_1 > 0) * current_date), var_date_received_1),
  124. +			STORE_PERM( max(LOAD_PERM(var_date_received_2),(waiting_cargo_2 > 0) * current_date), var_date_received_2),
  125. +			STORE_PERM( max(LOAD_PERM(var_date_received_3),(waiting_cargo_3 > 0) * current_date), var_date_received_3),
  126. +
  127. +			/* Store the delivered cargo permanently (for debugging purposes only */
  128. +			STORE_PERM( waiting_cargo_1, var_input_cargo_1),
  129. +			STORE_PERM( waiting_cargo_2, var_input_cargo_2),
  130. +			STORE_PERM( waiting_cargo_3, var_input_cargo_3),
  131. +
  132. +			/* Check whether the cargos were delivered within the time frame to be considered delivered concurrently */
  133. +			STORE_TEMP( (current_date - LOAD_PERM(var_date_received_1)) <= IND_PRODUCTION_SPAN, var_received_timely_1),
  134. +			STORE_TEMP( (current_date - LOAD_PERM(var_date_received_2)) <= IND_PRODUCTION_SPAN, var_received_timely_2),
  135. +			STORE_TEMP( (current_date - LOAD_PERM(var_date_received_3)) <= IND_PRODUCTION_SPAN, var_received_timely_3),
  136. +
  137. +			/* Calculate production ratios for the individual cargos */
  138. +			STORE_PERM( IND_PROD_RATIO_CARGO1 + 
  139. +			            LOAD_TEMP(var_received_timely_2) * IND_BOOST_21 +
  140. +			            LOAD_TEMP(var_received_timely_3) * IND_BOOST_31,
  141. +			    var_ratio_cargo_1
  142. +			),
  143. +			STORE_PERM( IND_PROD_RATIO_CARGO2 + 
  144. +			            LOAD_TEMP(var_received_timely_1) * IND_BOOST_12 +
  145. +			            LOAD_TEMP(var_received_timely_3) * IND_BOOST_32,
  146. +			    var_ratio_cargo_2
  147. +			),
  148. +			STORE_PERM( IND_PROD_RATIO_CARGO3 + 
  149. +			            LOAD_TEMP(var_received_timely_1) * IND_BOOST_13 +
  150. +			            LOAD_TEMP(var_received_timely_2) * IND_BOOST_23,
  151. +			    var_ratio_cargo_3
  152. +			),
  153. +
  154. +			/* Load the leftover cargo units which could not be processed during the last run and add current input cargo amounts */
  155. +			STORE_TEMP( waiting_cargo_1 + LOAD_PERM(var_leftover_cargo_1), var_amount_input_cargo_1),
  156. +			STORE_TEMP( waiting_cargo_2 + LOAD_PERM(var_leftover_cargo_1), var_amount_input_cargo_3),
  157. +			STORE_TEMP( waiting_cargo_3 + LOAD_PERM(var_leftover_cargo_1), var_amount_input_cargo_3),
  158. +			
  159. +			/* Calculate the production for input cargo 1 and store the remainder */
  160. +			STORE_TEMP( LOAD_TEMP(var_amount_input_cargo_1) * LOAD_PERM(var_ratio_cargo_1) / (MAX_SUM_PROD_RATIO * NUM_OUTPUT_CARGOS),
  161. +			    var_production_by_cargo_1
  162. +			),
  163. +			STORE_PERM( LOAD_TEMP(var_amount_input_cargo_1) * LOAD_PERM(var_ratio_cargo_1) % (MAX_SUM_PROD_RATIO * NUM_OUTPUT_CARGOS),
  164. +			    var_leftover_cargo_1
  165. +			)
  166. +			/* Calculate the production for input cargo 2 and store the remainder */
  167. +			STORE_TEMP( LOAD_TEMP(var_amount_input_cargo_2) * LOAD_PERM(var_ratio_cargo_2) / (MAX_SUM_PROD_RATIO * NUM_OUTPUT_CARGOS),
  168. +			    var_production_by_cargo_2
  169. +			),
  170. +			STORE_PERM( LOAD_TEMP(var_amount_input_cargo_2) * LOAD_PERM(var_ratio_cargo_2) % (MAX_SUM_PROD_RATIO * NUM_OUTPUT_CARGOS),
  171. +			    var_leftover_cargo_2
  172. +			)
  173. +			/* Calculate the production for input cargo 3 and store the remainder */
  174. +			STORE_TEMP( LOAD_TEMP(var_amount_input_cargo_3) * LOAD_PERM(var_ratio_cargo_3) / (MAX_SUM_PROD_RATIO * NUM_OUTPUT_CARGOS),
  175. +			    var_production_by_cargo_3
  176. +			),
  177. +			STORE_PERM( LOAD_TEMP(var_amount_input_cargo_3) * LOAD_PERM(var_ratio_cargo_3) % (MAX_SUM_PROD_RATIO * NUM_OUTPUT_CARGOS),
  178. +			    var_leftover_cargo_3
  179. +			)
  180. +			
  181. +			/* Calculate the production for output cargo 1 */
  182. +			STORE_TEMP( LOAD_TEMP(var_production_by_cargo_1) +
  183. +			            LOAD_TEMP(var_production_by_cargo_2) +
  184. +			            LOAD_TEMP(var_production_by_cargo_3),
  185. +			    var_output_cargo_1
  186. +			),
  187. +			/* If there's a 2nd output cargo, it is produced in equal amounts as the 1st output cargo */
  188. +			STORE_TEMP( LOAD_TEMP(var_output_cargo_1) * (NUM_OUTPUT_CARGOS > 1), var_output_cargo_2),
  189. +
  190. +			1
  191. +			] {
  192. +	IND_ID(simple_produce)
  193. +}
  194. +
  195. +#undef MAX_SUM_PROD_RATIO
  196. +#undef var_received_timely_1
  197. +#undef var_received_timely_2
  198. +#undef var_received_timely_3
  199. +#undef var_amount_input_cargo_1
  200. +#undef var_amount_input_cargo_2
  201. +#undef var_amount_input_cargo_3
  202. +#undef var_production_by_cargo_1
  203. +#undef var_production_by_cargo_2
  204. +#undef var_production_by_cargo_3
  205. +#undef var_output_cargo_1
  206. +#undef var_output_cargo_2
  207. diff --git a/sprites/nml/templates/undefs.pnml b/sprites/nml/templates/undefs.pnml
  208. --- a/sprites/nml/templates/undefs.pnml
  209. +++ b/sprites/nml/templates/undefs.pnml
  210. @@ -5,4 +5,19 @@
  211.   * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FIRS industry set. If not, see <http://www.gnu.org/licenses/>.
  212.   */
  213.  
  214. +// for each industry
  215.  #undef IND_ID
  216. +
  217. +// from secondary production template
  218. +#undef NUM_OUTPUT_CARGOS
  219. +#undef IND_PROD_RATIO_CARGO1
  220. +#undef IND_PROD_RATIO_CARGO2
  221. +#undef IND_PROD_RATIO_CARGO3
  222. +
  223. +#undef IND_BOOST_12
  224. +#undef IND_BOOST_13
  225. +#undef IND_BOOST_21
  226. +#undef IND_BOOST_23
  227. +#undef IND_BOOST_31
  228. +#undef IND_BOOST_32
  229. +
  230.  

Return to top