1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | (at your option) any later version. |
11 | * option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <sproto.h> |
26 | #include <sproto.h> |
26 | |
27 | |
27 | /* given that 'pet' is a friendly object, this function returns a |
28 | /* given that 'pet' is a friendly object, this function returns a |
… | |
… | |
31 | * this is now tilemap aware. |
32 | * this is now tilemap aware. |
32 | */ |
33 | */ |
33 | object * |
34 | object * |
34 | get_pet_enemy (object *pet, rv_vector * rv) |
35 | get_pet_enemy (object *pet, rv_vector * rv) |
35 | { |
36 | { |
36 | object *owner, *tmp, *attacker, *tmp3; |
37 | object *tmp, *attacker, *tmp3; |
37 | int i; |
38 | int i; |
38 | sint16 x, y; |
39 | sint16 x, y; |
39 | maptile *nm; |
40 | maptile *nm; |
40 | int search_arr[SIZEOFFREE]; |
41 | int search_arr[SIZEOFFREE]; |
41 | int mflags; |
42 | int mflags; |
42 | |
43 | |
43 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
44 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
44 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
45 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
45 | |
46 | |
46 | if ((owner = pet->owner) != NULL) |
47 | object *owner = pet->owner; |
47 | { |
48 | |
48 | /* If the owner has turned on the pet, make the pet |
49 | if (!owner) |
49 | * unfriendly. |
|
|
50 | */ |
|
|
51 | if ((check_enemy (owner, rv)) == pet) |
|
|
52 | { |
|
|
53 | CLEAR_FLAG (pet, FLAG_FRIENDLY); |
|
|
54 | remove_friendly_object (pet); |
|
|
55 | pet->attack_movement &= ~PETMOVE; |
|
|
56 | return owner; |
|
|
57 | } |
|
|
58 | } |
50 | { |
59 | else |
|
|
60 | { |
|
|
61 | /* else the owner is no longer around, so the |
51 | /* the owner is no longer around, so the |
62 | * pet no longer needs to be friendly. |
52 | * pet no longer needs to be friendly. |
63 | */ |
53 | */ |
64 | CLEAR_FLAG (pet, FLAG_FRIENDLY); |
|
|
65 | remove_friendly_object (pet); |
54 | remove_friendly_object (pet); |
66 | pet->attack_movement &= ~PETMOVE; |
55 | pet->attack_movement &= ~PETMOVE; |
67 | return NULL; |
56 | return 0; |
|
|
57 | } |
|
|
58 | |
|
|
59 | /* If the owner has turned on the pet, make the pet |
|
|
60 | * unfriendly. |
|
|
61 | */ |
|
|
62 | if (check_enemy (owner, rv) == pet) |
68 | } |
63 | { |
|
|
64 | remove_friendly_object (pet); |
|
|
65 | pet->attack_movement &= ~PETMOVE; |
|
|
66 | return owner; |
|
|
67 | } |
|
|
68 | |
69 | /* If they are not on the same map, the pet won't be agressive */ |
69 | /* If they are not on the same map, the pet won't be agressive */ |
70 | if (!on_same_map (pet, owner)) |
70 | //if (!on_same_map (pet, owner)) |
71 | return NULL; |
71 | // return 0; |
72 | |
72 | |
73 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
73 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
74 | if ((tmp = check_enemy (pet, rv)) != NULL) |
74 | if (tmp = check_enemy (pet, rv)) |
75 | { |
75 | { |
76 | if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) |
76 | if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) |
77 | /* without this check, you can actually get pets with |
77 | /* without this check, you can actually get pets with |
78 | * enemy set to owner! |
78 | * enemy set to owner! |
79 | */ |
79 | */ |
80 | pet->enemy = NULL; |
80 | pet->enemy = 0; |
81 | else |
81 | else |
82 | return tmp; |
82 | return tmp; |
83 | } |
83 | } |
84 | |
84 | |
85 | get_search_arr (search_arr); |
85 | get_search_arr (search_arr); |
… | |
… | |
87 | if (owner->type == PLAYER && owner->contr->petmode > pet_normal) |
87 | if (owner->type == PLAYER && owner->contr->petmode > pet_normal) |
88 | { |
88 | { |
89 | if (owner->contr->petmode == pet_sad) |
89 | if (owner->contr->petmode == pet_sad) |
90 | { |
90 | { |
91 | tmp = find_nearest_living_creature (pet); |
91 | tmp = find_nearest_living_creature (pet); |
92 | if (tmp != NULL) |
92 | if (tmp != 0) |
93 | { |
93 | { |
94 | get_rangevector (pet, tmp, rv, 0); |
94 | get_rangevector (pet, tmp, rv, 0); |
95 | if (check_enemy (pet, rv) != NULL) |
95 | if (check_enemy (pet, rv) != 0) |
96 | return tmp; |
96 | return tmp; |
97 | else |
97 | else |
98 | pet->enemy = NULL; |
98 | pet->enemy = 0; |
99 | } |
99 | } |
100 | /* if we got here we have no enemy */ |
100 | /* if we got here we have no enemy */ |
101 | /* we return NULL to avoid heading back to the owner */ |
101 | /* we return 0 to avoid heading back to the owner */ |
102 | pet->enemy = NULL; |
102 | pet->enemy = 0; |
103 | return NULL; |
103 | return 0; |
104 | } |
104 | } |
105 | } |
105 | } |
106 | |
106 | |
107 | /* Since the pet has no existing enemy, look for anything nasty |
107 | /* Since the pet has no existing enemy, look for anything nasty |
108 | * around the owner that it should go and attack. |
108 | * around the owner that it should go and attack. (if the owner is |
|
|
109 | * still on a map) |
109 | */ |
110 | */ |
110 | tmp3 = NULL; |
111 | // owners sometimes are not on a map but in the inventory of somehting else |
|
|
112 | if (!owner->flag [FLAG_REMOVED] && owner->map) |
|
|
113 | { |
|
|
114 | tmp3 = 0; |
|
|
115 | |
111 | for (i = 0; i < SIZEOFFREE; i++) |
116 | for (i = 0; i < SIZEOFFREE; i++) |
112 | { |
117 | { |
113 | x = owner->x + freearr_x[search_arr[i]]; |
118 | x = owner->x + freearr_x[search_arr[i]]; |
114 | y = owner->y + freearr_y[search_arr[i]]; |
119 | y = owner->y + freearr_y[search_arr[i]]; |
115 | nm = owner->map; |
120 | nm = owner->map; |
116 | /* Only look on the space if there is something alive there. */ |
121 | /* Only look on the space if there is something alive there. */ |
117 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
122 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
118 | |
123 | |
119 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
124 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
120 | { |
125 | { |
121 | for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above) |
126 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
122 | { |
|
|
123 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
|
|
124 | |
|
|
125 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
|
|
126 | (tmp2->type != PLAYER)) || |
|
|
127 | should_arena_attack (pet, owner, tmp2)) |
|
|
128 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
|
|
129 | { |
127 | { |
|
|
128 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
130 | |
129 | |
131 | if (!can_see_enemy (pet, tmp2)) |
130 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
|
|
131 | (tmp2->type != PLAYER)) || |
|
|
132 | should_arena_attack (pet, owner, tmp2)) |
|
|
133 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
132 | { |
134 | { |
|
|
135 | |
|
|
136 | if (!can_see_enemy (pet, tmp2)) |
|
|
137 | { |
133 | if (tmp3 != NULL) |
138 | if (tmp3 != 0) |
134 | tmp3 = tmp2; |
139 | tmp3 = tmp2; |
135 | } |
140 | } |
136 | else |
|
|
137 | { |
|
|
138 | pet->enemy = tmp2; |
|
|
139 | if (check_enemy (pet, rv) != NULL) |
|
|
140 | return tmp2; |
|
|
141 | else |
141 | else |
|
|
142 | { |
|
|
143 | pet->enemy = tmp2; |
|
|
144 | if (check_enemy (pet, rv) != 0) |
|
|
145 | return tmp2; |
|
|
146 | else |
142 | pet->enemy = NULL; |
147 | pet->enemy = 0; |
143 | } |
148 | } |
144 | } /* if this is a valid enemy */ |
149 | } /* if this is a valid enemy */ |
145 | } /* for objects on this space */ |
150 | } /* for objects on this space */ |
146 | } /* if there is something living on this space */ |
151 | } /* if there is something living on this space */ |
147 | } /* for loop of spaces around the owner */ |
152 | } /* for loop of spaces around the owner */ |
148 | |
153 | |
149 | /* fine, we went through the whole loop and didn't find one we could |
154 | /* fine, we went through the whole loop and didn't find one we could |
150 | see, take what we have */ |
155 | see, take what we have */ |
151 | if (tmp3 != NULL) |
156 | if (tmp3 != 0) |
152 | { |
157 | { |
153 | pet->enemy = tmp3; |
158 | pet->enemy = tmp3; |
154 | if (check_enemy (pet, rv) != NULL) |
159 | if (check_enemy (pet, rv) != 0) |
155 | return tmp3; |
160 | return tmp3; |
156 | else |
161 | else |
157 | pet->enemy = NULL; |
162 | pet->enemy = 0; |
|
|
163 | } |
158 | } |
164 | } |
159 | |
165 | |
160 | /* No threat to owner, check to see if the pet has an attacker */ |
166 | /* No threat to owner, check to see if the pet has an attacker */ |
161 | if (attacker) |
167 | if (attacker) |
162 | { |
168 | { |
… | |
… | |
164 | /* or otherwise non-hostile, and is an appropriate target */ |
170 | /* or otherwise non-hostile, and is an appropriate target */ |
165 | if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) |
171 | if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) |
166 | { |
172 | { |
167 | pet->enemy = attacker; |
173 | pet->enemy = attacker; |
168 | |
174 | |
169 | if (check_enemy (pet, rv) != NULL) |
175 | if (check_enemy (pet, rv) != 0) |
170 | return attacker; |
176 | return attacker; |
171 | else |
177 | else |
172 | pet->enemy = NULL; |
178 | pet->enemy = 0; |
173 | } |
179 | } |
174 | } |
180 | } |
175 | |
181 | |
176 | /* Don't have an attacker or legal enemy, so look for a new one!. |
182 | /* Don't have an attacker or legal enemy, so look for a new one!. |
177 | * This looks for one around where the pet is. Thus, you could lead |
183 | * This looks for one around where the pet is. Thus, you could lead |
178 | * a pet to danger, then take a few steps back. This code is basically |
184 | * a pet to danger, then take a few steps back. This code is basically |
179 | * the same as the code that looks around the owner. |
185 | * the same as the code that looks around the owner. |
180 | */ |
186 | */ |
181 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
187 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
182 | { |
188 | { |
183 | tmp3 = NULL; |
189 | tmp3 = 0; |
184 | for (i = 0; i < SIZEOFFREE; i++) |
190 | for (i = 0; i < SIZEOFFREE; i++) |
185 | { |
191 | { |
186 | x = pet->x + freearr_x[search_arr[i]]; |
192 | x = pet->x + freearr_x[search_arr[i]]; |
187 | y = pet->y + freearr_y[search_arr[i]]; |
193 | y = pet->y + freearr_y[search_arr[i]]; |
188 | nm = pet->map; |
194 | nm = pet->map; |
189 | /* Only look on the space if there is something alive there. */ |
195 | /* Only look on the space if there is something alive there. */ |
190 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
196 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
191 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
197 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
192 | { |
198 | { |
193 | for (tmp = GET_MAP_OB (nm, x, y); tmp != NULL; tmp = tmp->above) |
199 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
194 | { |
200 | { |
195 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
201 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
196 | |
202 | |
197 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
203 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
198 | (tmp2->type != PLAYER)) || |
204 | (tmp2->type != PLAYER)) || |
199 | should_arena_attack (pet, owner, tmp2)) |
205 | should_arena_attack (pet, owner, tmp2)) |
200 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
206 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
201 | { |
207 | { |
202 | |
208 | |
203 | if (!can_see_enemy (pet, tmp2)) |
209 | if (!can_see_enemy (pet, tmp2)) |
204 | { |
210 | { |
205 | if (tmp3 != NULL) |
211 | if (tmp3 != 0) |
206 | tmp3 = tmp2; |
212 | tmp3 = tmp2; |
207 | } |
213 | } |
208 | else |
214 | else |
209 | { |
215 | { |
210 | pet->enemy = tmp2; |
216 | pet->enemy = tmp2; |
211 | if (check_enemy (pet, rv) != NULL) |
217 | if (check_enemy (pet, rv) != 0) |
212 | return tmp2; |
218 | return tmp2; |
213 | else |
219 | else |
214 | pet->enemy = NULL; |
220 | pet->enemy = 0; |
215 | } |
221 | } |
216 | } /* make sure we can get to the bugger */ |
222 | } /* make sure we can get to the bugger */ |
217 | } /* for objects on this space */ |
223 | } /* for objects on this space */ |
218 | } /* if there is something living on this space */ |
224 | } /* if there is something living on this space */ |
219 | } /* for loop of spaces around the pet */ |
225 | } /* for loop of spaces around the pet */ |
|
|
226 | |
|
|
227 | /* fine, we went through the whole loop and didn't find one we could |
|
|
228 | see, take what we have */ |
|
|
229 | if (tmp3 != 0) |
|
|
230 | { |
|
|
231 | pet->enemy = tmp3; |
|
|
232 | if (check_enemy (pet, rv) != 0) |
|
|
233 | return tmp3; |
|
|
234 | else |
|
|
235 | pet->enemy = 0; |
|
|
236 | } |
220 | } /* pet in defence mode */ |
237 | } /* pet in defence mode */ |
221 | |
238 | |
222 | /* fine, we went through the whole loop and didn't find one we could |
239 | object *enemy = check_enemy (pet, rv); |
223 | see, take what we have */ |
240 | // we have a summoned pet here and the owners enemy isn't set or can't |
224 | if (tmp3 != NULL) |
241 | // be reached => search for a player around us and set it as our new enemy!! |
225 | { |
242 | if (!enemy && pet->owner && pet->owner->type != PLAYER) |
226 | pet->enemy = tmp3; |
243 | enemy = get_nearest_player (pet); |
227 | if (check_enemy (pet, rv) != NULL) |
|
|
228 | return tmp3; |
|
|
229 | else |
|
|
230 | pet->enemy = NULL; |
|
|
231 | } |
|
|
232 | |
244 | |
233 | /* Didn't find anything - return the owner's enemy or NULL */ |
245 | /* Didn't find anything - return the owner's enemy or 0 */ |
234 | return check_enemy (pet, rv); |
246 | return enemy; |
235 | } |
247 | } |
236 | |
248 | |
237 | void |
249 | void |
238 | terminate_all_pets (object *owner) |
250 | terminate_all_pets (object *owner) |
239 | { |
251 | { |
240 | objectlink *obl, *next; |
252 | objectlink *obl, *next; |
241 | |
253 | |
242 | for (obl = first_friendly_object; obl != NULL; obl = next) |
254 | for (obl = first_friendly_object; obl; obl = next) |
243 | { |
255 | { |
244 | object *ob = obl->ob; |
256 | object *ob = obl->ob; |
245 | |
|
|
246 | next = obl->next; |
257 | next = obl->next; |
|
|
258 | |
247 | if (ob->owner == owner) |
259 | if (ob->owner == owner) |
248 | { |
|
|
249 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
250 | ob->remove (); |
|
|
251 | remove_friendly_object (ob); |
|
|
252 | ob->destroy (); |
260 | ob->drop_and_destroy (); |
253 | } |
|
|
254 | } |
261 | } |
255 | } |
262 | } |
256 | |
263 | |
257 | /* |
264 | /* |
258 | * Unfortunately, sometimes, the owner of a pet is in the |
265 | * Unfortunately, sometimes, the owner of a pet is in the |
… | |
… | |
266 | remove_all_pets (maptile *map) |
273 | remove_all_pets (maptile *map) |
267 | { |
274 | { |
268 | objectlink *obl, *next; |
275 | objectlink *obl, *next; |
269 | object *owner; |
276 | object *owner; |
270 | |
277 | |
271 | for (obl = first_friendly_object; obl != NULL; obl = next) |
278 | for (obl = first_friendly_object; obl; obl = next) |
272 | { |
279 | { |
273 | next = obl->next; |
280 | next = obl->next; |
274 | if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && |
281 | |
275 | (owner = obl->ob->owner) != NULL && !on_same_map (owner, obl->ob)) |
282 | if (obl->ob->type != PLAYER |
|
|
283 | && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) |
|
|
284 | && (owner = obl->ob->owner) != 0 |
|
|
285 | && !on_same_map (owner, obl->ob)) |
276 | { |
286 | { |
277 | /* follow owner checks map status for us */ |
287 | /* follow owner checks map status for us */ |
278 | follow_owner (obl->ob, owner); |
288 | follow_owner (obl->ob, owner); |
279 | } |
289 | } |
280 | } |
290 | } |
281 | } |
291 | } |
282 | |
292 | |
283 | int |
293 | int |
284 | follow_owner (object *ob, object *owner) |
294 | follow_owner (object *ob, object *owner) |
285 | { |
295 | { |
286 | object *tmp; |
296 | if (owner->flag [FLAG_REMOVED]) |
287 | int dir; |
297 | return 0; // do nothing if the owner is removed |
288 | |
298 | else if (!owner->map || owner->map->in_memory != MAP_ACTIVE) |
289 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
299 | LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); |
290 | ob->remove (); |
300 | else |
291 | |
|
|
292 | if (owner->map == NULL) |
|
|
293 | { |
|
|
294 | LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); |
|
|
295 | goto fail; |
|
|
296 | } |
301 | { |
297 | if (owner->map->in_memory != MAP_IN_MEMORY) |
|
|
298 | { |
|
|
299 | LOG (llevError, "Owner of the pet not on a map in memory!?\n"); |
|
|
300 | goto fail; |
|
|
301 | } |
|
|
302 | |
|
|
303 | dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
302 | int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
304 | |
303 | |
305 | if (dir == -1) |
304 | if (dir >= 0) |
306 | { |
|
|
307 | LOG (llevMonster, "No space for pet to follow, freeing %s.\n", &ob->name); |
|
|
308 | goto fail; |
|
|
309 | } |
|
|
310 | for (tmp = ob; tmp != NULL; tmp = tmp->more) |
|
|
311 | { |
|
|
312 | tmp->x = owner->x + freearr_x[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
|
|
313 | tmp->y = owner->y + freearr_y[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
|
|
314 | tmp->map = owner->map; |
|
|
315 | if (OUT_OF_REAL_MAP (tmp->map, tmp->x, tmp->y)) |
|
|
316 | { |
|
|
317 | tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y); |
|
|
318 | } |
305 | { |
319 | } |
306 | owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]); |
320 | insert_ob_in_map (ob, ob->map, NULL, 0); |
307 | |
321 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
308 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
322 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
309 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
323 | |
310 | |
324 | return 0; |
311 | return 0; |
|
|
312 | } |
|
|
313 | } |
325 | |
314 | |
326 | fail: |
|
|
327 | remove_friendly_object (ob); |
|
|
328 | ob->destroy (); |
315 | ob->drop_and_destroy (); |
329 | |
316 | |
330 | return 1; |
317 | return 1; |
331 | } |
318 | } |
332 | |
319 | |
333 | void |
320 | void |
334 | pet_move (object *ob) |
321 | pet_move (object *ob) |
335 | { |
322 | { |
336 | int dir, i; |
323 | int dir = 0, i; |
337 | sint16 dx, dy; |
324 | sint16 dx, dy; |
338 | object *ob2, *owner; |
325 | object *ob2, *owner; |
339 | maptile *m; |
326 | maptile *m; |
340 | |
327 | |
341 | /* Check to see if player pulled out */ |
328 | /* Check to see if player pulled out */ |
342 | if ((owner = ob->owner) == NULL) |
329 | if ((owner = ob->owner) == NULL) |
343 | { |
330 | { |
344 | ob->remove (); /* Will be freed when returning */ |
|
|
345 | remove_friendly_object (ob); |
|
|
346 | ob->destroy (); |
331 | ob->drop_and_destroy (); |
347 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
332 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
348 | return; |
333 | return; |
349 | } |
334 | } |
350 | |
335 | |
351 | /* move monster into the owners map if not in the same map */ |
336 | /* move monster into the owners map if not in the same map |
352 | if (!on_same_map (ob, owner)) |
337 | * except when the owner is removed. |
|
|
338 | */ |
|
|
339 | if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) |
353 | { |
340 | { |
354 | follow_owner (ob, owner); |
341 | follow_owner (ob, owner); |
355 | return; |
342 | return; |
356 | } |
343 | } |
|
|
344 | |
357 | /* Calculate Direction */ |
345 | /* Calculate Direction */ |
358 | if (owner->type == PLAYER && owner->contr->petmode == pet_sad) |
346 | if (owner->type == PLAYER && owner->contr->petmode == pet_sad) |
359 | { |
347 | { |
360 | /* in S&D mode, if we have no enemy, run randomly about. */ |
348 | /* in S&D mode, if we have no enemy, run randomly about. */ |
361 | for (i = 0; i < 15; i++) |
349 | for (i = 0; i < 15; i++) |
… | |
… | |
370 | continue; |
358 | continue; |
371 | else |
359 | else |
372 | break; |
360 | break; |
373 | } |
361 | } |
374 | } |
362 | } |
375 | else |
363 | else if (!owner->flag [FLAG_REMOVED]) // only get vector to owner when owner not removed |
376 | { |
364 | { |
377 | struct rv_vector rv; |
365 | struct rv_vector rv; |
378 | |
366 | |
379 | get_rangevector (ob, ob->owner, &rv, 0); |
367 | get_rangevector (ob, ob->owner, &rv, 0); |
380 | dir = rv.direction; |
368 | dir = rv.direction; |
381 | } |
369 | } |
|
|
370 | |
382 | ob->direction = dir; |
371 | ob->direction = dir; |
383 | |
372 | |
384 | /* move_ob returns 0 if the object couldn't move. If that is the |
373 | /* move_ob returns 0 if the object couldn't move. If that is the |
385 | * case, lets do some other work. |
374 | * case, lets do some other work. |
386 | */ |
375 | */ |
… | |
… | |
403 | for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
392 | for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
404 | { |
393 | { |
405 | object *new_ob; |
394 | object *new_ob; |
406 | |
395 | |
407 | new_ob = ob2->head ? ob2->head : ob2; |
396 | new_ob = ob2->head ? ob2->head : ob2; |
|
|
397 | |
408 | if (new_ob == ob) |
398 | if (new_ob == ob) |
409 | break; |
399 | break; |
|
|
400 | |
410 | if (new_ob == ob->owner) |
401 | if (new_ob == ob->owner) |
411 | return; |
402 | return; |
|
|
403 | |
412 | if (new_ob->owner == ob->owner) |
404 | if (new_ob->owner == ob->owner) |
413 | break; |
405 | break; |
414 | |
406 | |
415 | /* Hmm. Did we try to move into an enemy monster? If so, |
407 | /* Hmm. Did we try to move into an enemy monster? If so, |
416 | * make it our enemy. |
408 | * make it our enemy. |
… | |
… | |
430 | return; |
422 | return; |
431 | } |
423 | } |
432 | } |
424 | } |
433 | } |
425 | } |
434 | /* Try a different course */ |
426 | /* Try a different course */ |
435 | dir = absdir (dir + 4 - (RANDOM () % 5) - (RANDOM () % 5)); |
427 | dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); |
436 | (void) move_ob (ob, dir, ob); |
428 | move_ob (ob, dir, ob); |
437 | } |
429 | } |
438 | return; |
|
|
439 | } |
430 | } |
440 | |
431 | |
441 | /**************************************************************************** |
432 | /**************************************************************************** |
442 | * |
433 | * |
443 | * GOLEM SPELL CODE |
434 | * GOLEM SPELL CODE |
… | |
… | |
451 | * is_golem is to note that this is a golem spell. |
442 | * is_golem is to note that this is a golem spell. |
452 | */ |
443 | */ |
453 | object * |
444 | object * |
454 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
445 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
455 | { |
446 | { |
456 | archetype *atmp; |
|
|
457 | object *tmp = NULL, *prev = NULL, *head = NULL; |
447 | object *tmp = NULL, *prev = NULL, *head = NULL; |
458 | |
448 | |
459 | for (atmp = at; atmp; atmp = atmp->more) |
449 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
460 | { |
450 | { |
461 | tmp = arch_to_object (atmp); |
451 | tmp = arch_to_object (atmp); |
462 | |
452 | |
463 | if (atmp == at) |
453 | if (atmp == at) |
464 | { |
454 | { |
465 | if (!is_golem) |
455 | if (!is_golem) |
466 | SET_FLAG (tmp, FLAG_MONSTER); |
456 | SET_FLAG (tmp, FLAG_MONSTER); |
467 | |
457 | |
468 | tmp->set_owner (op); |
458 | tmp->set_owner (op); |
|
|
459 | |
469 | if (op->type == PLAYER) |
460 | if (op->type == PLAYER) |
470 | { |
461 | { |
471 | tmp->stats.exp = 0; |
462 | tmp->stats.exp = 0; |
472 | add_friendly_object (tmp); |
463 | add_friendly_object (tmp); |
473 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
474 | if (is_golem) |
464 | if (is_golem) |
475 | CLEAR_FLAG (tmp, FLAG_MONSTER); |
465 | CLEAR_FLAG (tmp, FLAG_MONSTER); |
476 | } |
466 | } |
477 | else |
467 | else |
478 | { |
468 | { |
… | |
… | |
483 | if (owner) |
473 | if (owner) |
484 | { /* For now, we transfer ownership */ |
474 | { /* For now, we transfer ownership */ |
485 | tmp->set_owner (owner); |
475 | tmp->set_owner (owner); |
486 | tmp->attack_movement = PETMOVE; |
476 | tmp->attack_movement = PETMOVE; |
487 | add_friendly_object (tmp); |
477 | add_friendly_object (tmp); |
488 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
489 | } |
478 | } |
490 | } |
479 | } |
491 | } |
480 | } |
492 | |
481 | |
493 | if (op->type != PLAYER || !is_golem) |
482 | if (op->type != PLAYER || !is_golem) |
… | |
… | |
503 | } |
492 | } |
504 | |
493 | |
505 | if (!head) |
494 | if (!head) |
506 | head = tmp; |
495 | head = tmp; |
507 | |
496 | |
508 | tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; |
497 | tmp->x = op->x + freearr_x[dir] + tmp->arch->x; |
509 | tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; |
498 | tmp->y = op->y + freearr_y[dir] + tmp->arch->y; |
510 | tmp->map = op->map; |
499 | tmp->map = op->map; |
511 | |
500 | |
512 | if (tmp->invisible) |
501 | if (tmp->invisible) |
513 | tmp->invisible = 0; |
502 | tmp->invisible = 0; |
514 | |
503 | |
… | |
… | |
546 | object *tmp; |
535 | object *tmp; |
547 | |
536 | |
548 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
537 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
549 | return; /* Has already been moved */ |
538 | return; /* Has already been moved */ |
550 | |
539 | |
551 | if (op->owner == NULL) |
540 | if (!op->owner) |
552 | { |
541 | { |
553 | LOG (llevDebug, "Golem without owner destructed.\n"); |
542 | LOG (llevDebug, "Golem without owner destructed.\n"); |
554 | op->remove (); |
|
|
555 | op->destroy (); |
543 | op->drop_and_destroy (); |
556 | return; |
544 | return; |
557 | } |
545 | } |
558 | |
546 | |
559 | /* It would be nice to have a cleaner way of what message to print |
547 | /* It would be nice to have a cleaner way of what message to print |
560 | * when the golem expires than these hard coded entries. |
548 | * when the golem expires than these hard coded entries. |
… | |
… | |
564 | if (--op->stats.hp < 0) |
552 | if (--op->stats.hp < 0) |
565 | { |
553 | { |
566 | if (op->msg) |
554 | if (op->msg) |
567 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
555 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
568 | |
556 | |
569 | op->owner->contr->ranges[range_golem] = 0; |
|
|
570 | remove_friendly_object (op); |
|
|
571 | op->remove (); |
|
|
572 | op->destroy (); |
557 | op->drop_and_destroy (); |
573 | return; |
558 | return; |
574 | } |
559 | } |
575 | |
560 | |
576 | /* Do golem attacks/movement for single & multisq golems. |
561 | /* Do golem attacks/movement for single & multisq golems. |
577 | * Assuming here that op is the 'head' object. Pass only op to |
562 | * Assuming here that op is the 'head' object. Pass only op to |
… | |
… | |
595 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
580 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
596 | |
581 | |
597 | if (mflags & P_OUT_OF_MAP) |
582 | if (mflags & P_OUT_OF_MAP) |
598 | continue; |
583 | continue; |
599 | |
584 | |
600 | for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above) |
585 | for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above) |
601 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
586 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
602 | break; |
587 | break; |
603 | |
588 | |
604 | /* We used to call will_hit_self to make sure we don't |
589 | /* We used to call will_hit_self to make sure we don't |
605 | * hit ourselves, but that didn't work, and I don't really |
590 | * hit ourselves, but that didn't work, and I don't really |
… | |
… | |
608 | * but since we are not trying to dereferance that pointer, |
593 | * but since we are not trying to dereferance that pointer, |
609 | * that isn't a problem. |
594 | * that isn't a problem. |
610 | */ |
595 | */ |
611 | if (victim && victim != op && victim->head != op) |
596 | if (victim && victim != op && victim->head != op) |
612 | { |
597 | { |
613 | |
|
|
614 | /* for golems with race fields, we don't attack |
598 | /* for golems with race fields, we don't attack |
615 | * aligned races |
599 | * aligned races |
616 | */ |
600 | */ |
617 | |
601 | |
618 | if (victim->race && op->race && strstr (op->race, victim->race)) |
602 | if (victim->race && op->race && op->race.contains (victim->race)) |
619 | { |
603 | { |
620 | if (op->owner) |
604 | if (op->owner) |
621 | new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); |
605 | new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); |
622 | } |
606 | } |
623 | else if (victim == op->owner) |
607 | else if (victim == op->owner) |
… | |
… | |
630 | attack_ob (victim, op); |
614 | attack_ob (victim, op); |
631 | made_attack = 1; |
615 | made_attack = 1; |
632 | } |
616 | } |
633 | } /* If victim */ |
617 | } /* If victim */ |
634 | } |
618 | } |
|
|
619 | |
635 | if (made_attack) |
620 | if (made_attack) |
636 | update_object (op, UP_OBJ_FACE); |
621 | update_object (op, UP_OBJ_FACE); |
637 | } |
622 | } |
638 | |
623 | |
639 | /* this is a really stupid function when you get down and |
624 | /* this is a really stupid function when you get down and |
… | |
… | |
645 | control_golem (object *op, int dir) |
630 | control_golem (object *op, int dir) |
646 | { |
631 | { |
647 | op->direction = dir; |
632 | op->direction = dir; |
648 | } |
633 | } |
649 | |
634 | |
650 | /* summon golem: summons a monster for 'op'. caster is the object |
635 | /* summon golem: summons a monster for 'op'. caster is the object |
651 | * casting the spell, dir is the direction to place the monster, |
636 | * casting the spell, dir is the direction to place the monster, |
652 | * at is the archetype of the monster, and spob is the spell |
637 | * at is the archetype of the monster, and spob is the spell |
653 | * object. At this stage, all spob is really used for is to |
638 | * object. At this stage, all spob is really used for is to |
654 | * adjust some values in the monster. |
639 | * adjust some values in the monster. |
655 | */ |
640 | */ |
… | |
… | |
661 | char buf[MAX_BUF]; |
646 | char buf[MAX_BUF]; |
662 | |
647 | |
663 | /* Because there can be different golem spells, player may want to |
648 | /* Because there can be different golem spells, player may want to |
664 | * 'lose' their old golem. |
649 | * 'lose' their old golem. |
665 | */ |
650 | */ |
666 | if (op->type == PLAYER && op->contr->ranges[range_golem]) |
651 | if (op->type == PLAYER && op->contr->golem) |
667 | { |
652 | { |
668 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
653 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
669 | op->contr->ranges[range_golem]->remove (); |
|
|
670 | op->contr->ranges[range_golem]->destroy (); |
654 | op->contr->golem->drop_and_destroy (); |
671 | op->contr->ranges[range_golem] = 0; |
655 | op->contr->golem = 0; |
672 | } |
656 | } |
673 | |
657 | |
674 | if (spob->other_arch) |
658 | if (spob->other_arch) |
675 | at = spob->other_arch; |
659 | at = spob->other_arch; |
676 | else if (spob->race) |
660 | else if (spob->race) |
… | |
… | |
696 | LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); |
680 | LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); |
697 | return 0; |
681 | return 0; |
698 | } |
682 | } |
699 | |
683 | |
700 | if (!dir) |
684 | if (!dir) |
701 | dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
685 | dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
702 | |
686 | |
703 | if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
687 | if (dir < 0 || at->blocked (op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
704 | { |
688 | { |
705 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
689 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
706 | return 0; |
690 | return 0; |
707 | } |
691 | } |
708 | |
692 | |
… | |
… | |
715 | } |
699 | } |
716 | |
700 | |
717 | if (op->type == PLAYER) |
701 | if (op->type == PLAYER) |
718 | { |
702 | { |
719 | tmp->type = GOLEM; |
703 | tmp->type = GOLEM; |
720 | tmp->set_owner (op); |
704 | op->contr->golem = tmp; |
|
|
705 | /* give the player control of the golem */ |
721 | set_spell_skill (op, caster, spob, tmp); |
706 | set_spell_skill (op, caster, spob, tmp); |
722 | op->contr->ranges[range_golem] = tmp; |
|
|
723 | /* give the player control of the golem */ |
|
|
724 | op->contr->shoottype = range_golem; |
|
|
725 | } |
|
|
726 | else |
|
|
727 | { |
|
|
728 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
|
|
729 | { |
|
|
730 | object *owner = op->owner; |
|
|
731 | |
|
|
732 | if (owner) |
|
|
733 | { /* For now, we transfer ownership */ |
|
|
734 | tmp->set_owner (owner); |
|
|
735 | tmp->attack_movement = PETMOVE; |
|
|
736 | add_friendly_object (tmp); |
|
|
737 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
738 | } |
|
|
739 | } |
|
|
740 | |
|
|
741 | SET_FLAG (tmp, FLAG_MONSTER); |
|
|
742 | } |
707 | } |
743 | |
708 | |
744 | /* make the speed positive. */ |
709 | /* make the speed positive. */ |
745 | tmp->speed = FABS (tmp->speed); |
710 | tmp->speed = fabs (tmp->speed); |
746 | |
711 | |
747 | /* This sets the level dependencies on dam and hp for monsters */ |
712 | /* This sets the level dependencies on dam and hp for monsters */ |
748 | /* players can't cope with too strong summonings. */ |
713 | /* players can't cope with too strong summonings. */ |
749 | /* but monsters can. reserve these for players. */ |
714 | /* but monsters can. reserve these for players. */ |
750 | if (op->type == PLAYER) |
715 | if (op->type == PLAYER) |
… | |
… | |
755 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
720 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
756 | else |
721 | else |
757 | tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); |
722 | tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); |
758 | |
723 | |
759 | tmp->speed += .02 * SP_level_range_adjust (caster, spob); |
724 | tmp->speed += .02 * SP_level_range_adjust (caster, spob); |
760 | tmp->speed = MIN (tmp->speed, 1.0); |
725 | tmp->speed = min (tmp->speed, 1.0); |
761 | |
726 | |
762 | if (spob->attacktype) |
727 | if (spob->attacktype) |
763 | tmp->attacktype = spob->attacktype; |
728 | tmp->attacktype = spob->attacktype; |
764 | } |
729 | } |
765 | |
730 | |
… | |
… | |
769 | |
734 | |
770 | /* make experience increase in proportion to the strength. |
735 | /* make experience increase in proportion to the strength. |
771 | * this is a bit simplistic - we are basically just looking at how |
736 | * this is a bit simplistic - we are basically just looking at how |
772 | * often the sp doubles and use that as the ratio. |
737 | * often the sp doubles and use that as the ratio. |
773 | */ |
738 | */ |
774 | tmp->stats.exp *= 1 + (MAX (spob->stats.maxgrace, spob->stats.sp) / caster_level (caster, spob)); |
739 | tmp->stats.exp *= 1 + max (spob->stats.maxgrace, spob->stats.sp) / casting_level (caster, spob); |
775 | tmp->speed_left = 0; |
740 | tmp->speed_left = 0; |
776 | tmp->direction = dir; |
741 | tmp->direction = dir; |
777 | |
742 | |
778 | /* Holy spell - some additional tailoring */ |
743 | /* Holy spell - some additional tailoring */ |
779 | if (god) |
744 | if (god) |
… | |
… | |
795 | if (!(tmp->attacktype & AT_PHYSICAL)) |
760 | if (!(tmp->attacktype & AT_PHYSICAL)) |
796 | tmp->attacktype |= AT_PHYSICAL; |
761 | tmp->attacktype |= AT_PHYSICAL; |
797 | } |
762 | } |
798 | |
763 | |
799 | insert_ob_in_map (tmp, tmp->map, op, 0); |
764 | insert_ob_in_map (tmp, tmp->map, op, 0); |
|
|
765 | |
800 | return 1; |
766 | return 1; |
801 | } |
767 | } |
802 | |
768 | |
803 | |
769 | |
804 | /*************************************************************************** |
770 | /*************************************************************************** |
… | |
… | |
810 | /* Returns a monster (chosen at random) that this particular player (and his |
776 | /* Returns a monster (chosen at random) that this particular player (and his |
811 | * god) find acceptable. This checks level, races allowed by god, etc |
777 | * god) find acceptable. This checks level, races allowed by god, etc |
812 | * to determine what is acceptable. |
778 | * to determine what is acceptable. |
813 | * This returns NULL if no match was found. |
779 | * This returns NULL if no match was found. |
814 | */ |
780 | */ |
815 | |
|
|
816 | object * |
781 | object * |
817 | choose_cult_monster (object *pl, object *god, int summon_level) |
782 | choose_cult_monster (object *pl, object *god, int summon_level) |
818 | { |
783 | { |
819 | char buf[MAX_BUF]; |
784 | char buf[MAX_BUF]; |
820 | const char *race; |
785 | const char *race; |
… | |
… | |
875 | * a valid entry, assuming nothing is available and quit. |
840 | * a valid entry, assuming nothing is available and quit. |
876 | */ |
841 | */ |
877 | if (!mon_nr) |
842 | if (!mon_nr) |
878 | return NULL; |
843 | return NULL; |
879 | |
844 | |
880 | mon_nr = rndm (0, mon_nr - 1); |
845 | mon_nr = rndm (mon_nr - 1); |
881 | for (tobl = list->member; tobl; tobl = tobl->next) |
846 | for (tobl = list->member; tobl; tobl = tobl->next) |
882 | { |
847 | { |
883 | otmp = tobl->ob; |
848 | otmp = tobl->ob; |
884 | if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) |
849 | if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) |
885 | continue; |
850 | continue; |
|
|
851 | |
886 | if (otmp->level <= summon_level && !mon_nr--) |
852 | if (otmp->level <= summon_level && !mon_nr--) |
887 | return otmp; |
853 | return otmp; |
888 | } |
854 | } |
|
|
855 | |
889 | /* This should not happen */ |
856 | /* This should not happen */ |
890 | LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); |
857 | LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); |
891 | return NULL; |
858 | return NULL; |
892 | } |
859 | } |
893 | |
860 | |
… | |
… | |
900 | |
867 | |
901 | if (spell_ob->other_arch) |
868 | if (spell_ob->other_arch) |
902 | summon_arch = spell_ob->other_arch; |
869 | summon_arch = spell_ob->other_arch; |
903 | else if (spell_ob->randomitems) |
870 | else if (spell_ob->randomitems) |
904 | { |
871 | { |
905 | int level = caster_level (caster, spell_ob); |
872 | int level = casting_level (caster, spell_ob); |
906 | treasure *tr, *lasttr = NULL; |
873 | treasure *tr, *lasttr = NULL; |
907 | |
874 | |
908 | shstr_cmp sparam (stringarg); |
875 | shstr_cmp sparam (stringarg); |
909 | |
876 | |
910 | /* In old code, this was a very convoluted for statement, |
877 | /* In old code, this was a very convoluted for statement, |
… | |
… | |
919 | if (level < tr->magic) |
886 | if (level < tr->magic) |
920 | break; |
887 | break; |
921 | |
888 | |
922 | lasttr = tr; |
889 | lasttr = tr; |
923 | |
890 | |
924 | if (tr->item->name == sparam) |
891 | if (tr->item->archname == sparam) |
925 | break; |
892 | break; |
926 | } |
893 | } |
927 | |
894 | |
928 | if (!lasttr) |
895 | if (!lasttr) |
929 | { |
896 | { |
… | |
… | |
933 | } |
900 | } |
934 | |
901 | |
935 | summon_arch = lasttr->item; |
902 | summon_arch = lasttr->item; |
936 | nrof = lasttr->nrof; |
903 | nrof = lasttr->nrof; |
937 | } |
904 | } |
938 | else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) |
905 | else if (spell_ob->race == shstr_GODCULTMON) |
939 | { |
906 | { |
940 | object *god = find_god (determine_god (op)), *mon, *owner; |
907 | object *god = find_god (determine_god (op)), *mon, *owner; |
941 | int summon_level, tries; |
908 | int summon_level, tries; |
942 | |
909 | |
943 | if (!god && ((owner = op->owner) != NULL)) |
910 | if (!god && ((owner = op->owner) != NULL)) |
… | |
… | |
952 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); |
919 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); |
953 | return 0; |
920 | return 0; |
954 | } |
921 | } |
955 | |
922 | |
956 | /* the summon level */ |
923 | /* the summon level */ |
957 | summon_level = caster_level (caster, spell_ob); |
924 | summon_level = casting_level (caster, spell_ob); |
958 | if (summon_level == 0) |
925 | if (summon_level == 0) |
959 | summon_level = 1; |
926 | summon_level = 1; |
960 | |
927 | |
961 | tries = 0; |
928 | tries = 0; |
962 | do |
929 | do |
… | |
… | |
971 | ndir = dir; |
938 | ndir = dir; |
972 | |
939 | |
973 | if (!ndir) |
940 | if (!ndir) |
974 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
941 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
975 | |
942 | |
976 | if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) |
943 | if (ndir < 0 || mon->blocked (op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) |
977 | { |
944 | { |
978 | ndir = -1; |
945 | ndir = -1; |
979 | if (++tries == 5) |
946 | if (++tries == 5) |
980 | { |
947 | { |
981 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
948 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
… | |
… | |
1004 | return 0; |
971 | return 0; |
1005 | } |
972 | } |
1006 | |
973 | |
1007 | for (i = 1; i <= nrof; i++) |
974 | for (i = 1; i <= nrof; i++) |
1008 | { |
975 | { |
1009 | archetype *atmp; |
|
|
1010 | object *prev = NULL, *head = NULL, *tmp; |
976 | object *prev = NULL, *head = NULL, *tmp; |
1011 | |
977 | |
1012 | if (dir) |
978 | if (dir) |
1013 | { |
979 | { |
1014 | ndir = dir; |
980 | ndir = dir; |
1015 | dir = absdir (dir + 1); |
981 | dir = absdir (dir + 1); |
1016 | } |
982 | } |
1017 | else |
983 | else |
1018 | ndir = find_free_spot (&summon_arch->clone, op->map, op->x, op->y, 1, SIZEOFFREE); |
984 | ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); |
1019 | |
985 | |
1020 | if (ndir > 0) |
986 | if (ndir > 0) |
1021 | { |
987 | { |
1022 | x = freearr_x[ndir]; |
988 | x = freearr_x[ndir]; |
1023 | y = freearr_y[ndir]; |
989 | y = freearr_y[ndir]; |
1024 | } |
990 | } |
1025 | |
991 | |
1026 | if (ndir == -1 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) |
992 | if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y)) |
1027 | { |
993 | { |
1028 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
994 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1029 | if (nrof > 1) |
995 | if (nrof > 1) |
1030 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
996 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
1031 | |
997 | |
1032 | return nrof > 1; |
998 | return nrof > 1; |
1033 | } |
999 | } |
1034 | |
1000 | |
1035 | for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) |
1001 | for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more) |
1036 | { |
1002 | { |
1037 | tmp = arch_to_object (atmp); |
1003 | tmp = arch_to_object (atmp); |
1038 | if (atmp == summon_arch) |
1004 | if (atmp == summon_arch) |
1039 | { |
1005 | { |
1040 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
1006 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
… | |
… | |
1048 | if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) |
1014 | if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) |
1049 | { |
1015 | { |
1050 | /* If this is not set, we make it friendly */ |
1016 | /* If this is not set, we make it friendly */ |
1051 | if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) |
1017 | if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) |
1052 | { |
1018 | { |
1053 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
1054 | add_friendly_object (tmp); |
1019 | add_friendly_object (tmp); |
1055 | tmp->stats.exp = 0; |
1020 | tmp->stats.exp = 0; |
1056 | |
1021 | |
1057 | if (spell_ob->attack_movement) |
1022 | if (spell_ob->attack_movement) |
1058 | tmp->attack_movement = spell_ob->attack_movement; |
1023 | tmp->attack_movement = spell_ob->attack_movement; |
… | |
… | |
1074 | tmp->head = head; |
1039 | tmp->head = head; |
1075 | prev->more = tmp; |
1040 | prev->more = tmp; |
1076 | } |
1041 | } |
1077 | |
1042 | |
1078 | prev = tmp; |
1043 | prev = tmp; |
1079 | tmp->x = op->x + x + tmp->arch->clone.x; |
1044 | tmp->x = op->x + x + tmp->arch->x; |
1080 | tmp->y = op->y + y + tmp->arch->clone.y; |
1045 | tmp->y = op->y + y + tmp->arch->y; |
1081 | tmp->map = op->map; |
1046 | tmp->map = op->map; |
1082 | } |
1047 | } |
1083 | |
1048 | |
1084 | head->direction = freedir[ndir]; |
1049 | head->direction = freedir[ndir]; |
1085 | head->stats.exp = 0; |
1050 | head->stats.exp = 0; |
… | |
… | |
1088 | if (head && head->randomitems) |
1053 | if (head && head->randomitems) |
1089 | { |
1054 | { |
1090 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1055 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1091 | |
1056 | |
1092 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1057 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1093 | SET_FLAG (tmp, FLAG_NO_DROP); |
1058 | SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); |
1094 | } |
1059 | } |
1095 | } /* for i < nrof */ |
1060 | } /* for i < nrof */ |
1096 | |
1061 | |
1097 | return 1; |
1062 | return 1; |
1098 | } |
|
|
1099 | |
|
|
1100 | /* recursively look through the owner property of objects until the real owner |
|
|
1101 | is found */ |
|
|
1102 | object * |
|
|
1103 | get_real_owner (object *ob) |
|
|
1104 | { |
|
|
1105 | object *realowner = ob; |
|
|
1106 | |
|
|
1107 | if (realowner == NULL) |
|
|
1108 | return NULL; |
|
|
1109 | |
|
|
1110 | while (realowner->owner != NULL) |
|
|
1111 | { |
|
|
1112 | realowner = realowner->owner; |
|
|
1113 | } |
|
|
1114 | return realowner; |
|
|
1115 | } |
1063 | } |
1116 | |
1064 | |
1117 | /* determines if checks so pets don't attack players or other pets should be |
1065 | /* determines if checks so pets don't attack players or other pets should be |
1118 | overruled by the arena petmode */ |
1066 | overruled by the arena petmode */ |
1119 | int |
1067 | int |
… | |
… | |
1125 | if ((target == NULL) || (pet == NULL) || (owner == NULL)) |
1073 | if ((target == NULL) || (pet == NULL) || (owner == NULL)) |
1126 | return 0; |
1074 | return 0; |
1127 | |
1075 | |
1128 | /* get the owners of itself and the target, this is to deal with pets of |
1076 | /* get the owners of itself and the target, this is to deal with pets of |
1129 | pets */ |
1077 | pets */ |
1130 | rowner = get_real_owner (owner); |
1078 | rowner = owner->outer_owner (); |
1131 | if (target->type != PLAYER) |
1079 | towner = target->is_player () ? 0 : target->outer_owner (); |
1132 | { |
|
|
1133 | towner = get_real_owner (target); |
|
|
1134 | } |
|
|
1135 | else |
|
|
1136 | { |
|
|
1137 | towner = 0; |
|
|
1138 | } |
|
|
1139 | |
1080 | |
1140 | /* if the pet has now owner, exit with error */ |
1081 | /* if the pet has now owner, exit with error */ |
1141 | if (rowner == NULL) |
1082 | if (!rowner) |
1142 | { |
1083 | { |
1143 | LOG (llevError, "Pet has no owner.\n"); |
1084 | LOG (llevError, "Pet has no owner.\n"); |
1144 | return 0; |
1085 | return 0; |
1145 | } |
1086 | } |
1146 | |
1087 | |
1147 | /* if the target is not a player, and has no owner, we shouldn't be here |
1088 | /* if the target is not a player, and has no owner, we shouldn't be here |
1148 | */ |
1089 | */ |
1149 | if ((towner == NULL) && (target->type != PLAYER)) |
1090 | if (!towner && !target->is_player ()) |
1150 | { |
1091 | { |
1151 | LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); |
1092 | LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); |
1152 | return 0; |
1093 | return 0; |
1153 | } |
1094 | } |
1154 | |
1095 | |
1155 | /* make sure that the owner is a player */ |
1096 | /* make sure that the owner is a player */ |
1156 | if (rowner->type != PLAYER) |
1097 | if (!rowner->is_player ()) |
1157 | return 0; |
1098 | return 0; |
1158 | |
1099 | |
1159 | /* abort if the petmode is not arena */ |
1100 | /* abort if the petmode is not arena */ |
1160 | if (rowner->contr->petmode != pet_arena) |
1101 | if (rowner->contr->petmode != pet_arena) |
1161 | return 0; |
1102 | return 0; |
… | |
… | |
1163 | /* abort if the pet, it's owner, or the target is not on battleground */ |
1104 | /* abort if the pet, it's owner, or the target is not on battleground */ |
1164 | if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) |
1105 | if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) |
1165 | return 0; |
1106 | return 0; |
1166 | |
1107 | |
1167 | /* if the target is a monster, make sure it's owner is not the same */ |
1108 | /* if the target is a monster, make sure it's owner is not the same */ |
1168 | if ((target->type != PLAYER) && (rowner == towner)) |
1109 | if (!target->is_player () && rowner == towner) |
1169 | return 0; |
1110 | return 0; |
1170 | |
1111 | |
1171 | /* check if the target is a player which affects how it will handle |
1112 | /* check if the target is a player which affects how it will handle |
1172 | parties */ |
1113 | parties */ |
1173 | if (target->type != PLAYER) |
1114 | if (!target->is_player ()) |
1174 | { |
1115 | { |
1175 | /* if the target is owned by a player make sure than make sure |
1116 | /* if the target is owned by a player make sure than make sure |
1176 | it's not in the same party */ |
1117 | it's not in the same party */ |
1177 | if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) |
1118 | if (towner->is_player () && rowner->contr->party) |
1178 | { |
|
|
1179 | if (rowner->contr->party == towner->contr->party) |
1119 | if (rowner->contr->party == towner->contr->party) |
1180 | return 0; |
1120 | return 0; |
1181 | } |
|
|
1182 | } |
1121 | } |
1183 | else |
1122 | else |
1184 | { |
1123 | { |
1185 | /* if the target is a player make sure than make sure it's not |
1124 | /* if the target is a player make sure than make sure it's not |
1186 | in the same party */ |
1125 | in the same party */ |
1187 | if (rowner->contr->party != NULL) |
1126 | if (rowner->contr->party) |
1188 | { |
|
|
1189 | if (rowner->contr->party == target->contr->party) |
1127 | if (rowner->contr->party == target->contr->party) |
1190 | return 0; |
1128 | return 0; |
1191 | } |
|
|
1192 | } |
1129 | } |
1193 | |
1130 | |
1194 | return 1; |
1131 | return 1; |
1195 | } |
1132 | } |
|
|
1133 | |