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.7 by root, Sun Aug 27 16:15:13 2006 UTC vs.
Revision 1.9 by root, Tue Aug 29 07:34:00 2006 UTC

1/* 1/*
2 * static char *rcsid_player_c = 2 * static char *rcsid_player_c =
3 * "$Id: player.C,v 1.7 2006/08/27 16:15:13 root Exp $"; 3 * "$Id: player.C,v 1.9 2006/08/29 07:34: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
227 227
228 /* Clears basically the entire player structure except 228 /* Clears basically the entire player structure except
229 * for next and socket. 229 * for next and socket.
230 */ 230 */
231 memset (static_cast<player_memset *>(p), 0, sizeof (player_memset)); 231 memset (static_cast<player_memset *>(p), 0, sizeof (player_memset));
232 p->extendable_init (); //HACK 232 p->attachable_init (); //HACK
233 233
234 /* There are some elements we want initialized to non zero value - 234 /* There are some elements we want initialized to non zero value -
235 * we deal with that below this point. 235 * we deal with that below this point.
236 */ 236 */
237 p->party=NULL; 237 p->party=NULL;
2016 * going to try and move (not fire weapons). 2016 * going to try and move (not fire weapons).
2017 */ 2017 */
2018 2018
2019void move_player_attack(object *op, int dir) 2019void move_player_attack(object *op, int dir)
2020{ 2020{
2021 object *tmp, *mon, *tpl; 2021 object *tmp, *mon;
2022 sint16 nx, ny; 2022 sint16 nx, ny;
2023 int on_battleground; 2023 int on_battleground;
2024 mapstruct *m; 2024 mapstruct *m;
2025 2025
2026 if (op->contr->transport) tpl = op->contr->transport;
2027 else tpl = op;
2028 nx=freearr_x[dir]+tpl->x; 2026 nx=freearr_x[dir]+op->x;
2029 ny=freearr_y[dir]+tpl->y; 2027 ny=freearr_y[dir]+op->y;
2030 2028
2031 on_battleground = op_on_battleground(tpl, NULL, NULL); 2029 on_battleground = op_on_battleground(op, NULL, NULL);
2032 2030
2033 /* If braced, or can't move to the square, and it is not out of the 2031 /* If braced, or can't move to the square, and it is not out of the
2034 * map, attack it. Note order of if statement is important - don't 2032 * map, attack it. Note order of if statement is important - don't
2035 * want to be calling move_ob if braced, because move_ob will move the 2033 * want to be calling move_ob if braced, because move_ob will move the
2036 * player. This is a pretty nasty hack, because if we could 2034 * player. This is a pretty nasty hack, because if we could
2037 * move to some space, it then means that if we are braced, we should 2035 * move to some space, it then means that if we are braced, we should
2038 * do nothing at all. As it is, if we are braced, we go through 2036 * do nothing at all. As it is, if we are braced, we go through
2039 * quite a bit of processing. However, it probably is less than what 2037 * quite a bit of processing. However, it probably is less than what
2040 * move_ob uses. 2038 * move_ob uses.
2041 */ 2039 */
2042 if ((op->contr->braced || !move_ob(tpl,dir,tpl)) && !out_of_map(tpl->map,nx,ny)) { 2040 if ((op->contr->braced || !move_ob(op,dir,op)) && !out_of_map(op->map,nx,ny)) {
2043 if (OUT_OF_REAL_MAP(tpl->map, nx, ny)) { 2041 if (OUT_OF_REAL_MAP(op->map, nx, ny)) {
2044 m = get_map_from_coord(tpl->map, &nx, &ny); 2042 m = get_map_from_coord(op->map, &nx, &ny);
2045 if (!m) return; /* Don't think this should happen */ 2043 if (!m) return; /* Don't think this should happen */
2046 } 2044 }
2047 else m =tpl->map; 2045 else m =op->map;
2048 2046
2049 if ((tmp=get_map_ob(m,nx,ny))==NULL) { 2047 if ((tmp=get_map_ob(m,nx,ny))==NULL) {
2050 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n");*/ 2048 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n");*/
2051 return; 2049 return;
2052 } 2050 }
2105#endif 2103#endif
2106 && (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) 2104 && (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)))
2107 { 2105 {
2108 /* If we're braced, we don't want to switch places with it */ 2106 /* If we're braced, we don't want to switch places with it */
2109 if (op->contr->braced) return; 2107 if (op->contr->braced) return;
2110 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); 2108 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2111 (void) push_ob(mon,dir,op); 2109 (void) push_ob(mon,dir,op);
2112 if(op->contr->tmp_invis||op->hide) make_visible(op); 2110 if(op->contr->tmp_invis||op->hide) make_visible(op);
2113 return; 2111 return;
2114 } 2112 }
2115 2113
2127 op->contr->peaceful && 2125 op->contr->peaceful &&
2128#endif 2126#endif
2129 !on_battleground 2127 !on_battleground
2130 )) { 2128 )) {
2131 if (!op->contr->braced) { 2129 if (!op->contr->braced) {
2132 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER); 2130 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2133 (void) push_ob(mon,dir,op); 2131 (void) push_ob(mon,dir,op);
2134 } else { 2132 } else {
2135 new_draw_info(0, 0,op,"You withhold your attack"); 2133 new_draw_info(0, 0,op,"You withhold your attack");
2136 } 2134 }
2137 if(op->contr->tmp_invis||op->hide) make_visible(op); 2135 if(op->contr->tmp_invis||op->hide) make_visible(op);
2186 } /* if player should attack something */ 2184 } /* if player should attack something */
2187} 2185}
2188 2186
2189int move_player(object *op,int dir) { 2187int move_player(object *op,int dir) {
2190 int pick; 2188 int pick;
2191 object *transport = op->contr->transport;
2192 2189
2193 if(!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY)) 2190 if(op->map == NULL || op->map->in_memory != MAP_IN_MEMORY)
2194 return 0; 2191 return 0;
2195 2192
2196 /* Sanity check: make sure dir is valid */ 2193 /* Sanity check: make sure dir is valid */
2197 if ( ( dir < 0 ) || ( dir >= 9 ) ) { 2194 if ( ( dir < 0 ) || ( dir >= 9 ) ) {
2198 LOG( llevError, "move_player: invalid direction %d\n", dir); 2195 LOG( llevError, "move_player: invalid direction %d\n", dir);
2203 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir) 2200 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir)
2204 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2); 2201 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2);
2205 2202
2206 op->facing = dir; 2203 op->facing = dir;
2207 2204
2208 if(!transport && op->hide) do_hidden_move(op); 2205 if(op->hide) do_hidden_move(op);
2209
2210 if (transport) {
2211 /* transport->contr is set up for the person in charge of the boat.
2212 * if that isn't this person, he can't steer it, etc
2213 */
2214 if (transport->contr != op->contr) return 0;
2215
2216 /* Transport can't move. But update dir so it at least
2217 * will point in the same direction if player is running.
2218 */
2219 if (transport->speed_left < 0.0) {
2220 transport->direction = dir;
2221 op->direction = dir;
2222 return 0;
2223 }
2224 /* Remove transport speed. Give player just a little speed -
2225 * enough so that they will get an action again quickly.
2226 *
2227 */
2228 transport->speed_left -= 1.0;
2229 if (op->speed_left < 0.0) op->speed_left = -0.01;
2230
2231 }
2232 2206
2233 if(op->contr->fire_on) { 2207 if(op->contr->fire_on) {
2234 fire(op,dir); 2208 fire(op,dir);
2235 } 2209 }
2236 else move_player_attack(op,dir); 2210 else move_player_attack(op,dir);
2248 } 2222 }
2249 /* Update how the player looks. Use the facing, so direction may 2223 /* Update how the player looks. Use the facing, so direction may
2250 * get reset to zero. This allows for full animation capabilities 2224 * get reset to zero. This allows for full animation capabilities
2251 * for players. 2225 * for players.
2252 */ 2226 */
2253 if (!transport) animate_object(op, op->facing); 2227 animate_object(op, op->facing);
2254 return 0; 2228 return 0;
2255} 2229}
2256 2230
2257/* This is similar to handle_player, below, but is only used by the 2231/* This is similar to handle_player, below, but is only used by the
2258 * new client/server stuff. 2232 * new client/server stuff.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines