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.1.1.1 by root, Fri Feb 3 07:14:35 2006 UTC vs.
Revision 1.1.1.2 by elmex, Wed Feb 22 18:03:23 2006 UTC

1/* 1/*
2 * static char *rcsid_player_c = 2 * static char *rcsid_player_c =
3 * "$Id: player.c,v 1.1.1.1 2006/02/03 07:14:35 root Exp $"; 3 * "$Id: player.c,v 1.1.1.2 2006/02/22 18:03:23 elmex 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
73 } 73 }
74 } 74 }
75 return found; 75 return found;
76 } 76 }
77 77
78void display_motd(object *op) { 78void display_motd(const object *op) {
79 char buf[MAX_BUF]; 79 char buf[MAX_BUF];
80 char motd[HUGE_BUF]; 80 char motd[HUGE_BUF];
81 FILE *fp; 81 FILE *fp;
82 int comp; 82 int comp;
83 int size; 83 int size;
96 } 96 }
97 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); 97 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
98 close_and_delete(fp, comp); 98 close_and_delete(fp, comp);
99} 99}
100 100
101void send_rules(object *op) { 101void send_rules(const object *op) {
102 char buf[MAX_BUF]; 102 char buf[MAX_BUF];
103 char rules[HUGE_BUF]; 103 char rules[HUGE_BUF];
104 FILE *fp; 104 FILE *fp;
105 int comp; 105 int comp;
106 int size; 106 int size;
124 } 124 }
125 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); 125 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
126 close_and_delete(fp, comp); 126 close_and_delete(fp, comp);
127} 127}
128 128
129void send_news(object *op) { 129void send_news(const object *op) {
130 char buf[MAX_BUF]; 130 char buf[MAX_BUF];
131 char news[HUGE_BUF]; 131 char news[HUGE_BUF];
132 char subject[MAX_BUF]; 132 char subject[MAX_BUF];
133 FILE *fp; 133 FILE *fp;
134 int comp; 134 int comp;
634 if(op->type==SPELL) { 634 if(op->type==SPELL) {
635 remove_ob(op); 635 remove_ob(op);
636 free_object(op); 636 free_object(op);
637 continue; 637 continue;
638 } 638 }
639 if(op->type==SKILL) { 639 else if(op->type==SKILL) {
640 SET_FLAG(op, FLAG_CAN_USE_SKILL); 640 SET_FLAG(op, FLAG_CAN_USE_SKILL);
641 op->stats.exp = 0; 641 op->stats.exp = 0;
642 op->level = 1; 642 op->level = 1;
643 } 643 }
644 /* lock all 'normal items by default */
645 else SET_FLAG(op, FLAG_INV_LOCKED);
644 } /* for loop of objects in player inv */ 646 } /* for loop of objects in player inv */
645 647
646 /* Need to set up the skill pointers */ 648 /* Need to set up the skill pointers */
647 link_player_skills(pl); 649 link_player_skills(pl);
648} 650}
1983 * going to try and move (not fire weapons). 1985 * going to try and move (not fire weapons).
1984 */ 1986 */
1985 1987
1986void move_player_attack(object *op, int dir) 1988void move_player_attack(object *op, int dir)
1987{ 1989{
1988 object *tmp, *mon; 1990 object *tmp, *mon, *tpl;
1989 sint16 nx=freearr_x[dir]+op->x,ny=freearr_y[dir]+op->y; 1991 sint16 nx, ny;
1990 int on_battleground; 1992 int on_battleground;
1991 mapstruct *m; 1993 mapstruct *m;
1992 1994
1995 if (op->contr->transport) tpl = op->contr->transport;
1996 else tpl = op;
1997 nx=freearr_x[dir]+tpl->x;
1998 ny=freearr_y[dir]+tpl->y;
1999
1993 on_battleground = op_on_battleground(op, NULL, NULL); 2000 on_battleground = op_on_battleground(tpl, NULL, NULL);
1994 2001
1995 /* If braced, or can't move to the square, and it is not out of the 2002 /* If braced, or can't move to the square, and it is not out of the
1996 * map, attack it. Note order of if statement is important - don't 2003 * map, attack it. Note order of if statement is important - don't
1997 * want to be calling move_ob if braced, because move_ob will move the 2004 * want to be calling move_ob if braced, because move_ob will move the
1998 * player. This is a pretty nasty hack, because if we could 2005 * player. This is a pretty nasty hack, because if we could
1999 * move to some space, it then means that if we are braced, we should 2006 * move to some space, it then means that if we are braced, we should
2000 * do nothing at all. As it is, if we are braced, we go through 2007 * do nothing at all. As it is, if we are braced, we go through
2001 * quite a bit of processing. However, it probably is less than what 2008 * quite a bit of processing. However, it probably is less than what
2002 * move_ob uses. 2009 * move_ob uses.
2003 */ 2010 */
2004 if ((op->contr->braced || !move_ob(op,dir,op)) && !out_of_map(op->map,nx,ny)) { 2011 if ((op->contr->braced || !move_ob(tpl,dir,tpl)) && !out_of_map(tpl->map,nx,ny)) {
2005 if (OUT_OF_REAL_MAP(op->map, nx, ny)) { 2012 if (OUT_OF_REAL_MAP(tpl->map, nx, ny)) {
2006 m = get_map_from_coord(op->map, &nx, &ny); 2013 m = get_map_from_coord(tpl->map, &nx, &ny);
2007 if (!m) return; /* Don't think this should happen */ 2014 if (!m) return; /* Don't think this should happen */
2008 } 2015 }
2009 else m =op->map; 2016 else m =tpl->map;
2010 2017
2011 if ((tmp=get_map_ob(m,nx,ny))==NULL) { 2018 if ((tmp=get_map_ob(m,nx,ny))==NULL) {
2012 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n");*/ 2019 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n");*/
2013 return; 2020 return;
2014 } 2021 }
2057 if ((op->type==PLAYER) && get_owner(mon)==op && 2064 if ((op->type==PLAYER) && get_owner(mon)==op &&
2058 (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) 2065 (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)))
2059 { 2066 {
2060 /* If we're braced, we don't want to switch places with it */ 2067 /* If we're braced, we don't want to switch places with it */
2061 if (op->contr->braced) return; 2068 if (op->contr->braced) return;
2062 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2069 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2063 (void) push_ob(mon,dir,op); 2070 (void) push_ob(mon,dir,op);
2064 if(op->contr->tmp_invis||op->hide) make_visible(op); 2071 if(op->contr->tmp_invis||op->hide) make_visible(op);
2065 return; 2072 return;
2066 } 2073 }
2067 2074
2072 */ 2079 */
2073 if ((mon->type==PLAYER || mon->enemy != op) && 2080 if ((mon->type==PLAYER || mon->enemy != op) &&
2074 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) && 2081 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) &&
2075 (op->contr->peaceful && !on_battleground)) { 2082 (op->contr->peaceful && !on_battleground)) {
2076 if (!op->contr->braced) { 2083 if (!op->contr->braced) {
2077 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2084 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2078 (void) push_ob(mon,dir,op); 2085 (void) push_ob(mon,dir,op);
2079 } else { 2086 } else {
2080 new_draw_info(0, 0,op,"You withhold your attack"); 2087 new_draw_info(0, 0,op,"You withhold your attack");
2081 } 2088 }
2082 if(op->contr->tmp_invis||op->hide) make_visible(op); 2089 if(op->contr->tmp_invis||op->hide) make_visible(op);
2131 } /* if player should attack something */ 2138 } /* if player should attack something */
2132} 2139}
2133 2140
2134int move_player(object *op,int dir) { 2141int move_player(object *op,int dir) {
2135 int pick; 2142 int pick;
2143 object *transport = op->contr->transport;
2136 2144
2137 if(op->map == NULL || op->map->in_memory != MAP_IN_MEMORY) 2145 if(!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
2138 return 0; 2146 return 0;
2139 2147
2140 /* Sanity check: make sure dir is valid */ 2148 /* Sanity check: make sure dir is valid */
2141 if ( ( dir < 0 ) || ( dir >= 9 ) ) { 2149 if ( ( dir < 0 ) || ( dir >= 9 ) ) {
2142 LOG( llevError, "move_player: invalid direction %d\n", dir); 2150 LOG( llevError, "move_player: invalid direction %d\n", dir);
2147 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir) 2155 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir)
2148 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2); 2156 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2);
2149 2157
2150 op->facing = dir; 2158 op->facing = dir;
2151 2159
2152 if(op->hide) do_hidden_move(op); 2160 if(!transport && op->hide) do_hidden_move(op);
2161
2162 if (transport) {
2163 /* transport->contr is set up for the person in charge of the boat.
2164 * if that isn't this person, he can't steer it, etc
2165 */
2166 if (transport->contr != op->contr) return 0;
2167
2168 /* Transport can't move. But update dir so it at least
2169 * will point in the same direction if player is running.
2170 */
2171 if (transport->speed_left < 0.0) {
2172 transport->direction = dir;
2173 op->direction = dir;
2174 return 0;
2175 }
2176 /* Remove transport speed. Give player just a little speed -
2177 * enough so that they will get an action again quickly.
2178 *
2179 */
2180 transport->speed_left -= 1.0;
2181 if (op->speed_left < 0.0) op->speed_left = -0.01;
2182
2183 }
2153 2184
2154 if(op->contr->fire_on) { 2185 if(op->contr->fire_on) {
2155 fire(op,dir); 2186 fire(op,dir);
2156 } 2187 }
2157 else move_player_attack(op,dir); 2188 else move_player_attack(op,dir);
2169 } 2200 }
2170 /* Update how the player looks. Use the facing, so direction may 2201 /* Update how the player looks. Use the facing, so direction may
2171 * get reset to zero. This allows for full animation capabilities 2202 * get reset to zero. This allows for full animation capabilities
2172 * for players. 2203 * for players.
2173 */ 2204 */
2174 animate_object(op, op->facing); 2205 if (!transport) animate_object(op, op->facing);
2175 return 0; 2206 return 0;
2176} 2207}
2177 2208
2178/* This is similar to handle_player, below, but is only used by the 2209/* This is similar to handle_player, below, but is only used by the
2179 * new client/server stuff. 2210 * new client/server stuff.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines