File: player.c

package info (click to toggle)
crossfire 1.11.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 24,456 kB
  • ctags: 7,800
  • sloc: ansic: 80,483; sh: 11,825; perl: 2,327; lex: 1,946; makefile: 1,149
file content (118 lines) | stat: -rw-r--r-- 3,312 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * static char *rcsid_player_c =
 *   "$Id: player.c 5866 2007-03-24 15:08:23Z ryo_saeba $";
 */

/*
    CrossFire, A Multiplayer game for X-windows

    Copyright (C) 2002 Mark Wedel & Crossfire Development Team
    Copyright (C) 1992 Frank Tore Johansen

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    The authors can be reached via e-mail at crossfire-devel@real-time.com
*/

#include <global.h>
#include <funcpoint.h>

/**
 * Clears player structure, including pointed object (through free_object).
 */
void free_player(player *pl) {

    client_spell *info;
    client_spell* next;

    if (first_player!=pl) {
        player *prev=first_player;
        while(prev!=NULL&&prev->next!=NULL&&prev->next!=pl)
            prev=prev->next;
        if(prev->next!=pl) {
            LOG(llevError,"Free_player: Can't find previous player.\n");
            exit(1);
        }
        prev->next=pl->next;
    } else
        first_player=pl->next;

    if(pl->ob != NULL) {
        if (!QUERY_FLAG(pl->ob, FLAG_REMOVED)) remove_ob(pl->ob);
        free_object(pl->ob);
    }
    /* Clear item stack (used by DMs only) */
    if (pl->stack_items)
        free( pl->stack_items );

    info = pl->spell_state;
    while ( info )
    {
        next = info->next;
        free( info );
        info = next;
    }

    free(pl->socket.faces_sent);

    CFREE(pl);
}


/**
 * Determine if the attacktype represented by the
 * specified attack-number is enabled for dragon players.
 * A dragon player (quetzal) can gain resistances for
 * all enabled attacktypes.
 */
int atnr_is_dragon_enabled(int attacknr) {
  if (attacknr == ATNR_MAGIC || attacknr == ATNR_FIRE ||
      attacknr == ATNR_ELECTRICITY || attacknr == ATNR_COLD ||
      attacknr == ATNR_ACID || attacknr == ATNR_POISON)
    return 1;
  return 0;
}

/**
 * Returns true if the adressed object 'ob' is a player
 * of the dragon race.
 */
int is_dragon_pl(const object* op) {
  if (op != NULL && op->type == PLAYER && op->arch != NULL
      && op->arch->clone.race != NULL &&
      strcmp(op->arch->clone.race, "dragon")==0)
    return 1;
  return 0;
}

/**
 * Gets the (client-side) spell state for specified spell. Will be created to empty state if not found.
 */
client_spell* get_client_spell_state(player* pl, object* spell)
{
    client_spell* info = pl->spell_state;
    while (info)
    {
        if (info->spell == spell)
            return info;
        info = info->next;
    }
    info = (client_spell*)malloc(sizeof(client_spell));
    memset(info, 0, sizeof(client_spell));
    info->next = pl->spell_state;
    info->spell = spell;
    pl->spell_state = info;
    return info;
}