|
5 | 5 | #include "modules/Designations.h"
|
6 | 6 | #include "modules/Maps.h"
|
7 | 7 | #include "modules/Materials.h"
|
| 8 | +#include "modules/Random.h" |
8 | 9 |
|
9 | 10 | #include "df/map_block.h"
|
10 | 11 | #include "df/map_block_column.h"
|
@@ -211,32 +212,31 @@ selectability selectablePlant(color_ostream& out, const df::plant_raw* plant, bo
|
211 | 212 | }
|
212 | 213 |
|
213 | 214 | // Formula for determination of the variance in plant growth maturation time, determined via disassembly.
|
214 |
| -// The x and y parameters are in tiles relative to the embark. |
215 |
| -bool ripe(int32_t x, int32_t y, int32_t start, int32_t end) { |
216 |
| - int32_t time = (((435522653 - (((y + 3) * x + 5) * ((y + 7) * y * 400181475 + 289700012))) & 0x3FFFFFFF) % 2000 + *cur_year_tick) % 403200; |
| 215 | +// The coordinates are relative to the embark region. |
| 216 | +bool ripe(int32_t x, int32_t y, int32_t z, int32_t start, int32_t end) { |
| 217 | + DFHack::Random::SplitmixRNG rng((world->map.region_x * 48 + x) + (world->map.region_y * 48 + y) * 10000 + (world->map.region_z + z) * 100000000); |
| 218 | + int32_t time = (rng.df_trandom(2000) + *cur_year_tick) % 403200; |
217 | 219 |
|
218 | 220 | return time >= start && (end == -1 || time <= end);
|
219 | 221 | }
|
220 | 222 |
|
221 |
| -// Looks in the picked growths vector to see if a matching growth has been marked as picked. |
222 |
| -bool picked(const df::plant* plant, int32_t growth_subtype) { |
223 |
| - df::world_data* world_data = world->world_data; |
224 |
| - df::world_site* site = df::world_site::find(plotinfo->site_id); |
225 |
| - int32_t pos_x = site->global_min_x + plant->pos.x / 48; |
226 |
| - int32_t pos_y = site->global_min_y + plant->pos.y / 48; |
227 |
| - size_t id = pos_x + pos_y * 16 * world_data->world_width; |
228 |
| - df::world_object_data* object_data = df::world_object_data::find(id); |
229 |
| - if (!object_data) { |
| 223 | +// Looks in the local creation zone's picked growths vector to see if a matching growth has been marked as picked. |
| 224 | +bool picked(const df::plant* plant, int32_t growth_subtype, int32_t growth_density) { |
| 225 | + int32_t pos_x = plant->pos.x / 48 + world->map.region_x; |
| 226 | + int32_t pos_y = plant->pos.y / 48 + world->map.region_y; |
| 227 | + size_t cz_id = pos_x + pos_y * 16 * world->world_data->world_width; |
| 228 | + auto cz = df::world_object_data::find(cz_id); |
| 229 | + if (!cz) { |
230 | 230 | return false;
|
231 | 231 | }
|
232 |
| - df::map_block_column* column = world->map.map_block_columns[(plant->pos.x / 16) * world->map.x_count_block + (plant->pos.y / 16)]; |
233 |
| - |
234 |
| - for (size_t i = 0; i < object_data->picked_growths.x.size(); i++) { |
235 |
| - if (object_data->picked_growths.x[i] == plant->pos.x && |
236 |
| - object_data->picked_growths.y[i] == plant->pos.y && |
237 |
| - object_data->picked_growths.z[i] - column->z_base == plant->pos.z && |
238 |
| - object_data->picked_growths.subtype[i] == growth_subtype && |
239 |
| - object_data->picked_growths.year[i] == *cur_year) { |
| 232 | + |
| 233 | + for (size_t i = 0; i < cz->picked_growths.x.size(); i++) { |
| 234 | + if (cz->picked_growths.x[i] == (plant->pos.x % 48) && |
| 235 | + cz->picked_growths.y[i] == (plant->pos.y % 48) && |
| 236 | + cz->picked_growths.z[i] == (plant->pos.z + world->map.region_z) && |
| 237 | + cz->picked_growths.density[i] >= growth_density && |
| 238 | + cz->picked_growths.subtype[i] == growth_subtype && |
| 239 | + cz->picked_growths.year[i] == *cur_year) { |
240 | 240 | return true;
|
241 | 241 | }
|
242 | 242 | }
|
@@ -310,8 +310,8 @@ bool designate(color_ostream& out, const df::plant* plant, bool farming) {
|
310 | 310 | }
|
311 | 311 |
|
312 | 312 | if ((!farming || seedSource) &&
|
313 |
| - ripe(plant->pos.x, plant->pos.y, plant_raw->growths[i]->timing_1, plant_raw->growths[i]->timing_2) && |
314 |
| - !picked(plant, i)) |
| 313 | + ripe(plant->pos.x, plant->pos.y, plant->pos.z, plant_raw->growths[i]->timing_1, plant_raw->growths[i]->timing_2) && |
| 314 | + !picked(plant, i, plant_raw->growths[i]->density)) |
315 | 315 | return Designations::markPlant(plant);
|
316 | 316 | }
|
317 | 317 |
|
|
0 commit comments