2 * Copyright (C) 1987, 1988 Chuck Simmons
4 * See the file COPYING, distributed with empire, for restriction
5 * and warranty information.
9 attack.c -- handle an attack between two pieces. We do everything from
10 fighting it out between the pieces to notifying the user who won and
11 killing off the losing object. Somewhere far above, our caller is
12 responsible for actually removing the object from its list and actually
13 updating the player's view of the world.
15 Find object being attacked. If it is a city, attacker has 50% chance
16 of taking city. If successful, give city to attacker. Otherwise
17 kill attacking piece. Tell user who won.
19 If attacking object is not a city, loop. On each iteration, select one
20 piece to throw a blow. Damage the opponent by the strength of the blow
21 thrower. Stop looping when one object has 0 or fewer hits. Kill off
22 the dead object. Tell user who won and how many hits her piece has left,
30 attack_city(piece_info_t *att_obj, loc_t loc)
33 int att_owner, city_owner;
35 cityp = find_city (loc);
38 att_owner = att_obj->owner;
39 city_owner = cityp->owner;
41 if (irand (2) == 0) { /* attack fails? */
42 if (att_owner == USER) {
43 comment ("都市の防衛隊があなたの部隊を退けた。");
44 ksend ("都市の防衛隊があなたの部隊を退けた。\n"); //kermyt
46 else if (city_owner == USER) {
47 ksend ("支配下の都市%dが攻撃された。\n",loc_disp(cityp->loc)); //kermyt
48 comment ("支配下の都市%dが攻撃された。",loc_disp(cityp->loc));
50 kill_obj (att_obj, loc);
52 else { /* attack succeeded */
54 cityp->owner = att_owner;
55 kill_obj (att_obj, loc);
57 if (att_owner == USER) {
58 ksend ("都市%dを支配下に置いた!\n",loc_disp(cityp->loc)); //kermyt
59 error ("都市%dを支配下に置いた!",loc_disp(cityp->loc));
61 extra ("占領のため部隊は解散した。");
62 ksend ("占領のため部隊は解散した。\n");
65 else if (city_owner == USER) {
66 ksend("都市%dを失った!\n",loc_disp(cityp->loc)); //kermyt
67 comment ("都市%dを失った!",loc_disp(cityp->loc));
70 /* let city owner see all results */
71 if (city_owner != UNOWNED) scan (MAP(city_owner), loc);
75 Attack a piece other than a city. The piece could be anyone's.
76 First we have to figure out what is being attacked.
80 attack_obj(piece_info_t *att_obj, loc_t loc)
82 void describe(piece_info_t *, piece_info_t *, loc_t);
83 void survive(piece_info_t *, loc_t);
85 piece_info_t *def_obj; /* defender */
88 def_obj = find_obj_at_loc (loc);
89 ASSERT (def_obj != NULL); /* can't find object to attack? */
91 if (def_obj->type == SATELLITE) return; /* can't attack a satellite */
93 while (att_obj->hits > 0 && def_obj->hits > 0) {
94 if (irand (2) == 0) /* defender hits? */
95 att_obj->hits -= piece_attr[def_obj->type].strength;
96 else def_obj->hits -= piece_attr[att_obj->type].strength;
99 if (att_obj->hits > 0) { /* attacker won? */
100 describe (att_obj, def_obj, loc);
101 owner = def_obj->owner;
102 kill_obj (def_obj, loc); /* kill loser */
103 survive (att_obj, loc); /* move attacker */
105 else { /* defender won */
106 describe (def_obj, att_obj, loc);
107 owner = att_obj->owner;
108 kill_obj (att_obj, loc);
109 survive (def_obj, loc);
111 /* show results to first killed */
112 scan (MAP(owner), loc);
116 attack(piece_info_t *att_obj, loc_t loc)
118 if (map[loc].contents == MAP_CITY) /* attacking a city? */
119 attack_city (att_obj, loc);
120 else attack_obj (att_obj, loc); /* attacking a piece */
124 Here we look to see if any cargo was killed in the attack. If
125 a ships contents exceeds its capacity, some of the survivors
126 fall overboard and drown. We also move the survivor to the given
131 survive(piece_info_t *obj, loc_t loc)
133 while (obj_capacity (obj) < obj->count)
134 kill_obj (obj->cargo, loc);
140 describe(piece_info_t *win_obj, piece_info_t *lose_obj, loc_t loc)
148 if (win_obj->owner != lose_obj->owner) {
149 if (win_obj->owner == USER) {
151 user_score += piece_attr[lose_obj->type].build_time;
152 ksend ("敵の%s%dを破壊した。\n",piece_attr[lose_obj->type].name,loc_disp(loc)); //kermyt
153 topmsg (1, "敵の%s%dを破壊した。",piece_attr[lose_obj->type].name,loc_disp(loc));
154 ksend ("あなたの%sの残りヒットポイントは%dだ。\n",piece_attr[win_obj->type].name,win_obj->hits); //kermyt
155 topmsg (2, "あなたの%sの残りヒットポイントは%dだ。", piece_attr[win_obj->type].name, win_obj->hits);
157 diff = win_obj->count - obj_capacity (win_obj);
158 if (diff > 0) switch (win_obj->cargo->type) {
160 ksend("攻撃で%d個の地上部隊が海に落ちておぼれた。\n",diff); //kermyt
161 topmsg (3,"攻撃で%d個の地上部隊が海に落ちておぼれた。",diff);
164 ksend("攻撃で%d機の戦闘機が海に落ちて失われた。\n",diff); //kermyt
165 topmsg (3,"攻撃で%dの戦闘機が海に落ちて失われた。",diff);
170 comp_score += piece_attr[lose_obj->type].build_time;
171 ksend ("あなたの%s%dは破壊された。\n",piece_attr[lose_obj->type].name,loc_disp(loc)); //kermyt
172 topmsg (3, "あなたの%s%dは破壊された。",piece_attr[lose_obj->type].name,loc_disp(loc));