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