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 by root, Fri Feb 3 07:14:35 2006 UTC vs.
Revision 1.1.1.3 by elmex, Wed Mar 15 14:05:37 2006 UTC

1/* 1/*
2 * static char *rcsid_player_c = 2 * static char *rcsid_player_c =
3 * "$Id: player.c,v 1.1 2006/02/03 07:14:35 root Exp $"; 3 * "$Id: player.c,v 1.1.1.3 2006/03/15 14:05:37 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;
249 op->speed_left=0.5; 249 op->speed_left=0.5;
250 op->speed=1.0; 250 op->speed=1.0;
251 op->direction=5; /* So player faces south */ 251 op->direction=5; /* So player faces south */
252 op->stats.wc=2; 252 op->stats.wc=2;
253 op->run_away = 25; /* Then we panick... */ 253 op->run_away = 25; /* Then we panick... */
254 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
254 255
255 roll_stats(op); 256 roll_stats(op);
256 p->state=ST_ROLL_STAT; 257 p->state=ST_ROLL_STAT;
257 clear_los(op); 258 clear_los(op);
258 259
634 if(op->type==SPELL) { 635 if(op->type==SPELL) {
635 remove_ob(op); 636 remove_ob(op);
636 free_object(op); 637 free_object(op);
637 continue; 638 continue;
638 } 639 }
639 if(op->type==SKILL) { 640 else if(op->type==SKILL) {
640 SET_FLAG(op, FLAG_CAN_USE_SKILL); 641 SET_FLAG(op, FLAG_CAN_USE_SKILL);
641 op->stats.exp = 0; 642 op->stats.exp = 0;
642 op->level = 1; 643 op->level = 1;
643 } 644 }
645 /* lock all 'normal items by default */
646 else SET_FLAG(op, FLAG_INV_LOCKED);
644 } /* for loop of objects in player inv */ 647 } /* for loop of objects in player inv */
645 648
646 /* Need to set up the skill pointers */ 649 /* Need to set up the skill pointers */
647 link_player_skills(pl); 650 link_player_skills(pl);
648} 651}
1983 * going to try and move (not fire weapons). 1986 * going to try and move (not fire weapons).
1984 */ 1987 */
1985 1988
1986void move_player_attack(object *op, int dir) 1989void move_player_attack(object *op, int dir)
1987{ 1990{
1988 object *tmp, *mon; 1991 object *tmp, *mon, *tpl;
1989 sint16 nx=freearr_x[dir]+op->x,ny=freearr_y[dir]+op->y; 1992 sint16 nx, ny;
1990 int on_battleground; 1993 int on_battleground;
1991 mapstruct *m; 1994 mapstruct *m;
1992 1995
1996 if (op->contr->transport) tpl = op->contr->transport;
1997 else tpl = op;
1998 nx=freearr_x[dir]+tpl->x;
1999 ny=freearr_y[dir]+tpl->y;
2000
1993 on_battleground = op_on_battleground(op, NULL, NULL); 2001 on_battleground = op_on_battleground(tpl, NULL, NULL);
1994 2002
1995 /* If braced, or can't move to the square, and it is not out of the 2003 /* 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 2004 * 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 2005 * 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 2006 * 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 2007 * 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 2008 * 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 2009 * quite a bit of processing. However, it probably is less than what
2002 * move_ob uses. 2010 * move_ob uses.
2003 */ 2011 */
2004 if ((op->contr->braced || !move_ob(op,dir,op)) && !out_of_map(op->map,nx,ny)) { 2012 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)) { 2013 if (OUT_OF_REAL_MAP(tpl->map, nx, ny)) {
2006 m = get_map_from_coord(op->map, &nx, &ny); 2014 m = get_map_from_coord(tpl->map, &nx, &ny);
2007 if (!m) return; /* Don't think this should happen */ 2015 if (!m) return; /* Don't think this should happen */
2008 } 2016 }
2009 else m =op->map; 2017 else m =tpl->map;
2010 2018
2011 if ((tmp=get_map_ob(m,nx,ny))==NULL) { 2019 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");*/ 2020 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n");*/
2013 return; 2021 return;
2014 } 2022 }
2057 if ((op->type==PLAYER) && get_owner(mon)==op && 2065 if ((op->type==PLAYER) && get_owner(mon)==op &&
2058 (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) 2066 (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)))
2059 { 2067 {
2060 /* If we're braced, we don't want to switch places with it */ 2068 /* If we're braced, we don't want to switch places with it */
2061 if (op->contr->braced) return; 2069 if (op->contr->braced) return;
2062 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2070 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2063 (void) push_ob(mon,dir,op); 2071 (void) push_ob(mon,dir,op);
2064 if(op->contr->tmp_invis||op->hide) make_visible(op); 2072 if(op->contr->tmp_invis||op->hide) make_visible(op);
2065 return; 2073 return;
2066 } 2074 }
2067 2075
2072 */ 2080 */
2073 if ((mon->type==PLAYER || mon->enemy != op) && 2081 if ((mon->type==PLAYER || mon->enemy != op) &&
2074 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) && 2082 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) &&
2075 (op->contr->peaceful && !on_battleground)) { 2083 (op->contr->peaceful && !on_battleground)) {
2076 if (!op->contr->braced) { 2084 if (!op->contr->braced) {
2077 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2085 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2078 (void) push_ob(mon,dir,op); 2086 (void) push_ob(mon,dir,op);
2079 } else { 2087 } else {
2080 new_draw_info(0, 0,op,"You withhold your attack"); 2088 new_draw_info(0, 0,op,"You withhold your attack");
2081 } 2089 }
2082 if(op->contr->tmp_invis||op->hide) make_visible(op); 2090 if(op->contr->tmp_invis||op->hide) make_visible(op);
2131 } /* if player should attack something */ 2139 } /* if player should attack something */
2132} 2140}
2133 2141
2134int move_player(object *op,int dir) { 2142int move_player(object *op,int dir) {
2135 int pick; 2143 int pick;
2144 object *transport = op->contr->transport;
2136 2145
2137 if(op->map == NULL || op->map->in_memory != MAP_IN_MEMORY) 2146 if(!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
2138 return 0; 2147 return 0;
2139 2148
2140 /* Sanity check: make sure dir is valid */ 2149 /* Sanity check: make sure dir is valid */
2141 if ( ( dir < 0 ) || ( dir >= 9 ) ) { 2150 if ( ( dir < 0 ) || ( dir >= 9 ) ) {
2142 LOG( llevError, "move_player: invalid direction %d\n", dir); 2151 LOG( llevError, "move_player: invalid direction %d\n", dir);
2147 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir) 2156 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir)
2148 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2); 2157 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2);
2149 2158
2150 op->facing = dir; 2159 op->facing = dir;
2151 2160
2152 if(op->hide) do_hidden_move(op); 2161 if(!transport && op->hide) do_hidden_move(op);
2162
2163 if (transport) {
2164 /* transport->contr is set up for the person in charge of the boat.
2165 * if that isn't this person, he can't steer it, etc
2166 */
2167 if (transport->contr != op->contr) return 0;
2168
2169 /* Transport can't move. But update dir so it at least
2170 * will point in the same direction if player is running.
2171 */
2172 if (transport->speed_left < 0.0) {
2173 transport->direction = dir;
2174 op->direction = dir;
2175 return 0;
2176 }
2177 /* Remove transport speed. Give player just a little speed -
2178 * enough so that they will get an action again quickly.
2179 *
2180 */
2181 transport->speed_left -= 1.0;
2182 if (op->speed_left < 0.0) op->speed_left = -0.01;
2183
2184 }
2153 2185
2154 if(op->contr->fire_on) { 2186 if(op->contr->fire_on) {
2155 fire(op,dir); 2187 fire(op,dir);
2156 } 2188 }
2157 else move_player_attack(op,dir); 2189 else move_player_attack(op,dir);
2169 } 2201 }
2170 /* Update how the player looks. Use the facing, so direction may 2202 /* Update how the player looks. Use the facing, so direction may
2171 * get reset to zero. This allows for full animation capabilities 2203 * get reset to zero. This allows for full animation capabilities
2172 * for players. 2204 * for players.
2173 */ 2205 */
2174 animate_object(op, op->facing); 2206 if (!transport) animate_object(op, op->facing);
2175 return 0; 2207 return 0;
2176} 2208}
2177 2209
2178/* This is similar to handle_player, below, but is only used by the 2210/* This is similar to handle_player, below, but is only used by the
2179 * new client/server stuff. 2211 * new client/server stuff.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines