00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <global.h>
00034 #include <stdlib.h>
00035 #include <check.h>
00036 #include <loader.h>
00037 #include <toolkit_common.h>
00038 #include <sproto.h>
00039
00040 void setup(void) {
00041 }
00042
00043 void teardown(void) {
00044
00045 }
00046
00047 START_TEST(test_hit_player) {
00048 object *victim = NULL;
00049 object *hitter = NULL;
00050 object *floor = NULL;
00051 mapstruct *map = NULL;
00052 archetype *deplete = NULL;
00053 int test;
00054
00055 map = get_empty_map(5, 5);
00056 floor = create_archetype("battleground");
00057 fail_unless(floor != NULL, "can't find archetype battleground");
00058 insert_ob_in_map_at(floor, map, NULL, 0, 0, 0);
00059 floor = create_archetype("battleground");
00060 fail_unless(floor != NULL, "can't find archetype battleground");
00061 insert_ob_in_map_at(floor, map, NULL, 0, 1, 0);
00062
00063 deplete = find_archetype(ARCH_DEPLETION);
00064 fail_unless(deplete != NULL, "can't find archetype %s", ARCH_DEPLETION);
00065
00066 victim = create_archetype("kobold");
00067 fail_unless(victim != NULL, "couldn't create kobold");
00068 fail_unless(victim->inv == NULL, "kobold shouldn't have an inventory");
00069 victim->stats.hp = 5000;
00070 victim->stats.maxhp = 5000;
00071 victim->resist[ATNR_DEPLETE] = 100;
00072 victim->resist[ATNR_FIRE] = 100;
00073 insert_ob_in_map_at(victim, map, NULL, 0, 0, 0);
00074 hitter = create_archetype("sword");
00075 fail_unless(hitter != NULL, "couldn't create sword");
00076 hitter->attacktype = AT_DEPLETE|AT_FIRE;
00077 hitter->stats.dam = 100;
00078 hitter->map = map;
00079 insert_ob_in_map_at(hitter, map, NULL, 0, 1, 0);
00080
00081 fail_unless(present_arch_in_ob(deplete, victim) == NULL, "victim shouldn't be depleted before being attacked");
00082
00083 for (test = 0; test < 100; test++) {
00084 hit_player(victim, hitter->stats.dam, hitter, hitter->attacktype, 0);
00085 fail_unless(victim->stats.hp == victim->stats.maxhp, "victim should have %d hp and not %d.", victim->stats.maxhp, victim->stats.hp);
00086 }
00087 fail_unless(victim->inv == NULL, "kobold shouldn't have an inventory after attacked");
00088 fail_unless(present_arch_in_ob(deplete, victim) == NULL, "victim shouldn't be depleted when slaying not set");
00089
00090 hitter->slaying = add_string(victim->race);
00091 victim->resist[ATNR_FIRE] = 95;
00092 for (test = 0; test < 100 && present_arch_in_ob(deplete, victim) == NULL; test++) {
00093 hit_player(victim, hitter->stats.dam, hitter, hitter->attacktype, 0);
00094 }
00095 fail_unless(present_arch_in_ob(deplete, victim) != NULL, "victim should be depleted when slaying is set");
00096 fail_unless(victim->stats.hp != victim->stats.maxhp, "victim shouldn't have %d hp", victim->stats.hp);
00097 }
00098 END_TEST
00099
00100 Suite *attack_suite(void) {
00101 Suite *s = suite_create("attack");
00102 TCase *tc_core = tcase_create("Core");
00103
00104
00105 tcase_add_checked_fixture(tc_core, setup, teardown);
00106
00107 suite_add_tcase(s, tc_core);
00108 tcase_add_test(tc_core, test_hit_player);
00109
00110 return s;
00111 }
00112
00113 int main(void) {
00114 int nf;
00115 Suite *s = attack_suite();
00116 SRunner *sr = srunner_create(s);
00117
00118
00119
00120
00121 settings.debug = 0;
00122 init(0, NULL);
00123
00124 srunner_set_xml(sr, LOGDIR "/unit/server/attack.xml");
00125 srunner_set_log(sr, LOGDIR "/unit/server/attack.out");
00126 srunner_run_all(sr, CK_ENV);
00127 nf = srunner_ntests_failed(sr);
00128 srunner_free(sr);
00129 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
00130 }