… | |
… | |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
|
|
25 | //+GPL |
|
|
26 | |
25 | #include <global.h> |
27 | #include <global.h> |
26 | #include <sproto.h> |
28 | #include <sproto.h> |
27 | #include <sounds.h> |
29 | #include <sounds.h> |
28 | #include <living.h> |
30 | #include <living.h> |
29 | #include <object.h> |
31 | #include <object.h> |
… | |
… | |
168 | observe = viewpoint = ob; |
170 | observe = viewpoint = ob; |
169 | |
171 | |
170 | deactivate (); |
172 | deactivate (); |
171 | } |
173 | } |
172 | |
174 | |
|
|
175 | //-GPL |
|
|
176 | |
173 | // the need for this function can be explained |
177 | // the need for this function can be explained |
174 | // by load_object not returning the object |
178 | // by load_object not returning the object |
175 | void |
179 | void |
176 | player::set_object (object *op) |
180 | player::set_object (object *op) |
177 | { |
181 | { |
… | |
… | |
223 | { |
227 | { |
224 | viewpoint = op ? op : (object *)observe; |
228 | viewpoint = op ? op : (object *)observe; |
225 | do_los = 1; |
229 | do_los = 1; |
226 | } |
230 | } |
227 | |
231 | |
|
|
232 | //+GPL |
|
|
233 | |
228 | player::player () |
234 | player::player () |
229 | { |
235 | { |
230 | /* There are some elements we want initialised to non zero value - |
236 | /* There are some elements we want initialised to non zero value - |
231 | * we deal with that below this point. |
237 | * we deal with that below this point. |
232 | */ |
238 | */ |
… | |
… | |
267 | { |
273 | { |
268 | /* Clear item stack */ |
274 | /* Clear item stack */ |
269 | free (stack_items); |
275 | free (stack_items); |
270 | } |
276 | } |
271 | |
277 | |
|
|
278 | /* |
|
|
279 | * get_player_archetype() return next player archetype from archetype |
|
|
280 | * list. Not very efficient routine, but used only creating new players. |
|
|
281 | * Note: there MUST be at least one player archetype! |
|
|
282 | */ |
|
|
283 | static archetype * |
|
|
284 | get_player_archetype (archetype *at) |
|
|
285 | { |
|
|
286 | // archetypes could have been reloaded |
|
|
287 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
288 | |
|
|
289 | if (!nat) |
|
|
290 | return at; |
|
|
291 | |
|
|
292 | archvec::iterator i = archetypes.find (nat); |
|
|
293 | |
|
|
294 | for (;;) |
|
|
295 | { |
|
|
296 | if (++i == archetypes.end ()) |
|
|
297 | i = archetypes.begin (); |
|
|
298 | else if (*i == at) |
|
|
299 | cleanup ("not a single player archetype found"); |
|
|
300 | |
|
|
301 | if ((*i)->type == PLAYER) |
|
|
302 | return *i; |
|
|
303 | } |
|
|
304 | } |
|
|
305 | |
272 | /* Tries to add player on the connection passed in ns. |
306 | /* Tries to add player on the connection passed in ns. |
273 | * All we can really get in this is some settings like host and display |
307 | * All we can really get in this is some settings like host and display |
274 | * mode. |
308 | * mode. |
275 | */ |
309 | */ |
276 | player * |
310 | player * |
… | |
… | |
285 | pl->ob->run_away = 25; /* Then we panick... */ |
319 | pl->ob->run_away = 25; /* Then we panick... */ |
286 | |
320 | |
287 | set_first_map (pl->ob); |
321 | set_first_map (pl->ob); |
288 | |
322 | |
289 | return pl; |
323 | return pl; |
290 | } |
|
|
291 | |
|
|
292 | /* |
|
|
293 | * get_player_archetype() return next player archetype from archetype |
|
|
294 | * list. Not very efficient routine, but used only creating new players. |
|
|
295 | * Note: there MUST be at least one player archetype! |
|
|
296 | */ |
|
|
297 | archetype * |
|
|
298 | get_player_archetype (archetype *at) |
|
|
299 | { |
|
|
300 | // archetypes could have been reloaded |
|
|
301 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
302 | |
|
|
303 | if (!nat) |
|
|
304 | return at; |
|
|
305 | |
|
|
306 | archvec::iterator i = archetypes.find (nat); |
|
|
307 | |
|
|
308 | for (;;) |
|
|
309 | { |
|
|
310 | if (++i == archetypes.end ()) |
|
|
311 | i = archetypes.begin (); |
|
|
312 | else if (*i == at) |
|
|
313 | cleanup ("not a single player archetype found"); |
|
|
314 | |
|
|
315 | if ((*i)->type == PLAYER) |
|
|
316 | return *i; |
|
|
317 | } |
|
|
318 | } |
324 | } |
319 | |
325 | |
320 | object * |
326 | object * |
321 | get_nearest_player (object *mon) |
327 | get_nearest_player (object *mon) |
322 | { |
328 | { |
… | |
… | |
1151 | } |
1157 | } |
1152 | |
1158 | |
1153 | return !stop; |
1159 | return !stop; |
1154 | } |
1160 | } |
1155 | |
1161 | |
|
|
1162 | /* routine for both players and monsters. We call this when |
|
|
1163 | * there is a possibility for our action distrubing our hiding |
|
|
1164 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
1165 | * "noise" instead. If we arent invisible to begin with, we |
|
|
1166 | * return 0. |
|
|
1167 | */ |
|
|
1168 | int |
|
|
1169 | action_makes_visible (object *op) |
|
|
1170 | { |
|
|
1171 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
1172 | { |
|
|
1173 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
1174 | { |
|
|
1175 | // artefact invisibility is permanent, but we still make noise |
|
|
1176 | // this is important for game-balance. |
|
|
1177 | if (op->contr) |
|
|
1178 | op->make_noise (); |
|
|
1179 | |
|
|
1180 | return 0; |
|
|
1181 | } |
|
|
1182 | |
|
|
1183 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
1184 | return 0; |
|
|
1185 | |
|
|
1186 | /* If monsters, they should become visible */ |
|
|
1187 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
1188 | { |
|
|
1189 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
1190 | return 1; |
|
|
1191 | } |
|
|
1192 | } |
|
|
1193 | |
|
|
1194 | return 0; |
|
|
1195 | } |
|
|
1196 | |
1156 | /* |
1197 | /* |
1157 | * Find an arrow in the inventory and after that |
1198 | * Find an arrow in the inventory and after that |
1158 | * in the right type container (quiver). Pointer to the |
1199 | * in the right type container (quiver). Pointer to the |
1159 | * found object is returned. |
1200 | * found object is returned. |
1160 | */ |
1201 | */ |
… | |
… | |
3011 | } |
3052 | } |
3012 | |
3053 | |
3013 | return 0; |
3054 | return 0; |
3014 | } |
3055 | } |
3015 | |
3056 | |
3016 | /* routine for both players and monsters. We call this when |
|
|
3017 | * there is a possibility for our action distrubing our hiding |
|
|
3018 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
3019 | * "noise" instead. If we arent invisible to begin with, we |
|
|
3020 | * return 0. |
|
|
3021 | */ |
|
|
3022 | int |
|
|
3023 | action_makes_visible (object *op) |
|
|
3024 | { |
|
|
3025 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
3026 | { |
|
|
3027 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
3028 | { |
|
|
3029 | // artefact invisibility is permanent, but we still make noise |
|
|
3030 | // this is important for game-balance. |
|
|
3031 | if (op->contr) |
|
|
3032 | op->make_noise (); |
|
|
3033 | |
|
|
3034 | return 0; |
|
|
3035 | } |
|
|
3036 | |
|
|
3037 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
3038 | return 0; |
|
|
3039 | |
|
|
3040 | /* If monsters, they should become visible */ |
|
|
3041 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
3042 | { |
|
|
3043 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
3044 | return 1; |
|
|
3045 | } |
|
|
3046 | } |
|
|
3047 | |
|
|
3048 | return 0; |
|
|
3049 | } |
|
|
3050 | |
|
|
3051 | /* op_on_battleground - checks if the given object op (usually |
3057 | /* op_on_battleground - checks if the given object op (usually |
3052 | * a player) is standing on a valid battleground-tile, |
3058 | * a player) is standing on a valid battleground-tile, |
3053 | * function returns TRUE/FALSE. If true x, y returns the battleground |
3059 | * function returns TRUE/FALSE. If true x, y returns the battleground |
3054 | * -exit-coord. (and if x, y not NULL) |
3060 | * -exit-coord. (and if x, y not NULL) |
3055 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
3061 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
… | |
… | |
3275 | |
3281 | |
3276 | if (pl->ranged_ob == ob) |
3282 | if (pl->ranged_ob == ob) |
3277 | pl->ranged_ob = 0; |
3283 | pl->ranged_ob = 0; |
3278 | } |
3284 | } |
3279 | |
3285 | |
|
|
3286 | //-GPL |
|
|
3287 | |
3280 | sint8 |
3288 | sint8 |
3281 | player::darkness_at (maptile *map, int x, int y) const |
3289 | player::darkness_at (maptile *map, int x, int y) const |
3282 | { |
3290 | { |
3283 | if (!ns) |
3291 | if (!ns) |
3284 | return LOS_BLOCKED; |
3292 | return LOS_BLOCKED; |