1 | /* |
1 | /* |
2 | * static char *rcsid_player_c = |
2 | * static char *rcsid_player_c = |
3 | * "$Id: player.C,v 1.14 2006/09/03 00:18:42 root Exp $"; |
3 | * "$Id: player.C,v 1.15 2006/09/04 11:08:00 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
197 | * Hopefully this will be less bugfree and simpler. |
197 | * Hopefully this will be less bugfree and simpler. |
198 | * Returns the player structure. If 'p' is null, |
198 | * Returns the player structure. If 'p' is null, |
199 | * we create a new one. Otherwise, we recycle |
199 | * we create a new one. Otherwise, we recycle |
200 | * the one that is passed. |
200 | * the one that is passed. |
201 | */ |
201 | */ |
202 | static player* get_player(player *p) { |
202 | static player * |
|
|
203 | get_player (player * p) |
|
|
204 | { |
203 | object *op=arch_to_object(get_player_archetype(NULL)); |
205 | object *op = arch_to_object (get_player_archetype (NULL)); |
204 | int i; |
206 | int i; |
205 | |
207 | |
206 | if (!p) { |
208 | if (!p) |
|
|
209 | { |
207 | p = new player; |
210 | p = new player; |
208 | |
211 | |
209 | /* This adds the player in the linked list. There is extra |
212 | /* This adds the player in the linked list. There is extra |
210 | * complexity here because we want to add the new player at the |
213 | * complexity here because we want to add the new player at the |
211 | * end of the list - there is in fact no compelling reason that |
214 | * end of the list - there is in fact no compelling reason that |
212 | * that needs to be done except for things like output of |
215 | * that needs to be done except for things like output of |
213 | * 'who'. |
216 | * 'who'. |
214 | */ |
217 | */ |
215 | player *tmp = first_player; |
218 | player *tmp = first_player; |
216 | while(tmp!=NULL&&tmp->next!=NULL) |
219 | while (tmp != NULL && tmp->next != NULL) |
217 | tmp=tmp->next; |
220 | tmp = tmp->next; |
218 | if(tmp!=NULL) |
221 | if (tmp != NULL) |
219 | tmp->next=p; |
222 | tmp->next = p; |
220 | else |
223 | else |
221 | first_player=p; |
224 | first_player = p; |
222 | |
225 | |
223 | p->next = NULL; |
226 | p->next = NULL; |
224 | } |
227 | } |
225 | |
228 | |
226 | /* Clears basically the entire player structure except |
229 | /* Clears basically the entire player structure except |
227 | * for next and socket. |
230 | * for next and socket. |
228 | */ |
231 | */ |
229 | memset (static_cast<player_memset *>(p), 0, sizeof (player_memset)); |
232 | memset (static_cast<player_pod *>(p), 0, sizeof (player_pod)); |
230 | p->attachable_init (); //HACK |
233 | p->attachable_clear (); |
231 | |
234 | |
232 | /* There are some elements we want initialized to non zero value - |
235 | /* There are some elements we want initialized to non zero value - |
233 | * we deal with that below this point. |
236 | * we deal with that below this point. |
234 | */ |
237 | */ |
235 | p->party=NULL; |
238 | p->party = NULL; |
236 | p->outputs_sync=16; /* Every 2 seconds */ |
239 | p->outputs_sync = 16; /* Every 2 seconds */ |
237 | p->outputs_count=8; /* Keeps present behaviour */ |
240 | p->outputs_count = 8; /* Keeps present behaviour */ |
238 | p->unapply = unapply_nochoice; |
241 | p->unapply = unapply_nochoice; |
239 | p->Swap_First = -1; |
242 | p->Swap_First = -1; |
240 | |
243 | |
241 | #ifdef AUTOSAVE |
244 | #ifdef AUTOSAVE |
242 | p->last_save_tick = 9999999; |
245 | p->last_save_tick = 9999999; |
243 | #endif |
246 | #endif |
244 | |
247 | |
245 | strcpy(p->savebed_map, first_map_path); /* Init. respawn position */ |
248 | strcpy (p->savebed_map, first_map_path); /* Init. respawn position */ |
246 | |
249 | |
247 | op->contr=p; /* this aren't yet in archetype */ |
250 | op->contr = p; /* this aren't yet in archetype */ |
248 | p->ob = op; |
251 | p->ob = op; |
249 | op->speed_left=0.5; |
252 | op->speed_left = 0.5; |
250 | op->speed=1.0; |
253 | op->speed = 1.0; |
251 | op->direction=5; /* So player faces south */ |
254 | op->direction = 5; /* So player faces south */ |
252 | op->stats.wc=2; |
255 | op->stats.wc = 2; |
253 | op->run_away = 25; /* Then we panick... */ |
256 | op->run_away = 25; /* Then we panick... */ |
254 | p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
257 | p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
255 | |
258 | |
256 | roll_stats(op); |
259 | roll_stats (op); |
257 | p->state=ST_ROLL_STAT; |
260 | p->state = ST_ROLL_STAT; |
258 | clear_los(op); |
261 | clear_los (op); |
259 | |
262 | |
260 | p->gen_sp_armour=10; |
263 | p->gen_sp_armour = 10; |
261 | p->last_speed= -1; |
264 | p->last_speed = -1; |
262 | p->shoottype=range_none; |
265 | p->shoottype = range_none; |
263 | p->bowtype=bow_normal; |
266 | p->bowtype = bow_normal; |
264 | p->petmode=pet_normal; |
267 | p->petmode = pet_normal; |
265 | p->listening=10; |
268 | p->listening = 10; |
266 | p->usekeys=containers; |
269 | p->usekeys = containers; |
267 | p->last_weapon_sp= -1; |
270 | p->last_weapon_sp = -1; |
268 | p->peaceful=1; /* default peaceful */ |
271 | p->peaceful = 1; /* default peaceful */ |
269 | p->do_los=1; |
272 | p->do_los = 1; |
270 | p->explore=0; |
273 | p->explore = 0; |
271 | p->no_shout=0; /* default can shout */ |
274 | p->no_shout = 0; /* default can shout */ |
272 | |
275 | |
273 | strncpy(p->title, op->arch->clone.name, sizeof(p->title)-1); |
276 | strncpy (p->title, op->arch->clone.name, sizeof (p->title) - 1); |
274 | p->title[sizeof(p->title)-1] = '\0'; |
277 | p->title[sizeof (p->title) - 1] = '\0'; |
275 | op->race = op->arch->clone.race; |
278 | op->race = op->arch->clone.race; |
276 | |
279 | |
277 | CLEAR_FLAG(op,FLAG_READY_SKILL); |
280 | CLEAR_FLAG (op, FLAG_READY_SKILL); |
278 | |
281 | |
279 | /* we need to clear these to -1 and not zero - otherwise, |
282 | /* we need to clear these to -1 and not zero - otherwise, |
280 | * if a player quits and starts a new character, we wont |
283 | * if a player quits and starts a new character, we wont |
281 | * send new values to the client, as things like exp start |
284 | * send new values to the client, as things like exp start |
282 | * at zero. |
285 | * at zero. |
283 | */ |
286 | */ |
284 | for (i=0; i < NUM_SKILLS; i++) { |
287 | for (i = 0; i < NUM_SKILLS; i++) |
|
|
288 | { |
285 | p->last_skill_exp[i] = -1; |
289 | p->last_skill_exp[i] = -1; |
286 | p->last_skill_ob[i] = NULL; |
290 | p->last_skill_ob[i] = NULL; |
287 | } |
291 | } |
288 | for (i=0; i < NROFATTACKS; i++) { |
292 | for (i = 0; i < NROFATTACKS; i++) |
|
|
293 | { |
289 | p->last_resist[i] = -1; |
294 | p->last_resist[i] = -1; |
290 | } |
295 | } |
291 | p->last_stats.exp = -1; |
296 | p->last_stats.exp = -1; |
292 | p->last_weight = (uint32)-1; |
297 | p->last_weight = (uint32) - 1; |
293 | |
298 | |
294 | p->socket.update_look=0; |
299 | p->socket.update_look = 0; |
295 | p->socket.look_position=0; |
300 | p->socket.look_position = 0; |
296 | return p; |
301 | return p; |
297 | } |
302 | } |
298 | |
|
|
299 | |
303 | |
300 | /* This loads the first map an puts the player on it. */ |
304 | /* This loads the first map an puts the player on it. */ |
301 | static void set_first_map(object *op) |
305 | static void set_first_map(object *op) |
302 | { |
306 | { |
303 | strcpy(op->contr->maplevel, first_map_path); |
307 | strcpy(op->contr->maplevel, first_map_path); |