ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.237 by root, Thu Nov 5 15:18:26 2009 UTC vs.
Revision 1.240 by root, Fri Nov 6 12:49:19 2009 UTC

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
175void 179void
176player::set_object (object *op) 180player::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
228player::player () 234player::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 */
283static archetype *
284get_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 */
276player * 310player *
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 */
297archetype *
298get_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
320object * 326object *
321get_nearest_player (object *mon) 327get_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 */
1168static int
1169action_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 */
1161object * 1202static object *
1162find_arrow (object *op, const char *type) 1203find_arrow (object *op, const char *type)
1163{ 1204{
1164 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1205 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1165 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1206 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1166 return splay (tmp); 1207 return splay (tmp);
1180 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1221 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1181 * against the target. A full test is not performed, simply a basic test 1222 * against the target. A full test is not performed, simply a basic test
1182 * of resistances. The archer is making a quick guess at what he sees down 1223 * of resistances. The archer is making a quick guess at what he sees down
1183 * the hall. Failing that it does it's best to pick the highest plus arrow. 1224 * the hall. Failing that it does it's best to pick the highest plus arrow.
1184 */ 1225 */
1185object * 1226static object *
1186find_better_arrow (object *op, object *target, shstr_cmp type, int *better) 1227find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1187{ 1228{
1188 object *tmp = NULL, *arrow, *ntmp; 1229 object *tmp = NULL, *arrow, *ntmp;
1189 int attacknum, attacktype, betterby = 0, i; 1230 int attacknum, attacktype, betterby = 0, i;
1190 1231
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 */
3022int
3023action_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
3280sint8 3288sint8
3281player::darkness_at (maptile *map, int x, int y) const 3289player::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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines