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