| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include <stdlib.h> |
| 35 |
#include <check.h> |
| 36 |
#include <global.h> |
| 37 |
#include <sproto.h> |
| 38 |
|
| 39 |
static void setup(void) { |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
static void teardown(void) { |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
#if 0 |
| 48 |
static mapstruct *get_random_map(mapstruct *map) { |
| 49 |
object *exit_ob; |
| 50 |
mapstruct *random; |
| 51 |
RMParms rp; |
| 52 |
char newmap_name[HUGE_BUF], *cp; |
| 53 |
static int reference_number = 0; |
| 54 |
int x, y; |
| 55 |
|
| 56 |
exit_ob = NULL; |
| 57 |
for (x = 0; x < MAP_WIDTH(map) && exit_ob == NULL; x++) { |
| 58 |
for (y = 0; y < MAP_HEIGHT(map) && exit_ob == NULL; y++) { |
| 59 |
for (exit_ob = GET_MAP_OB(map, x, y); exit_ob != NULL; exit_ob = exit_ob->above) |
| 60 |
if (exit_ob->type == EXIT && exit_ob->msg != NULL) |
| 61 |
break; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
if (!exit_ob) |
| 66 |
|
| 67 |
return NULL; |
| 68 |
|
| 69 |
|
| 70 |
memset(&rp, 0, sizeof(RMParms)); |
| 71 |
rp.Xsize = -1; |
| 72 |
rp.Ysize = -1; |
| 73 |
rp.region = get_region_by_map(exit_ob->map); |
| 74 |
if (exit_ob->msg) |
| 75 |
set_random_map_variable(&rp, exit_ob->msg); |
| 76 |
rp.origin_x = exit_ob->x; |
| 77 |
rp.origin_y = exit_ob->y; |
| 78 |
strcpy(rp.origin_map, map->path); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
if (rp.final_map[0]) { |
| 86 |
cp = strrchr(rp.final_map, '/'); |
| 87 |
if (!cp) |
| 88 |
cp = rp.final_map; |
| 89 |
} else { |
| 90 |
char buf[HUGE_BUF]; |
| 91 |
|
| 92 |
cp = strrchr(rp.origin_map, '/'); |
| 93 |
if (!cp) |
| 94 |
cp = rp.origin_map; |
| 95 |
|
| 96 |
snprintf(buf, sizeof(buf), "%s", cp); |
| 97 |
while (isdigit(buf[strlen(buf)-1])) |
| 98 |
buf[strlen(buf)-1] = 0; |
| 99 |
cp = buf; |
| 100 |
} |
| 101 |
snprintf(newmap_name, sizeof(newmap_name), "/random/%s%04d", cp+1, reference_number++); |
| 102 |
|
| 103 |
return generate_random_map(newmap_name, &rp, NULL); |
| 104 |
} |
| 105 |
|
| 106 |
static void do_run(void) { |
| 107 |
mapstruct *worldmap; |
| 108 |
mapstruct *random; |
| 109 |
mapstruct *old; |
| 110 |
int iteration, x, y, map; |
| 111 |
object *check; |
| 112 |
char path[150]; |
| 113 |
|
| 114 |
for (map = 1; map <= 3; map++) { |
| 115 |
snprintf(path, sizeof(path), "/whalingoutpost/underwaterdungeon/level%d", map); |
| 116 |
worldmap = ready_map_name(path, 0); |
| 117 |
fail_unless(worldmap != NULL, "Can't load %s", path); |
| 118 |
|
| 119 |
random = worldmap; |
| 120 |
old = NULL; |
| 121 |
iteration = 0; |
| 122 |
while (random != NULL) { |
| 123 |
random = get_random_map(random); |
| 124 |
if (!random) |
| 125 |
break; |
| 126 |
if (old) |
| 127 |
delete_map(old); |
| 128 |
old = random; |
| 129 |
iteration++; |
| 130 |
for (x = 0; x < MAP_WIDTH(random); x++) { |
| 131 |
for (y = 0; y < MAP_HEIGHT(random); y++) { |
| 132 |
for (check = GET_MAP_OB(random, x, y); check; check = check->above) { |
| 133 |
if (check->type == ROD && check->title && strcmp(check->title, "of Plenty") == 0) |
| 134 |
fail_unless(check->inv != NULL, "Horn has empty inventory!"); |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
fail_unless(iteration != 0, "did %d iterations", iteration); |
| 140 |
if (old) |
| 141 |
delete_map(old); |
| 142 |
} |
| 143 |
} |
| 144 |
#endif |
| 145 |
|
| 146 |
#if 0 |
| 147 |
static void do_run(void) { |
| 148 |
mapstruct *map, *overlay; |
| 149 |
int x, y, found = 0, test = 0; |
| 150 |
object *check; |
| 151 |
|
| 152 |
overlay = ready_map_name("../../rsc/bug_1727944_unique", MAP_PLAYER_UNIQUE); |
| 153 |
fail_unless(overlay != NULL, "Couldn't load unique map ../../rsc/bug_1727944_unique"); |
| 154 |
|
| 155 |
while (found == 0 && test < 10) { |
| 156 |
map = ready_map_name("../../rsc/bug_1727944", MAP_PLAYER_UNIQUE); |
| 157 |
fail_unless(map != NULL, "couldn't load map ../../rsc/bug_1727944"); |
| 158 |
|
| 159 |
for (x = 0; x < MAP_WIDTH(map); x++) { |
| 160 |
for (y = 0; y < MAP_HEIGHT(map); y++) { |
| 161 |
for (check = GET_MAP_OB(map, x, y); check; check = check->above) { |
| 162 |
if (check->type == ROD) { |
| 163 |
fail_unless(check->inv != NULL, "Horn has empty inventory!"); |
| 164 |
fail_unless(check->inv->below == NULL, "Horn has 2 items in inventory!"); |
| 165 |
if (check->title && strcmp(check->title, "of Plenty") == 0) { |
| 166 |
object_remove(check); |
| 167 |
object_insert_in_map_at(check, overlay, NULL, 0, 2, 3); |
| 168 |
found++; |
| 169 |
break; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
delete_map(map); |
| 176 |
test++; |
| 177 |
} |
| 178 |
save_map(overlay, SAVE_MODE_OVERLAY); |
| 179 |
delete_map(overlay); |
| 180 |
} |
| 181 |
#endif |
| 182 |
|
| 183 |
extern int artifact_init; |
| 184 |
extern int arch_init; |
| 185 |
|
| 186 |
|
| 187 |
extern const char *const spell_mapping[]; |
| 188 |
|
| 189 |
static void local_check_loaded_object(object *op) { |
| 190 |
int ip; |
| 191 |
|
| 192 |
if (artifact_init) |
| 193 |
|
| 194 |
return; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
if (op->arch && op->name != op->arch->clone.name && op->name_pl == op->arch->clone.name_pl) { |
| 206 |
if (op->name_pl) |
| 207 |
free_string(op->name_pl); |
| 208 |
op->name_pl = NULL; |
| 209 |
} |
| 210 |
if (!op->name_pl && op->name) |
| 211 |
op->name_pl = add_string(op->name); |
| 212 |
|
| 213 |
|
| 214 |
if (!(IS_WEAPON(op) && op->level > 0)) { |
| 215 |
set_materialname(op); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
if ((op->type == WEAPON || op->type == BOW) && arch_init) { |
| 223 |
if (!op->skill) { |
| 224 |
LOG(llevError, "Weapon %s lacks a skill.\n", op->name); |
| 225 |
} else if ((!strcmp(op->skill, "one handed weapons") && op->body_info[1] != -1) |
| 226 |
|| (!strcmp(op->skill, "two handed weapons") && op->body_info[1] != -2)) { |
| 227 |
LOG(llevError, "weapon %s arm usage does not match skill: %d, %s\n", |
| 228 |
op->name, op->body_info[1], op->skill); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
if ((op->type == WEAPON) |
| 237 |
|| (op->type == ARMOUR) |
| 238 |
|| (op->type == HELMET) |
| 239 |
|| (op->type == SHIELD) |
| 240 |
|| (op->type == RING) |
| 241 |
|| (op->type == BOOTS) |
| 242 |
|| (op->type == GLOVES) |
| 243 |
|| (op->type == AMULET) |
| 244 |
|| (op->type == GIRDLE) |
| 245 |
|| (op->type == BRACERS) |
| 246 |
|| (op->type == CLOAK)) { |
| 247 |
if (op->last_heal) { |
| 248 |
LOG(llevDebug, "Object %s still has last_heal set, not gen_sp_armour\n", op->name ? op->name : "NULL"); |
| 249 |
op->gen_sp_armour = op->last_heal; |
| 250 |
op->last_heal = 0; |
| 251 |
} |
| 252 |
ip = calc_item_power(op); |
| 253 |
|
| 254 |
if (!op->item_power && ip) { |
| 255 |
if (ip > 3) { |
| 256 |
LOG(llevDebug, "Object %s had no item power, using %d\n", op->name ? op->name : "NULL", ip); |
| 257 |
} |
| 258 |
op->item_power = ip; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
if (ip > 2*op->item_power && ip > (op->item_power+3)) { |
| 267 |
LOG(llevDebug, "Object %s seems to have too low item power? %d > %d\n", op->name ? op->name : "NULL", ip, op->item_power); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == FIREWALL || ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) |
| 272 |
&& !op->inv |
| 273 |
&& !arch_init) { |
| 274 |
object *tmp; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
tmp = create_archetype(spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]); |
| 280 |
object_insert_in_ob(tmp, op); |
| 281 |
op->randomitems = NULL; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !arch_init) { |
| 286 |
object *tmp; |
| 287 |
|
| 288 |
tmp = create_archetype_by_object_name(op->slaying); |
| 289 |
object_insert_in_ob(tmp, op); |
| 290 |
op->randomitems = NULL; |
| 291 |
|
| 292 |
op->value = op->arch->clone.value*op->inv->value; |
| 293 |
} |
| 294 |
|
| 295 |
if (QUERY_FLAG(op, FLAG_MONSTER)) { |
| 296 |
if (op->stats.hp > op->stats.maxhp) |
| 297 |
LOG(llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", op->name, op->stats.hp, op->stats.maxhp); |
| 298 |
} |
| 299 |
if ((QUERY_FLAG(op, FLAG_GENERATOR) && QUERY_FLAG(op, FLAG_CONTENT_ON_GEN)) |
| 300 |
|| op->type == CREATOR |
| 301 |
|| op->type == CONVERTER) { |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
object_set_flag_inv(op, FLAG_IS_A_TEMPLATE); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
if (arch_init == 0 && artifact_init == 0 && QUERY_FLAG(op, FLAG_MONSTER) && op->arch && !object_can_merge(op, &op->arch->clone)) { |
| 315 |
archetype *temp = get_archetype_struct(); |
| 316 |
|
| 317 |
temp->reference_count++; |
| 318 |
temp->name = add_string(op->arch->name); |
| 319 |
temp->tail_x = op->arch->tail_x; |
| 320 |
temp->tail_y = op->arch->tail_y; |
| 321 |
object_copy(op, &temp->clone); |
| 322 |
temp->clone.inv = NULL; |
| 323 |
temp->clone.env = NULL; |
| 324 |
temp->clone.x = 0; |
| 325 |
temp->clone.y = 0; |
| 326 |
temp->clone.map = NULL; |
| 327 |
if (FABS(temp->clone.speed) > MIN_ACTIVE_SPEED) { |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
temp->clone.speed = 0; |
| 335 |
object_update_speed(&temp->clone); |
| 336 |
temp->clone.speed = op->speed; |
| 337 |
} |
| 338 |
|
| 339 |
temp->more = op->arch->more; |
| 340 |
op->arch = temp; |
| 341 |
|
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
START_TEST(test_randommaps) { |
| 346 |
#if 0 |
| 347 |
int test; |
| 348 |
mapstruct *overlay; |
| 349 |
object *check; |
| 350 |
|
| 351 |
for (test = 0; test < 50; test++) |
| 352 |
do_run(); |
| 353 |
|
| 354 |
for (test = 0; test < 50; test++) { |
| 355 |
overlay = ready_map_name("../../rsc/bug_1727944_unique", MAP_PLAYER_UNIQUE); |
| 356 |
fail_unless(overlay != NULL, "Couldn't load unique map ../../rsc/bug_1727944_unique"); |
| 357 |
fail_unless(GET_MAP_OB(overlay, 2, 3) != NULL, "No item on spot 2,3?"); |
| 358 |
|
| 359 |
for (check = GET_MAP_OB(overlay, 2, 3)->above; check != NULL; check = check->above) { |
| 360 |
fail_unless(check->type == ROD, "Found a non horn?"); |
| 361 |
fail_unless(check->inv != NULL, "Horn without a spell!"); |
| 362 |
fail_unless(check->inv->below == NULL, "Horn with 2 items in inventory."); |
| 363 |
} |
| 364 |
save_map(overlay, SAVE_MODE_OVERLAY); |
| 365 |
delete_map(overlay); |
| 366 |
} |
| 367 |
#endif |
| 368 |
|
| 369 |
#if 0 |
| 370 |
int test; |
| 371 |
archetype *horn = find_archetype("horn"); |
| 372 |
fail_unless(horn != NULL, "couldn't find archetype horn."); |
| 373 |
archetype *horn2 = find_archetype("horn2"); |
| 374 |
fail_unless(horn2 != NULL, "couldn't find archetype horn2."); |
| 375 |
|
| 376 |
for (test = 0; test < 100000; test++) { |
| 377 |
object *check = arch_to_object(RANDOM()%2 ? horn : horn2); |
| 378 |
|
| 379 |
generate_artifact(check, RANDOM()%100); |
| 380 |
fail_unless(check->inv != NULL, "horn without inventory!"); |
| 381 |
} |
| 382 |
#endif |
| 383 |
|
| 384 |
int test, level, found = 0; |
| 385 |
object *the_chest, *check; |
| 386 |
mapstruct *map; |
| 387 |
treasurelist *tlist = find_treasurelist("uncommon_items"); |
| 388 |
fail_unless(tlist != NULL, "couldn't find treasure list uncommon_items"); |
| 389 |
|
| 390 |
for (test = 0; test < 10; test++) { |
| 391 |
for (level = 1; level < 120; level++) { |
| 392 |
map = get_empty_map(1, 1); |
| 393 |
fail_unless(map != NULL, "failed to get empty map"); |
| 394 |
map->difficulty = level; |
| 395 |
|
| 396 |
the_chest = create_archetype("chest"); |
| 397 |
fail_unless(the_chest != NULL, "failed to get chest"); |
| 398 |
the_chest->randomitems = tlist; |
| 399 |
the_chest->stats.hp = RANDOM()%100; |
| 400 |
object_insert_in_map_at(the_chest, map, NULL, 0, 0, 0); |
| 401 |
apply_auto_fix(map); |
| 402 |
the_chest = GET_MAP_OB(map, 0, 0); |
| 403 |
fail_unless(the_chest != NULL, "failed to recover chest?"); |
| 404 |
for (check = the_chest->inv; check; check = check->below) { |
| 405 |
if (check->type != ROD) |
| 406 |
continue; |
| 407 |
local_check_loaded_object(check); |
| 408 |
fail_unless(check->inv != NULL, "horn without inventory"); |
| 409 |
fail_unless(check->inv->below == NULL, "horn with 2 items"); |
| 410 |
fail_unless(check->randomitems == NULL, "horn with randomitems set"); |
| 411 |
found++; |
| 412 |
} |
| 413 |
delete_map(map); |
| 414 |
} |
| 415 |
} |
| 416 |
fail_unless(found > 100, "didn't find 100 horn but %d??", found); |
| 417 |
|
| 418 |
} |
| 419 |
END_TEST |
| 420 |
|
| 421 |
static Suite *bug_suite(void) { |
| 422 |
Suite *s = suite_create("bug"); |
| 423 |
TCase *tc_core = tcase_create("Core"); |
| 424 |
|
| 425 |
|
| 426 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 427 |
|
| 428 |
suite_add_tcase(s, tc_core); |
| 429 |
tcase_add_test(tc_core, test_randommaps); |
| 430 |
tcase_set_timeout(tc_core, 0); |
| 431 |
|
| 432 |
return s; |
| 433 |
} |
| 434 |
|
| 435 |
int main(void) { |
| 436 |
int nf; |
| 437 |
Suite *s = bug_suite(); |
| 438 |
SRunner *sr = srunner_create(s); |
| 439 |
|
| 440 |
srunner_set_fork_status(sr, CK_NOFORK); |
| 441 |
init(0, NULL); |
| 442 |
|
| 443 |
srunner_set_xml(sr, LOGDIR "/bugs/bugtrack/1727944.xml"); |
| 444 |
srunner_set_log(sr, LOGDIR "/bugs/bugtrack/1727944.out"); |
| 445 |
srunner_run_all(sr, CK_ENV); |
| 446 |
nf = srunner_ntests_failed(sr); |
| 447 |
srunner_free(sr); |
| 448 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 449 |
} |