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.89 by root, Sun Jan 7 02:39:14 2007 UTC vs.
Revision 1.99 by root, Thu Jan 18 19:42:10 2007 UTC

180 180
181 players.insert (this); 181 players.insert (this);
182 ob->remove (); 182 ob->remove ();
183 ob->map = 0; 183 ob->map = 0;
184 ob->activate_recursive (); 184 ob->activate_recursive ();
185 CLEAR_FLAG (ob, FLAG_FRIENDLY);
186 add_friendly_object (ob);
185 enter_map (); 187 enter_map ();
186} 188}
187 189
188void 190void
189player::deactivate () 191player::deactivate ()
190{ 192{
191 if (!active) 193 if (!active)
192 return; 194 return;
193 195
194 terminate_all_pets (ob); 196 terminate_all_pets (ob);
197 remove_friendly_object (ob);
195 ob->deactivate_recursive (); 198 ob->deactivate_recursive ();
199 maplevel = ob->map->path;
196 ob->remove (); 200 ob->remove ();
197 ob->map = 0; 201 ob->map = 0;
202
203 // for weird reasons, this is often "ob", keeping a circular reference
204 ranges [range_skill] = 0;
198 205
199 players.erase (this); 206 players.erase (this);
200} 207}
201 208
202// connect the player with a specific client 209// connect the player with a specific client
205player::connect (client *ns) 212player::connect (client *ns)
206{ 213{
207 this->ns = ns; 214 this->ns = ns;
208 ns->pl = this; 215 ns->pl = this;
209 216
217 run_on = 0;
218 fire_on = 0;
219 ob->container = 0; //TODO: client-specific
220
210 ns->update_look = 0; 221 ns->update_look = 0;
211 ns->look_position = 0; 222 ns->look_position = 0;
212 223
213 clear_los (ob); 224 clear_los (ob);
225
226 ns->reset_stats ();
214 227
215 /* make sure he's a player -- needed because of class change. */ 228 /* make sure he's a player -- needed because of class change. */
216 ob->type = PLAYER; // we are paranoid 229 ob->type = PLAYER; // we are paranoid
217 ob->race = ob->arch->clone.race; 230 ob->race = ob->arch->clone.race;
218 231
252 skin = tmp; 265 skin = tmp;
253 266
254 set_dragon_name (ob, abil, skin); 267 set_dragon_name (ob, abil, skin);
255 } 268 }
256 269
257 CLEAR_FLAG (ob, FLAG_FRIENDLY);
258 add_friendly_object (ob);
259
260 LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &ob->name, ns->host);
261
262 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 270 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
263 271
264 esrv_new_player (this, ob->weight + ob->carrying); 272 esrv_new_player (this, ob->weight + ob->carrying);
265 273
266 ob->update_stats (); 274 ob->update_stats ();
280} 288}
281 289
282void 290void
283player::disconnect () 291player::disconnect ()
284{ 292{
285 //TODO: don't be so harsh and destroy :)
286 if (ns) 293 if (ns)
287 { 294 {
288 if (active) 295 if (active)
289 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); 296 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
290 297
291 INVOKE_PLAYER (DISCONNECT, this); 298 INVOKE_PLAYER (DISCONNECT, this);
292 299
300 ns->reset_stats ();
293 ns->pl = 0; 301 ns->pl = 0;
294 this->ns = 0; 302 this->ns = 0;
295 } 303 }
296 304
305 ob->container = 0; //TODO: client-specific
297 deactivate (); 306 deactivate ();
298} 307}
299 308
300// the need for this function can be explained 309// the need for this function can be explained
301// by load_object not returning the object 310// by load_object not returning the object
324 unapply = unapply_nochoice; 333 unapply = unapply_nochoice;
325 334
326 savebed_map = first_map_path; /* Init. respawn position */ 335 savebed_map = first_map_path; /* Init. respawn position */
327 336
328 gen_sp_armour = 10; 337 gen_sp_armour = 10;
329 last_speed = -1;
330 shoottype = range_none; 338 shoottype = range_none;
331 bowtype = bow_normal; 339 bowtype = bow_normal;
332 petmode = pet_normal; 340 petmode = pet_normal;
333 listening = 10; 341 listening = 10;
334 usekeys = containers; 342 usekeys = containers;
335 last_weapon_sp = -1;
336 peaceful = 1; /* default peaceful */ 343 peaceful = 1; /* default peaceful */
337 do_los = 1; 344 do_los = 1;
338
339 /* we need to clear these to -1 and not zero - otherwise,
340 * if a player quits and starts a new character, we wont
341 * send new values to the client, as things like exp start
342 * at zero.
343 */
344 for (int i = 0; i < NUM_SKILLS; i++)
345 last_skill_exp[i] = -1;
346
347 for (int i = 0; i < NROFATTACKS; i++)
348 last_resist[i] = -1;
349
350 last_stats.exp = -1;
351 last_weight = (uint32) - 1;
352} 345}
353 346
354void 347void
355player::do_destroy () 348player::do_destroy ()
356{ 349{
420 object *op = NULL; 413 object *op = NULL;
421 objectlink *ol; 414 objectlink *ol;
422 unsigned lastdist; 415 unsigned lastdist;
423 rv_vector rv; 416 rv_vector rv;
424 417
425 for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) 418 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next)
426 { 419 {
427 /* We should not find free objects on this friendly list, but it 420 /* We should not find free objects on this friendly list, but it
428 * does periodically happen. Given that, lets deal with it. 421 * does periodically happen. Given that, lets deal with it.
429 * While unlikely, it is possible the next object on the friendly 422 * While unlikely, it is possible the next object on the friendly
430 * list is also free, so encapsulate this in a while loop. 423 * list is also free, so encapsulate this in a while loop.
434 object *tmp = ol->ob; 427 object *tmp = ol->ob;
435 428
436 /* Can't do much more other than log the fact, because the object 429 /* Can't do much more other than log the fact, because the object
437 * itself will have been cleared. 430 * itself will have been cleared.
438 */ 431 */
439 LOG (llevDebug, "get_nearest_player: Found free/non friendly object on friendly list\n"); 432 LOG (llevDebug, "get_nearest_player: Found free/non friendly object '%s' on friendly list\n",
433 tmp->debug_desc ());
440 ol = ol->next; 434 ol = ol->next;
441 remove_friendly_object (tmp); 435 remove_friendly_object (tmp);
442 if (!ol) 436 if (!ol)
443 return op; 437 return op;
444 } 438 }
762roll_stat (void) 756roll_stat (void)
763{ 757{
764 int a[4], i, j, k; 758 int a[4], i, j, k;
765 759
766 for (i = 0; i < 4; i++) 760 for (i = 0; i < 4; i++)
767 a[i] = (int) RANDOM () % 6 + 1; 761 a[i] = (int) rndm (6) + 1;
768 762
769 for (i = 0, j = 0, k = 7; i < 4; i++) 763 for (i = 0, j = 0, k = 7; i < 4; i++)
770 if (a[i] < k) 764 if (a[i] < k)
771 k = a[i], j = i; 765 k = a[i], j = i;
772 766
902 * to save here. 896 * to save here.
903 */ 897 */
904 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &op->name); 898 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &op->name);
905 make_path_to_file (buf); 899 make_path_to_file (buf);
906 900
907#ifdef AUTOSAVE
908 op->contr->last_save_tick = pticks;
909#endif
910 start_info (op); 901 start_info (op);
911 CLEAR_FLAG (op, FLAG_WIZ); 902 CLEAR_FLAG (op, FLAG_WIZ);
912 give_initial_items (op, op->randomitems); 903 give_initial_items (op, op->randomitems);
913 link_player_skills (op); 904 link_player_skills (op);
914 esrv_send_inventory (op, op); 905 esrv_send_inventory (op, op);
1862 { 1853 {
1863 if (op->type == PLAYER) 1854 if (op->type == PLAYER)
1864 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use."); 1855 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use.");
1865 return; 1856 return;
1866 } 1857 }
1858
1867 (void) do_skill (op, op, op->chosen_skill, dir, NULL); 1859 do_skill (op, op, op->chosen_skill, dir, NULL);
1868 return; 1860 return;
1869 case range_builder: 1861 case range_builder:
1870 apply_map_builder (op, dir); 1862 apply_map_builder (op, dir);
1871 return; 1863 return;
1872 default: 1864 default:
2219 return 0; 2211 return 0;
2220 } 2212 }
2221 2213
2222 /* peterm: added following line */ 2214 /* peterm: added following line */
2223 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2215 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2224 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 2216 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2225 2217
2226 op->facing = dir; 2218 op->facing = dir;
2227 2219
2228 if (op->hide) 2220 if (op->hide)
2229 do_hidden_move (op); 2221 do_hidden_move (op);
2990 tmp->x = op->x, tmp->y = op->y; 2982 tmp->x = op->x, tmp->y = op->y;
2991 if (tmp->type == CONTAINER) 2983 if (tmp->type == CONTAINER)
2992 { /* empty container to ground */ 2984 { /* empty container to ground */
2993 loot_object (tmp); 2985 loot_object (tmp);
2994 } 2986 }
2995 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 2987 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3))))
2996 { 2988 {
2997 if (tmp->nrof > 1) 2989 if (tmp->nrof > 1)
2998 { 2990 {
2999 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2991 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3000 tmp2->destroy (); 2992 tmp2->destroy ();
3534 * not readied. 3526 * not readied.
3535 */ 3527 */
3536void 3528void
3537player_unready_range_ob (player *pl, object *ob) 3529player_unready_range_ob (player *pl, object *ob)
3538{ 3530{
3539 rangetype i;
3540
3541 for (i = (rangetype) 0; i < range_size; i = (rangetype) ((int) i + 1)) 3531 for (rangetype i = (rangetype) 0; i < range_size; i = (rangetype) ((int) i + 1))
3542 {
3543 if (pl->ranges[i] == ob) 3532 if (pl->ranges[i] == ob)
3544 { 3533 {
3545 pl->ranges[i] = NULL; 3534 pl->ranges[i] = 0;
3546 if (pl->shoottype == i) 3535 if (pl->shoottype == i)
3547 {
3548 pl->shoottype = range_none; 3536 pl->shoottype = range_none;
3549 }
3550 } 3537 }
3551 }
3552} 3538}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines