OSDN Git Service

日本語訳を修正
[vms-empire-jp/vms-empire-jp.git] / attack.c
1 /*
2  *    Copyright (C) 1987, 1988 Chuck Simmons
3  * 
4  * See the file COPYING, distributed with empire, for restriction
5  * and warranty information.
6  */
7
8 /*
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.
14
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.
18
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,
23 if any.
24 */
25
26 #include "empire.h"
27 #include "extern.h"
28
29 void
30 attack_city(piece_info_t *att_obj, loc_t loc)
31 {
32     city_info_t *cityp;
33     int att_owner, city_owner;
34
35     cityp = find_city (loc);
36     ASSERT (cityp);
37         
38     att_owner = att_obj->owner;
39     city_owner = cityp->owner;
40
41     if (irand (2) == 0) { /* attack fails? */
42         if (att_owner == USER) {
43             comment ("都市の防衛隊があなたの部隊を退けた。");
44             ksend ("都市の防衛隊があなたの部隊を退けた。\n"); //kermyt
45         }
46         else if (city_owner == USER) {
47             ksend ("支配下の都市%dが攻撃された。\n",loc_disp(cityp->loc)); //kermyt
48             comment ("支配下の都市%dが攻撃された。",loc_disp(cityp->loc));
49         }
50         kill_obj (att_obj, loc);
51     }
52     else { /* attack succeeded */
53         kill_city (cityp);
54         cityp->owner = att_owner;
55         kill_obj (att_obj, loc);
56
57         if (att_owner == USER) {
58             ksend ("都市%dを支配下に置いた!\n",loc_disp(cityp->loc)); //kermyt
59             error ("都市%dを支配下に置いた!",loc_disp(cityp->loc));
60
61             extra ("占領のため部隊は解散した。");
62             ksend ("占領のため部隊は解散した。\n");
63             set_prod (cityp);
64         }
65         else if (city_owner == USER) {
66             ksend("都市%dを失った!\n",loc_disp(cityp->loc)); //kermyt
67             comment ("都市%dを失った!",loc_disp(cityp->loc));
68         }
69     }
70     /* let city owner see all results */
71     if (city_owner != UNOWNED) scan (MAP(city_owner), loc);
72 }
73
74 /*
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.
77 */
78
79 void
80 attack_obj(piece_info_t *att_obj, loc_t loc)
81 {
82     void describe(piece_info_t *, piece_info_t *, loc_t);
83     void survive(piece_info_t *, loc_t);
84
85     piece_info_t *def_obj; /* defender */
86     int owner;
87
88     def_obj = find_obj_at_loc (loc);
89     ASSERT (def_obj != NULL); /* can't find object to attack? */
90         
91     if (def_obj->type == SATELLITE) return; /* can't attack a satellite */
92
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;
97     }
98
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 */
104     }
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);
110     }
111     /* show results to first killed */
112     scan (MAP(owner), loc);
113 }
114
115 void
116 attack(piece_info_t *att_obj, loc_t loc)
117 {
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 */
121 }
122
123 /*
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
127 location.
128 */
129
130 void
131 survive(piece_info_t *obj, loc_t loc)
132 {
133     while (obj_capacity (obj) < obj->count)
134         kill_obj (obj->cargo, loc);
135                 
136     move_obj (obj, loc);
137 }
138
139 void
140 describe(piece_info_t *win_obj, piece_info_t *lose_obj, loc_t loc)
141 {
142     char buf[STRSIZE];
143     char buf2[STRSIZE];
144         
145     *buf = '\0';
146     *buf2 = '\0';
147         
148     if (win_obj->owner != lose_obj->owner) {
149         if (win_obj->owner == USER) {
150             int diff;
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);
156                                 
157             diff = win_obj->count - obj_capacity (win_obj);
158             if (diff > 0) switch (win_obj->cargo->type) {
159                 case ARMY:
160                     ksend("攻撃で%d個の地上部隊が海に落ちておぼれた。\n",diff); //kermyt
161                     topmsg (3,"攻撃で%d個の地上部隊が海に落ちておぼれた。",diff);
162                     break;
163                 case FIGHTER:
164                     ksend("攻撃で%d機の戦闘機が海に落ちて失われた。\n",diff); //kermyt
165                     topmsg (3,"攻撃で%dの戦闘機が海に落ちて失われた。",diff);
166                     break;
167                 }
168         }
169         else {
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));
173         }
174         set_need_delay ();
175     }
176 }
177
178 /* end */