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