| 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 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
#include <stdlib.h> |
| 48 |
#include <check.h> |
| 49 |
|
| 50 |
#include <global.h> |
| 51 |
#include <sproto.h> |
| 52 |
|
| 53 |
#define TEST_MAP_SIZE 40 |
| 54 |
#define NUM_TICKS_TO_RUN 500 |
| 55 |
#define NUM_COMETS_TO_CAST 30 |
| 56 |
#define STARTING_HP 25000 |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#define HP_DELTA 10 |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
mapstruct *test_map; |
| 74 |
object *mon; |
| 75 |
|
| 76 |
static void setup(void) { |
| 77 |
object *mon1; |
| 78 |
int x, i; |
| 79 |
|
| 80 |
test_map = get_empty_map(TEST_MAP_SIZE, TEST_MAP_SIZE); |
| 81 |
|
| 82 |
mon = create_archetype("orc"); |
| 83 |
fail_unless(mon != NULL, "Unable to find orc object"); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
for (i = 0; i < NROFATTACKS; i++) |
| 90 |
mon->resist[i] = 95; |
| 91 |
mon->stats.hp = STARTING_HP; |
| 92 |
mon->stats.maxhp = STARTING_HP; |
| 93 |
mon->speed = 0.0; |
| 94 |
mon->speed_left = 0.0; |
| 95 |
SET_FLAG(mon, FLAG_STAND_STILL); |
| 96 |
object_update_speed(mon); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
for (x = 0; x < TEST_MAP_SIZE; x++) { |
| 106 |
mon1 = object_new(); |
| 107 |
object_copy(mon, mon1); |
| 108 |
object_insert_in_map_at(mon1, test_map, NULL, 0, x, TEST_MAP_SIZE/2); |
| 109 |
|
| 110 |
if (x != TEST_MAP_SIZE/2) { |
| 111 |
mon1 = object_new(); |
| 112 |
object_copy(mon, mon1); |
| 113 |
object_insert_in_map_at(mon1, test_map, NULL, 0, x, x); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
static void teardown(void) { |
| 120 |
free_map(test_map); |
| 121 |
} |
| 122 |
|
| 123 |
static void check_hp(const char *test, int hp_row[TEST_MAP_SIZE], int hp_diag[TEST_MAP_SIZE]) { |
| 124 |
object *our_mon; |
| 125 |
int x, diff; |
| 126 |
|
| 127 |
#ifdef PRINT_DEBUG_HP |
| 128 |
printf("\nDumping debug hp for test %s\n ", test); |
| 129 |
#endif |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
for (x = 0; x < TEST_MAP_SIZE; x++) { |
| 135 |
our_mon = GET_MAP_OB(test_map, x, TEST_MAP_SIZE/2); |
| 136 |
if (!our_mon) { |
| 137 |
fail("Monster destroyed at %d, %d\n", x, TEST_MAP_SIZE/2); |
| 138 |
continue; |
| 139 |
} |
| 140 |
fail_unless(mon->name == our_mon->name, "Could not find our monster on the space?"); |
| 141 |
|
| 142 |
#ifdef PRINT_DEBUG_HP |
| 143 |
printf("%d, ", our_mon->stats.hp); |
| 144 |
#else |
| 145 |
|
| 146 |
if (our_mon->stats.hp == hp_row[x]) { |
| 147 |
diff = 0; |
| 148 |
} else if (our_mon->stats.hp < hp_row[x]) { |
| 149 |
diff = 100-(STARTING_HP-hp_row[x])*100/((STARTING_HP-our_mon->stats.hp) ? (STARTING_HP-our_mon->stats.hp) : 1); |
| 150 |
} else { |
| 151 |
diff = -(100-(STARTING_HP-our_mon->stats.hp)*100/((STARTING_HP-hp_row[x]) ? (STARTING_HP-hp_row[x]) : 1)); |
| 152 |
} |
| 153 |
|
| 154 |
if (FABS(diff) > HP_DELTA) { |
| 155 |
fail("Mon (%d, %d) has hp out of range (%d != %d +/- %d, diff %d)\n", our_mon->x, our_mon->y, our_mon->stats.hp, hp_row[x], HP_DELTA, diff); |
| 156 |
} |
| 157 |
#endif |
| 158 |
} |
| 159 |
|
| 160 |
#ifdef PRINT_DEBUG_HP |
| 161 |
printf("\n\n"); |
| 162 |
#endif |
| 163 |
|
| 164 |
for (x = 0; x < TEST_MAP_SIZE; x++) { |
| 165 |
our_mon = GET_MAP_OB(test_map, x, x); |
| 166 |
if (!our_mon) { |
| 167 |
fprintf(stderr, "Monster destroyed at %d, %d\n", x, x); |
| 168 |
continue; |
| 169 |
} |
| 170 |
|
| 171 |
fail_unless(mon->name == our_mon->name, "Could not find our monster on the space?"); |
| 172 |
|
| 173 |
#ifdef PRINT_DEBUG_HP |
| 174 |
printf("%d, ", our_mon->stats.hp); |
| 175 |
#else |
| 176 |
if (our_mon->stats.hp == hp_diag[x]) { |
| 177 |
diff = 0; |
| 178 |
} else if (our_mon->stats.hp < hp_diag[x]) { |
| 179 |
diff = 100-(STARTING_HP-hp_diag[x])*100/((STARTING_HP-our_mon->stats.hp) ? (STARTING_HP-our_mon->stats.hp) : 1); |
| 180 |
} else { |
| 181 |
diff = -(100-(STARTING_HP-our_mon->stats.hp)*100/((STARTING_HP-hp_diag[x]) ? (STARTING_HP-hp_diag[x]) : 1)); |
| 182 |
} |
| 183 |
|
| 184 |
if (FABS(diff) > HP_DELTA) { |
| 185 |
fail("Mon (%d, %d) has hp out of range (%d != %d +/- %d, diff %d)\n", our_mon->x, our_mon->y, our_mon->stats.hp, hp_diag[x], HP_DELTA, diff); |
| 186 |
} |
| 187 |
#endif |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
START_TEST(cast_one_comet) { |
| 192 |
int hp_row[TEST_MAP_SIZE] = {25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000, 24924, 24920, 24916, 24912, 24908, 24904, 24900, 24896, 24892, 24888, 24884, 24880, 24869, 24880, 24884, 24888, 24892, 24896, 24900, 24904, 24908, 24912, 24916, 24920, 24924, 25000, 25000, 25000, 25000, 25000, 25000, 25000 }, |
| 193 |
hp_diag[TEST_MAP_SIZE] = {25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000, 24924, 24920, 24916, 24912, 24908, 24904, 24900, 24896, 24892, 24888, 24884, 24880, 24869, 24880, 24884, 24888, 24892, 24896, 24900, 24904, 24908, 24912, 24916, 24920, 24924, 25000, 25000, 25000, 25000, 25000, 25000, 25000 }; |
| 194 |
object *comet, *rod; |
| 195 |
int tick; |
| 196 |
|
| 197 |
rod = create_archetype("rod_heavy"); |
| 198 |
rod->level = 100; |
| 199 |
comet = create_archetype("spell_comet"); |
| 200 |
object_insert_in_ob(comet, rod); |
| 201 |
|
| 202 |
object_insert_in_map_at(rod, test_map, NULL, 0, TEST_MAP_SIZE/2, TEST_MAP_SIZE-1); |
| 203 |
|
| 204 |
cast_spell(rod, rod, 1, rod->inv, NULL); |
| 205 |
for (tick = 0; tick < NUM_TICKS_TO_RUN; tick++) { |
| 206 |
process_events(); |
| 207 |
} |
| 208 |
|
| 209 |
check_hp("cast_one_comet", hp_row, hp_diag); |
| 210 |
} |
| 211 |
END_TEST |
| 212 |
|
| 213 |
START_TEST(cast_random_comet) { |
| 214 |
object *comet, *rod; |
| 215 |
int tick, num_cast = 0; |
| 216 |
int hp_row[TEST_MAP_SIZE] = {23756, 23617, 23516, 23428, 23397, 23291, 23203, 23097, 23014, 22875, 22801, 22782, 22706, 22707, 22620, 22645, 22646, 22595, 22705, 22773, 22809, 22835, 22975, 23098, 23239, 23346, 23462, 23597, 23627, 23675, 23786, 23888, 24001, 24119, 24206, 24306, 24336, 24455, 24565, 24649 }, |
| 217 |
hp_diag[TEST_MAP_SIZE] = {25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000, 23515, 23351, 23177, 23097, 22946, 22931, 22763, 22706, 22678, 22658, 22728, 22812, 22809, 22712, 22728, 22741, 22726, 22833, 22862, 22967, 23014, 23009, 23167, 23267, 23367, 23459, 23596, 23713, 23750, 23879, 24026, 24160 }; |
| 218 |
|
| 219 |
rod = create_archetype("rod_heavy"); |
| 220 |
rod->level = 100; |
| 221 |
comet = create_archetype("spell_comet"); |
| 222 |
object_insert_in_ob(comet, rod); |
| 223 |
|
| 224 |
object_insert_in_map_at(rod, test_map, NULL, 0, TEST_MAP_SIZE/2, TEST_MAP_SIZE-1); |
| 225 |
|
| 226 |
for (tick = 0; tick < NUM_TICKS_TO_RUN; tick++) { |
| 227 |
if (num_cast < NUM_COMETS_TO_CAST && (tick%1) == 0) { |
| 228 |
object_remove(rod); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
object_insert_in_map_at(rod, test_map, NULL, 0, (tick*59)%37, TEST_MAP_SIZE-1); |
| 235 |
|
| 236 |
cast_spell(rod, rod, 1, rod->inv, NULL); |
| 237 |
num_cast++; |
| 238 |
} |
| 239 |
process_events(); |
| 240 |
} |
| 241 |
check_hp("cast_random_comet", hp_row, hp_diag); |
| 242 |
|
| 243 |
} |
| 244 |
END_TEST |
| 245 |
|
| 246 |
START_TEST(cast_bunch_comet) { |
| 247 |
object *comet, *rod; |
| 248 |
int tick, num_cast = 0; |
| 249 |
int hp_row[TEST_MAP_SIZE] = {25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000, 22355, 22262, 22115, 21966, 21837, 21684, 21554, 21424, 21268, 21137, 21006, 20875, 20534, 20875, 21006, 21137, 21268, 21424, 21554, 21684, 21837, 21966, 22115, 22262, 22355, 25000, 25000, 25000, 25000, 25000, 25000, 25000 }, |
| 250 |
hp_diag[TEST_MAP_SIZE] = {25000, 25000, 25000, 25000, 25000, 25000, 25000, 25000, 22355, 22262, 22115, 21966, 21837, 21684, 21554, 21424, 21268, 21137, 21006, 20875, 20534, 20875, 21006, 21137, 21268, 21424, 21554, 21684, 21837, 21966, 22115, 22262, 22355, 25000, 25000, 25000, 25000, 25000, 25000, 25000 }; |
| 251 |
|
| 252 |
rod = create_archetype("rod_heavy"); |
| 253 |
rod->level = 100; |
| 254 |
comet = create_archetype("spell_comet"); |
| 255 |
object_insert_in_ob(comet, rod); |
| 256 |
|
| 257 |
object_insert_in_map_at(rod, test_map, NULL, 0, TEST_MAP_SIZE/2, TEST_MAP_SIZE-1); |
| 258 |
|
| 259 |
for (tick = 0; tick < NUM_TICKS_TO_RUN; tick++) { |
| 260 |
if (num_cast < NUM_COMETS_TO_CAST && (tick%1) == 0) { |
| 261 |
cast_spell(rod, rod, 1, rod->inv, NULL); |
| 262 |
num_cast++; |
| 263 |
} |
| 264 |
process_events(); |
| 265 |
} |
| 266 |
check_hp("cast_bunch_comet", hp_row, hp_diag); |
| 267 |
|
| 268 |
} |
| 269 |
END_TEST |
| 270 |
|
| 271 |
static Suite *comet_suite(void) { |
| 272 |
Suite *s = suite_create("comet"); |
| 273 |
TCase *tc_core = tcase_create("Core"); |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
tcase_set_timeout(tc_core, 20); |
| 281 |
|
| 282 |
|
| 283 |
tcase_add_checked_fixture(tc_core, setup, teardown); |
| 284 |
|
| 285 |
suite_add_tcase(s, tc_core); |
| 286 |
tcase_add_test(tc_core, cast_one_comet); |
| 287 |
tcase_add_test(tc_core, cast_bunch_comet); |
| 288 |
tcase_add_test(tc_core, cast_random_comet); |
| 289 |
|
| 290 |
return s; |
| 291 |
} |
| 292 |
|
| 293 |
int main(void) { |
| 294 |
int nf; |
| 295 |
|
| 296 |
Suite *s = comet_suite(); |
| 297 |
SRunner *sr = srunner_create(s); |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
srunner_set_fork_status(sr, CK_NOFORK); |
| 304 |
|
| 305 |
|
| 306 |
init(0, NULL); |
| 307 |
|
| 308 |
srunner_set_xml(sr, LOGDIR "/unit/server/comet.xml"); |
| 309 |
srunner_set_log(sr, LOGDIR "/unit/server/comet.out"); |
| 310 |
srunner_run_all(sr, CK_ENV); |
| 311 |
nf = srunner_ntests_failed(sr); |
| 312 |
srunner_free(sr); |
| 313 |
fprintf(stderr, "Got %"FMT64U" supressions, %"FMT64U" spell merges, %"FMT64U" full tables\n", statistics.spell_suppressions, statistics.spell_merges, statistics.spell_hash_full); |
| 314 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 315 |
} |