1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <sproto.h> |
25 | #include <sproto.h> |
27 | |
26 | |
… | |
… | |
42 | int mflags; |
41 | int mflags; |
43 | |
42 | |
44 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
43 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
45 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
44 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
46 | |
45 | |
47 | if ((owner = pet->owner) != NULL) |
46 | if (owner = pet->owner) |
48 | { |
47 | { |
49 | /* If the owner has turned on the pet, make the pet |
48 | /* If the owner has turned on the pet, make the pet |
50 | * unfriendly. |
49 | * unfriendly. |
51 | */ |
50 | */ |
52 | if ((check_enemy (owner, rv)) == pet) |
51 | if (check_enemy (owner, rv) == pet) |
53 | { |
52 | { |
54 | CLEAR_FLAG (pet, FLAG_FRIENDLY); |
|
|
55 | remove_friendly_object (pet); |
53 | remove_friendly_object (pet); |
56 | pet->attack_movement &= ~PETMOVE; |
54 | pet->attack_movement &= ~PETMOVE; |
57 | return owner; |
55 | return owner; |
58 | } |
56 | } |
59 | } |
57 | } |
60 | else |
58 | else |
61 | { |
59 | { |
62 | /* else the owner is no longer around, so the |
60 | /* else the owner is no longer around, so the |
63 | * pet no longer needs to be friendly. |
61 | * pet no longer needs to be friendly. |
64 | */ |
62 | */ |
65 | CLEAR_FLAG (pet, FLAG_FRIENDLY); |
|
|
66 | remove_friendly_object (pet); |
63 | remove_friendly_object (pet); |
67 | pet->attack_movement &= ~PETMOVE; |
64 | pet->attack_movement &= ~PETMOVE; |
68 | return NULL; |
65 | return 0; |
69 | } |
66 | } |
|
|
67 | |
70 | /* If they are not on the same map, the pet won't be agressive */ |
68 | /* If they are not on the same map, the pet won't be agressive */ |
71 | if (!on_same_map (pet, owner)) |
69 | //if (!on_same_map (pet, owner)) |
72 | return NULL; |
70 | // return 0; |
73 | |
71 | |
74 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
72 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
75 | if ((tmp = check_enemy (pet, rv)) != NULL) |
73 | if (tmp = check_enemy (pet, rv)) |
76 | { |
74 | { |
77 | if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) |
75 | if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) |
78 | /* without this check, you can actually get pets with |
76 | /* without this check, you can actually get pets with |
79 | * enemy set to owner! |
77 | * enemy set to owner! |
80 | */ |
78 | */ |
81 | pet->enemy = NULL; |
79 | pet->enemy = 0; |
82 | else |
80 | else |
83 | return tmp; |
81 | return tmp; |
84 | } |
82 | } |
85 | |
83 | |
86 | get_search_arr (search_arr); |
84 | get_search_arr (search_arr); |
… | |
… | |
88 | if (owner->type == PLAYER && owner->contr->petmode > pet_normal) |
86 | if (owner->type == PLAYER && owner->contr->petmode > pet_normal) |
89 | { |
87 | { |
90 | if (owner->contr->petmode == pet_sad) |
88 | if (owner->contr->petmode == pet_sad) |
91 | { |
89 | { |
92 | tmp = find_nearest_living_creature (pet); |
90 | tmp = find_nearest_living_creature (pet); |
93 | if (tmp != NULL) |
91 | if (tmp != 0) |
94 | { |
92 | { |
95 | get_rangevector (pet, tmp, rv, 0); |
93 | get_rangevector (pet, tmp, rv, 0); |
96 | if (check_enemy (pet, rv) != NULL) |
94 | if (check_enemy (pet, rv) != 0) |
97 | return tmp; |
95 | return tmp; |
98 | else |
96 | else |
99 | pet->enemy = NULL; |
97 | pet->enemy = 0; |
100 | } |
98 | } |
101 | /* if we got here we have no enemy */ |
99 | /* if we got here we have no enemy */ |
102 | /* we return NULL to avoid heading back to the owner */ |
100 | /* we return 0 to avoid heading back to the owner */ |
103 | pet->enemy = NULL; |
101 | pet->enemy = 0; |
104 | return NULL; |
102 | return 0; |
105 | } |
103 | } |
106 | } |
104 | } |
107 | |
105 | |
108 | /* Since the pet has no existing enemy, look for anything nasty |
106 | /* Since the pet has no existing enemy, look for anything nasty |
109 | * around the owner that it should go and attack. |
107 | * around the owner that it should go and attack. (if the owner is |
|
|
108 | * still on a map) |
110 | */ |
109 | */ |
111 | tmp3 = NULL; |
110 | // owners sometimes are not on a map but in the inventory of somehting else |
|
|
111 | if (!owner->flag [FLAG_REMOVED] && owner->map) |
|
|
112 | { |
|
|
113 | tmp3 = 0; |
|
|
114 | |
112 | for (i = 0; i < SIZEOFFREE; i++) |
115 | for (i = 0; i < SIZEOFFREE; i++) |
113 | { |
116 | { |
114 | x = owner->x + freearr_x[search_arr[i]]; |
117 | x = owner->x + freearr_x[search_arr[i]]; |
115 | y = owner->y + freearr_y[search_arr[i]]; |
118 | y = owner->y + freearr_y[search_arr[i]]; |
116 | nm = owner->map; |
119 | nm = owner->map; |
117 | /* Only look on the space if there is something alive there. */ |
120 | /* Only look on the space if there is something alive there. */ |
118 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
121 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
119 | |
122 | |
120 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
123 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
121 | { |
124 | { |
122 | for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above) |
125 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
123 | { |
|
|
124 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
|
|
125 | |
|
|
126 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
|
|
127 | (tmp2->type != PLAYER)) || |
|
|
128 | should_arena_attack (pet, owner, tmp2)) |
|
|
129 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
|
|
130 | { |
126 | { |
|
|
127 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
131 | |
128 | |
132 | if (!can_see_enemy (pet, tmp2)) |
129 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
|
|
130 | (tmp2->type != PLAYER)) || |
|
|
131 | should_arena_attack (pet, owner, tmp2)) |
|
|
132 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
133 | { |
133 | { |
|
|
134 | |
|
|
135 | if (!can_see_enemy (pet, tmp2)) |
|
|
136 | { |
134 | if (tmp3 != NULL) |
137 | if (tmp3 != 0) |
135 | tmp3 = tmp2; |
138 | tmp3 = tmp2; |
136 | } |
139 | } |
137 | else |
|
|
138 | { |
|
|
139 | pet->enemy = tmp2; |
|
|
140 | if (check_enemy (pet, rv) != NULL) |
|
|
141 | return tmp2; |
|
|
142 | else |
140 | else |
|
|
141 | { |
|
|
142 | pet->enemy = tmp2; |
|
|
143 | if (check_enemy (pet, rv) != 0) |
|
|
144 | return tmp2; |
|
|
145 | else |
143 | pet->enemy = NULL; |
146 | pet->enemy = 0; |
144 | } |
147 | } |
145 | } /* if this is a valid enemy */ |
148 | } /* if this is a valid enemy */ |
146 | } /* for objects on this space */ |
149 | } /* for objects on this space */ |
147 | } /* if there is something living on this space */ |
150 | } /* if there is something living on this space */ |
148 | } /* for loop of spaces around the owner */ |
151 | } /* for loop of spaces around the owner */ |
149 | |
152 | |
150 | /* fine, we went through the whole loop and didn't find one we could |
153 | /* fine, we went through the whole loop and didn't find one we could |
151 | see, take what we have */ |
154 | see, take what we have */ |
152 | if (tmp3 != NULL) |
155 | if (tmp3 != 0) |
153 | { |
156 | { |
154 | pet->enemy = tmp3; |
157 | pet->enemy = tmp3; |
155 | if (check_enemy (pet, rv) != NULL) |
158 | if (check_enemy (pet, rv) != 0) |
156 | return tmp3; |
159 | return tmp3; |
157 | else |
160 | else |
158 | pet->enemy = NULL; |
161 | pet->enemy = 0; |
|
|
162 | } |
159 | } |
163 | } |
160 | |
164 | |
161 | /* No threat to owner, check to see if the pet has an attacker */ |
165 | /* No threat to owner, check to see if the pet has an attacker */ |
162 | if (attacker) |
166 | if (attacker) |
163 | { |
167 | { |
… | |
… | |
165 | /* or otherwise non-hostile, and is an appropriate target */ |
169 | /* or otherwise non-hostile, and is an appropriate target */ |
166 | if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) |
170 | if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) |
167 | { |
171 | { |
168 | pet->enemy = attacker; |
172 | pet->enemy = attacker; |
169 | |
173 | |
170 | if (check_enemy (pet, rv) != NULL) |
174 | if (check_enemy (pet, rv) != 0) |
171 | return attacker; |
175 | return attacker; |
172 | else |
176 | else |
173 | pet->enemy = NULL; |
177 | pet->enemy = 0; |
174 | } |
178 | } |
175 | } |
179 | } |
176 | |
180 | |
177 | /* Don't have an attacker or legal enemy, so look for a new one!. |
181 | /* Don't have an attacker or legal enemy, so look for a new one!. |
178 | * This looks for one around where the pet is. Thus, you could lead |
182 | * This looks for one around where the pet is. Thus, you could lead |
179 | * a pet to danger, then take a few steps back. This code is basically |
183 | * a pet to danger, then take a few steps back. This code is basically |
180 | * the same as the code that looks around the owner. |
184 | * the same as the code that looks around the owner. |
181 | */ |
185 | */ |
182 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
186 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
183 | { |
187 | { |
184 | tmp3 = NULL; |
188 | tmp3 = 0; |
185 | for (i = 0; i < SIZEOFFREE; i++) |
189 | for (i = 0; i < SIZEOFFREE; i++) |
186 | { |
190 | { |
187 | x = pet->x + freearr_x[search_arr[i]]; |
191 | x = pet->x + freearr_x[search_arr[i]]; |
188 | y = pet->y + freearr_y[search_arr[i]]; |
192 | y = pet->y + freearr_y[search_arr[i]]; |
189 | nm = pet->map; |
193 | nm = pet->map; |
190 | /* Only look on the space if there is something alive there. */ |
194 | /* Only look on the space if there is something alive there. */ |
191 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
195 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
192 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
196 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
193 | { |
197 | { |
194 | for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above) |
198 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
195 | { |
199 | { |
196 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
200 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
197 | |
201 | |
198 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
202 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
199 | (tmp2->type != PLAYER)) || |
203 | (tmp2->type != PLAYER)) || |
200 | should_arena_attack (pet, owner, tmp2)) |
204 | should_arena_attack (pet, owner, tmp2)) |
201 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
205 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
202 | { |
206 | { |
203 | |
207 | |
204 | if (!can_see_enemy (pet, tmp2)) |
208 | if (!can_see_enemy (pet, tmp2)) |
205 | { |
209 | { |
206 | if (tmp3 != NULL) |
210 | if (tmp3 != 0) |
207 | tmp3 = tmp2; |
211 | tmp3 = tmp2; |
208 | } |
212 | } |
209 | else |
213 | else |
210 | { |
214 | { |
211 | pet->enemy = tmp2; |
215 | pet->enemy = tmp2; |
212 | if (check_enemy (pet, rv) != NULL) |
216 | if (check_enemy (pet, rv) != 0) |
213 | return tmp2; |
217 | return tmp2; |
214 | else |
218 | else |
215 | pet->enemy = NULL; |
219 | pet->enemy = 0; |
216 | } |
220 | } |
217 | } /* make sure we can get to the bugger */ |
221 | } /* make sure we can get to the bugger */ |
218 | } /* for objects on this space */ |
222 | } /* for objects on this space */ |
219 | } /* if there is something living on this space */ |
223 | } /* if there is something living on this space */ |
220 | } /* for loop of spaces around the pet */ |
224 | } /* for loop of spaces around the pet */ |
|
|
225 | |
|
|
226 | /* fine, we went through the whole loop and didn't find one we could |
|
|
227 | see, take what we have */ |
|
|
228 | if (tmp3 != 0) |
|
|
229 | { |
|
|
230 | pet->enemy = tmp3; |
|
|
231 | if (check_enemy (pet, rv) != 0) |
|
|
232 | return tmp3; |
|
|
233 | else |
|
|
234 | pet->enemy = 0; |
|
|
235 | } |
221 | } /* pet in defence mode */ |
236 | } /* pet in defence mode */ |
222 | |
237 | |
223 | /* fine, we went through the whole loop and didn't find one we could |
238 | object *enemy = check_enemy (pet, rv); |
224 | see, take what we have */ |
239 | // we have a summoned pet here and the owners enemy isn't set or can't |
225 | if (tmp3 != NULL) |
240 | // be reached => search for a player around us and set it as our new enemy!! |
226 | { |
241 | if (!enemy && pet->owner && pet->owner->type != PLAYER) |
227 | pet->enemy = tmp3; |
242 | enemy = get_nearest_player (pet); |
228 | if (check_enemy (pet, rv) != NULL) |
|
|
229 | return tmp3; |
|
|
230 | else |
|
|
231 | pet->enemy = NULL; |
|
|
232 | } |
|
|
233 | |
243 | |
234 | /* Didn't find anything - return the owner's enemy or NULL */ |
244 | /* Didn't find anything - return the owner's enemy or 0 */ |
235 | return check_enemy (pet, rv); |
245 | return enemy; |
236 | } |
246 | } |
237 | |
247 | |
238 | void |
248 | void |
239 | terminate_all_pets (object *owner) |
249 | terminate_all_pets (object *owner) |
240 | { |
250 | { |
241 | objectlink *obl, *next; |
251 | objectlink *obl, *next; |
242 | |
252 | |
243 | for (obl = first_friendly_object; obl != NULL; obl = next) |
253 | for (obl = first_friendly_object; obl; obl = next) |
244 | { |
254 | { |
245 | object *ob = obl->ob; |
255 | object *ob = obl->ob; |
246 | |
|
|
247 | next = obl->next; |
256 | next = obl->next; |
|
|
257 | |
248 | if (ob->owner == owner) |
258 | if (ob->owner == owner) |
249 | { |
|
|
250 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
251 | ob->remove (); |
|
|
252 | remove_friendly_object (ob); |
|
|
253 | ob->destroy (); |
259 | ob->destroy (); |
254 | } |
|
|
255 | } |
260 | } |
256 | } |
261 | } |
257 | |
262 | |
258 | /* |
263 | /* |
259 | * Unfortunately, sometimes, the owner of a pet is in the |
264 | * Unfortunately, sometimes, the owner of a pet is in the |
… | |
… | |
285 | } |
290 | } |
286 | |
291 | |
287 | int |
292 | int |
288 | follow_owner (object *ob, object *owner) |
293 | follow_owner (object *ob, object *owner) |
289 | { |
294 | { |
290 | if (!owner->map) |
295 | if (owner->flag [FLAG_REMOVED]) |
291 | LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); |
296 | return 0; // do nothing if the owner is removed |
292 | else if (owner->map->in_memory != MAP_IN_MEMORY) |
297 | else if (!owner->map || owner->map->in_memory != MAP_IN_MEMORY) |
293 | LOG (llevError, "Owner of the pet not on a map in memory!?\n"); |
298 | LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); |
294 | else |
299 | else |
295 | { |
300 | { |
296 | int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
301 | int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
297 | |
302 | |
298 | if (dir >= 0) |
303 | if (dir >= 0) |
… | |
… | |
311 | } |
316 | } |
312 | |
317 | |
313 | void |
318 | void |
314 | pet_move (object *ob) |
319 | pet_move (object *ob) |
315 | { |
320 | { |
316 | int dir, i; |
321 | int dir = 0, i; |
317 | sint16 dx, dy; |
322 | sint16 dx, dy; |
318 | object *ob2, *owner; |
323 | object *ob2, *owner; |
319 | maptile *m; |
324 | maptile *m; |
320 | |
325 | |
321 | /* Check to see if player pulled out */ |
326 | /* Check to see if player pulled out */ |
322 | if ((owner = ob->owner) == NULL) |
327 | if ((owner = ob->owner) == NULL) |
323 | { |
328 | { |
324 | ob->remove (); /* Will be freed when returning */ |
|
|
325 | remove_friendly_object (ob); |
|
|
326 | ob->destroy (); |
329 | ob->destroy (); |
327 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
330 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
328 | return; |
331 | return; |
329 | } |
332 | } |
330 | |
333 | |
331 | /* move monster into the owners map if not in the same map */ |
334 | /* move monster into the owners map if not in the same map |
332 | if (!on_same_map (ob, owner)) |
335 | * except when the owner is removed. |
|
|
336 | */ |
|
|
337 | if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) |
333 | { |
338 | { |
334 | follow_owner (ob, owner); |
339 | follow_owner (ob, owner); |
335 | return; |
340 | return; |
336 | } |
341 | } |
337 | /* Calculate Direction */ |
342 | /* Calculate Direction */ |
… | |
… | |
350 | continue; |
355 | continue; |
351 | else |
356 | else |
352 | break; |
357 | break; |
353 | } |
358 | } |
354 | } |
359 | } |
355 | else |
360 | else if (!owner->flag [FLAG_REMOVED]) // only get vector to owner when owner not removed |
356 | { |
361 | { |
357 | struct rv_vector rv; |
362 | struct rv_vector rv; |
358 | |
363 | |
359 | get_rangevector (ob, ob->owner, &rv, 0); |
364 | get_rangevector (ob, ob->owner, &rv, 0); |
360 | dir = rv.direction; |
365 | dir = rv.direction; |
… | |
… | |
431 | * is_golem is to note that this is a golem spell. |
436 | * is_golem is to note that this is a golem spell. |
432 | */ |
437 | */ |
433 | object * |
438 | object * |
434 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
439 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
435 | { |
440 | { |
436 | archetype *atmp; |
|
|
437 | object *tmp = NULL, *prev = NULL, *head = NULL; |
441 | object *tmp = NULL, *prev = NULL, *head = NULL; |
438 | |
442 | |
439 | for (atmp = at; atmp; atmp = atmp->more) |
443 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
440 | { |
444 | { |
441 | tmp = arch_to_object (atmp); |
445 | tmp = arch_to_object (atmp); |
442 | |
446 | |
443 | if (atmp == at) |
447 | if (atmp == at) |
444 | { |
448 | { |
445 | if (!is_golem) |
449 | if (!is_golem) |
446 | SET_FLAG (tmp, FLAG_MONSTER); |
450 | SET_FLAG (tmp, FLAG_MONSTER); |
447 | |
451 | |
448 | tmp->set_owner (op); |
452 | tmp->set_owner (op); |
|
|
453 | |
449 | if (op->type == PLAYER) |
454 | if (op->type == PLAYER) |
450 | { |
455 | { |
451 | tmp->stats.exp = 0; |
456 | tmp->stats.exp = 0; |
452 | add_friendly_object (tmp); |
457 | add_friendly_object (tmp); |
453 | if (is_golem) |
458 | if (is_golem) |
… | |
… | |
481 | } |
486 | } |
482 | |
487 | |
483 | if (!head) |
488 | if (!head) |
484 | head = tmp; |
489 | head = tmp; |
485 | |
490 | |
486 | tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; |
491 | tmp->x = op->x + freearr_x[dir] + tmp->arch->x; |
487 | tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; |
492 | tmp->y = op->y + freearr_y[dir] + tmp->arch->y; |
488 | tmp->map = op->map; |
493 | tmp->map = op->map; |
489 | |
494 | |
490 | if (tmp->invisible) |
495 | if (tmp->invisible) |
491 | tmp->invisible = 0; |
496 | tmp->invisible = 0; |
492 | |
497 | |
… | |
… | |
524 | object *tmp; |
529 | object *tmp; |
525 | |
530 | |
526 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
531 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
527 | return; /* Has already been moved */ |
532 | return; /* Has already been moved */ |
528 | |
533 | |
529 | if (op->owner == NULL) |
534 | if (!op->owner) |
530 | { |
535 | { |
531 | LOG (llevDebug, "Golem without owner destructed.\n"); |
536 | LOG (llevDebug, "Golem without owner destructed.\n"); |
532 | op->remove (); |
537 | op->remove (); |
533 | op->destroy (); |
538 | op->destroy (); |
534 | return; |
539 | return; |
… | |
… | |
542 | if (--op->stats.hp < 0) |
547 | if (--op->stats.hp < 0) |
543 | { |
548 | { |
544 | if (op->msg) |
549 | if (op->msg) |
545 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
550 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
546 | |
551 | |
547 | op->owner->contr->ranges[range_golem] = 0; |
|
|
548 | remove_friendly_object (op); |
|
|
549 | op->remove (); |
|
|
550 | op->destroy (); |
552 | op->destroy (); |
551 | return; |
553 | return; |
552 | } |
554 | } |
553 | |
555 | |
554 | /* Do golem attacks/movement for single & multisq golems. |
556 | /* Do golem attacks/movement for single & multisq golems. |
… | |
… | |
586 | * but since we are not trying to dereferance that pointer, |
588 | * but since we are not trying to dereferance that pointer, |
587 | * that isn't a problem. |
589 | * that isn't a problem. |
588 | */ |
590 | */ |
589 | if (victim && victim != op && victim->head != op) |
591 | if (victim && victim != op && victim->head != op) |
590 | { |
592 | { |
591 | |
|
|
592 | /* for golems with race fields, we don't attack |
593 | /* for golems with race fields, we don't attack |
593 | * aligned races |
594 | * aligned races |
594 | */ |
595 | */ |
595 | |
596 | |
596 | if (victim->race && op->race && strstr (op->race, victim->race)) |
597 | if (victim->race && op->race && strstr (op->race, victim->race)) |
… | |
… | |
608 | attack_ob (victim, op); |
609 | attack_ob (victim, op); |
609 | made_attack = 1; |
610 | made_attack = 1; |
610 | } |
611 | } |
611 | } /* If victim */ |
612 | } /* If victim */ |
612 | } |
613 | } |
|
|
614 | |
613 | if (made_attack) |
615 | if (made_attack) |
614 | update_object (op, UP_OBJ_FACE); |
616 | update_object (op, UP_OBJ_FACE); |
615 | } |
617 | } |
616 | |
618 | |
617 | /* this is a really stupid function when you get down and |
619 | /* this is a really stupid function when you get down and |
… | |
… | |
639 | char buf[MAX_BUF]; |
641 | char buf[MAX_BUF]; |
640 | |
642 | |
641 | /* Because there can be different golem spells, player may want to |
643 | /* Because there can be different golem spells, player may want to |
642 | * 'lose' their old golem. |
644 | * 'lose' their old golem. |
643 | */ |
645 | */ |
644 | if (op->type == PLAYER && op->contr->ranges[range_golem]) |
646 | if (op->type == PLAYER && op->contr->golem) |
645 | { |
647 | { |
646 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
648 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
647 | op->contr->ranges[range_golem]->remove (); |
649 | op->contr->golem->remove (); |
648 | op->contr->ranges[range_golem]->destroy (); |
650 | op->contr->golem->destroy (); |
649 | op->contr->ranges[range_golem] = 0; |
651 | op->contr->golem = 0; |
650 | } |
652 | } |
651 | |
653 | |
652 | if (spob->other_arch) |
654 | if (spob->other_arch) |
653 | at = spob->other_arch; |
655 | at = spob->other_arch; |
654 | else if (spob->race) |
656 | else if (spob->race) |
… | |
… | |
674 | LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); |
676 | LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); |
675 | return 0; |
677 | return 0; |
676 | } |
678 | } |
677 | |
679 | |
678 | if (!dir) |
680 | if (!dir) |
679 | dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
681 | dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
680 | |
682 | |
681 | if (dir < 0 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
683 | if (dir < 0 || ob_blocked (at, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
682 | { |
684 | { |
683 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
685 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
684 | return 0; |
686 | return 0; |
685 | } |
687 | } |
686 | |
688 | |
… | |
… | |
694 | |
696 | |
695 | if (op->type == PLAYER) |
697 | if (op->type == PLAYER) |
696 | { |
698 | { |
697 | tmp->type = GOLEM; |
699 | tmp->type = GOLEM; |
698 | tmp->set_owner (op); |
700 | tmp->set_owner (op); |
|
|
701 | op->contr->golem = tmp; |
|
|
702 | /* give the player control of the golem */ |
699 | set_spell_skill (op, caster, spob, tmp); |
703 | set_spell_skill (op, caster, spob, tmp); |
700 | op->contr->ranges[range_golem] = tmp; |
|
|
701 | /* give the player control of the golem */ |
|
|
702 | op->contr->shoottype = range_golem; |
|
|
703 | } |
704 | } |
704 | else |
705 | else |
705 | { |
706 | { |
706 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
707 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
707 | { |
708 | { |
… | |
… | |
896 | if (level < tr->magic) |
897 | if (level < tr->magic) |
897 | break; |
898 | break; |
898 | |
899 | |
899 | lasttr = tr; |
900 | lasttr = tr; |
900 | |
901 | |
901 | if (tr->item->name == sparam) |
902 | if (tr->item->archname == sparam) |
902 | break; |
903 | break; |
903 | } |
904 | } |
904 | |
905 | |
905 | if (!lasttr) |
906 | if (!lasttr) |
906 | { |
907 | { |
… | |
… | |
981 | return 0; |
982 | return 0; |
982 | } |
983 | } |
983 | |
984 | |
984 | for (i = 1; i <= nrof; i++) |
985 | for (i = 1; i <= nrof; i++) |
985 | { |
986 | { |
986 | archetype *atmp; |
|
|
987 | object *prev = NULL, *head = NULL, *tmp; |
987 | object *prev = NULL, *head = NULL, *tmp; |
988 | |
988 | |
989 | if (dir) |
989 | if (dir) |
990 | { |
990 | { |
991 | ndir = dir; |
991 | ndir = dir; |
992 | dir = absdir (dir + 1); |
992 | dir = absdir (dir + 1); |
993 | } |
993 | } |
994 | else |
994 | else |
995 | ndir = find_free_spot (&summon_arch->clone, op->map, op->x, op->y, 1, SIZEOFFREE); |
995 | ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); |
996 | |
996 | |
997 | if (ndir > 0) |
997 | if (ndir > 0) |
998 | { |
998 | { |
999 | x = freearr_x[ndir]; |
999 | x = freearr_x[ndir]; |
1000 | y = freearr_y[ndir]; |
1000 | y = freearr_y[ndir]; |
1001 | } |
1001 | } |
1002 | |
1002 | |
1003 | if (ndir < 0 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) |
1003 | if (ndir < 0 || ob_blocked (summon_arch, op->map, op->x + x, op->y + y)) |
1004 | { |
1004 | { |
1005 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1005 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1006 | if (nrof > 1) |
1006 | if (nrof > 1) |
1007 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
1007 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
1008 | |
1008 | |
1009 | return nrof > 1; |
1009 | return nrof > 1; |
1010 | } |
1010 | } |
1011 | |
1011 | |
1012 | for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) |
1012 | for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more) |
1013 | { |
1013 | { |
1014 | tmp = arch_to_object (atmp); |
1014 | tmp = arch_to_object (atmp); |
1015 | if (atmp == summon_arch) |
1015 | if (atmp == summon_arch) |
1016 | { |
1016 | { |
1017 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
1017 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
… | |
… | |
1050 | tmp->head = head; |
1050 | tmp->head = head; |
1051 | prev->more = tmp; |
1051 | prev->more = tmp; |
1052 | } |
1052 | } |
1053 | |
1053 | |
1054 | prev = tmp; |
1054 | prev = tmp; |
1055 | tmp->x = op->x + x + tmp->arch->clone.x; |
1055 | tmp->x = op->x + x + tmp->arch->x; |
1056 | tmp->y = op->y + y + tmp->arch->clone.y; |
1056 | tmp->y = op->y + y + tmp->arch->y; |
1057 | tmp->map = op->map; |
1057 | tmp->map = op->map; |
1058 | } |
1058 | } |
1059 | |
1059 | |
1060 | head->direction = freedir[ndir]; |
1060 | head->direction = freedir[ndir]; |
1061 | head->stats.exp = 0; |
1061 | head->stats.exp = 0; |
… | |
… | |
1102 | return 0; |
1102 | return 0; |
1103 | |
1103 | |
1104 | /* get the owners of itself and the target, this is to deal with pets of |
1104 | /* get the owners of itself and the target, this is to deal with pets of |
1105 | pets */ |
1105 | pets */ |
1106 | rowner = get_real_owner (owner); |
1106 | rowner = get_real_owner (owner); |
1107 | if (target->type != PLAYER) |
1107 | towner = target->type == PLAYER ? 0 : get_real_owner (target); |
1108 | { |
|
|
1109 | towner = get_real_owner (target); |
|
|
1110 | } |
|
|
1111 | else |
|
|
1112 | { |
|
|
1113 | towner = 0; |
|
|
1114 | } |
|
|
1115 | |
1108 | |
1116 | /* if the pet has now owner, exit with error */ |
1109 | /* if the pet has now owner, exit with error */ |
1117 | if (rowner == NULL) |
1110 | if (!rowner) |
1118 | { |
1111 | { |
1119 | LOG (llevError, "Pet has no owner.\n"); |
1112 | LOG (llevError, "Pet has no owner.\n"); |
1120 | return 0; |
1113 | return 0; |
1121 | } |
1114 | } |
1122 | |
1115 | |