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.5 by root, Fri Feb 10 04:35:33 2006 UTC vs.
Revision 1.6 by elmex, Wed Feb 22 18:53:56 2006 UTC

1/* 1/*
2 * static char *rcsid_player_c = 2 * static char *rcsid_player_c =
3 * "$Id: player.c,v 1.5 2006/02/10 04:35:33 root Exp $"; 3 * "$Id: player.c,v 1.6 2006/02/22 18:53:56 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
77 } 77 }
78 } 78 }
79 return found; 79 return found;
80 } 80 }
81 81
82void display_motd(object *op) { 82void display_motd(const object *op) {
83 char buf[MAX_BUF]; 83 char buf[MAX_BUF];
84 char motd[HUGE_BUF]; 84 char motd[HUGE_BUF];
85 FILE *fp; 85 FILE *fp;
86 int comp; 86 int comp;
87 int size; 87 int size;
100 } 100 }
101 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); 101 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
102 close_and_delete(fp, comp); 102 close_and_delete(fp, comp);
103} 103}
104 104
105void send_rules(object *op) { 105void send_rules(const object *op) {
106 char buf[MAX_BUF]; 106 char buf[MAX_BUF];
107 char rules[HUGE_BUF]; 107 char rules[HUGE_BUF];
108 FILE *fp; 108 FILE *fp;
109 int comp; 109 int comp;
110 int size; 110 int size;
128 } 128 }
129 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); 129 draw_ext_info(NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
130 close_and_delete(fp, comp); 130 close_and_delete(fp, comp);
131} 131}
132 132
133void send_news(object *op) { 133void send_news(const object *op) {
134 char buf[MAX_BUF]; 134 char buf[MAX_BUF];
135 char news[HUGE_BUF]; 135 char news[HUGE_BUF];
136 char subject[MAX_BUF]; 136 char subject[MAX_BUF];
137 FILE *fp; 137 FILE *fp;
138 int comp; 138 int comp;
638 if(op->type==SPELL) { 638 if(op->type==SPELL) {
639 remove_ob(op); 639 remove_ob(op);
640 free_object(op); 640 free_object(op);
641 continue; 641 continue;
642 } 642 }
643 if(op->type==SKILL) { 643 else if(op->type==SKILL) {
644 SET_FLAG(op, FLAG_CAN_USE_SKILL); 644 SET_FLAG(op, FLAG_CAN_USE_SKILL);
645 op->stats.exp = 0; 645 op->stats.exp = 0;
646 op->level = 1; 646 op->level = 1;
647 } 647 }
648 /* lock all 'normal items by default */
649 else SET_FLAG(op, FLAG_INV_LOCKED);
648 } /* for loop of objects in player inv */ 650 } /* for loop of objects in player inv */
649 651
650 /* Need to set up the skill pointers */ 652 /* Need to set up the skill pointers */
651 link_player_skills(pl); 653 link_player_skills(pl);
652} 654}
1987 * going to try and move (not fire weapons). 1989 * going to try and move (not fire weapons).
1988 */ 1990 */
1989 1991
1990void move_player_attack(object *op, int dir) 1992void move_player_attack(object *op, int dir)
1991{ 1993{
1992 object *tmp, *mon; 1994 object *tmp, *mon, *tpl;
1993 sint16 nx=freearr_x[dir]+op->x,ny=freearr_y[dir]+op->y; 1995 sint16 nx, ny;
1994 int on_battleground; 1996 int on_battleground;
1995 mapstruct *m; 1997 mapstruct *m;
1996 1998
1999 if (op->contr->transport) tpl = op->contr->transport;
2000 else tpl = op;
2001 nx=freearr_x[dir]+tpl->x;
2002 ny=freearr_y[dir]+tpl->y;
2003
1997 on_battleground = op_on_battleground(op, NULL, NULL); 2004 on_battleground = op_on_battleground(tpl, NULL, NULL);
1998 2005
1999 /* If braced, or can't move to the square, and it is not out of the 2006 /* If braced, or can't move to the square, and it is not out of the
2000 * map, attack it. Note order of if statement is important - don't 2007 * map, attack it. Note order of if statement is important - don't
2001 * want to be calling move_ob if braced, because move_ob will move the 2008 * want to be calling move_ob if braced, because move_ob will move the
2002 * player. This is a pretty nasty hack, because if we could 2009 * player. This is a pretty nasty hack, because if we could
2003 * move to some space, it then means that if we are braced, we should 2010 * move to some space, it then means that if we are braced, we should
2004 * do nothing at all. As it is, if we are braced, we go through 2011 * do nothing at all. As it is, if we are braced, we go through
2005 * quite a bit of processing. However, it probably is less than what 2012 * quite a bit of processing. However, it probably is less than what
2006 * move_ob uses. 2013 * move_ob uses.
2007 */ 2014 */
2008 if ((op->contr->braced || !move_ob(op,dir,op)) && !out_of_map(op->map,nx,ny)) { 2015 if ((op->contr->braced || !move_ob(tpl,dir,tpl)) && !out_of_map(tpl->map,nx,ny)) {
2009 if (OUT_OF_REAL_MAP(op->map, nx, ny)) { 2016 if (OUT_OF_REAL_MAP(tpl->map, nx, ny)) {
2010 m = get_map_from_coord(op->map, &nx, &ny); 2017 m = get_map_from_coord(tpl->map, &nx, &ny);
2011 if (!m) return; /* Don't think this should happen */ 2018 if (!m) return; /* Don't think this should happen */
2012 } 2019 }
2013 else m =op->map; 2020 else m =tpl->map;
2014 2021
2015 if ((tmp=get_map_ob(m,nx,ny))==NULL) { 2022 if ((tmp=get_map_ob(m,nx,ny))==NULL) {
2016 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n");*/ 2023 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n");*/
2017 return; 2024 return;
2018 } 2025 }
2071#endif 2078#endif
2072 && (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) 2079 && (QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)))
2073 { 2080 {
2074 /* If we're braced, we don't want to switch places with it */ 2081 /* If we're braced, we don't want to switch places with it */
2075 if (op->contr->braced) return; 2082 if (op->contr->braced) return;
2076 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2083 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2077 (void) push_ob(mon,dir,op); 2084 (void) push_ob(mon,dir,op);
2078 if(op->contr->tmp_invis||op->hide) make_visible(op); 2085 if(op->contr->tmp_invis||op->hide) make_visible(op);
2079 return; 2086 return;
2080 } 2087 }
2081 2088
2086 */ 2093 */
2087 if ((mon->type==PLAYER || mon->enemy != op) && 2094 if ((mon->type==PLAYER || mon->enemy != op) &&
2088 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) && 2095 (mon->type==PLAYER || QUERY_FLAG(mon,FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY)) &&
2089 (op->contr->peaceful && !on_battleground)) { 2096 (op->contr->peaceful && !on_battleground)) {
2090 if (!op->contr->braced) { 2097 if (!op->contr->braced) {
2091 play_sound_map(op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2098 play_sound_map(tpl->map, tpl->x, tpl->y, SOUND_PUSH_PLAYER);
2092 (void) push_ob(mon,dir,op); 2099 (void) push_ob(mon,dir,op);
2093 } else { 2100 } else {
2094 new_draw_info(0, 0,op,"You withhold your attack"); 2101 new_draw_info(0, 0,op,"You withhold your attack");
2095 } 2102 }
2096 if(op->contr->tmp_invis||op->hide) make_visible(op); 2103 if(op->contr->tmp_invis||op->hide) make_visible(op);
2145 } /* if player should attack something */ 2152 } /* if player should attack something */
2146} 2153}
2147 2154
2148int move_player(object *op,int dir) { 2155int move_player(object *op,int dir) {
2149 int pick; 2156 int pick;
2157 object *transport = op->contr->transport;
2150 2158
2151 if(op->map == NULL || op->map->in_memory != MAP_IN_MEMORY) 2159 if(!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
2152 return 0; 2160 return 0;
2153 2161
2154 /* Sanity check: make sure dir is valid */ 2162 /* Sanity check: make sure dir is valid */
2155 if ( ( dir < 0 ) || ( dir >= 9 ) ) { 2163 if ( ( dir < 0 ) || ( dir >= 9 ) ) {
2156 LOG( llevError, "move_player: invalid direction %d\n", dir); 2164 LOG( llevError, "move_player: invalid direction %d\n", dir);
2161 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir) 2169 if(QUERY_FLAG(op,FLAG_CONFUSED) && dir)
2162 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2); 2170 dir = absdir(dir + RANDOM()%3 + RANDOM()%3 - 2);
2163 2171
2164 op->facing = dir; 2172 op->facing = dir;
2165 2173
2166 if(op->hide) do_hidden_move(op); 2174 if(!transport && op->hide) do_hidden_move(op);
2175
2176 if (transport) {
2177 /* transport->contr is set up for the person in charge of the boat.
2178 * if that isn't this person, he can't steer it, etc
2179 */
2180 if (transport->contr != op->contr) return 0;
2181
2182 /* Transport can't move. But update dir so it at least
2183 * will point in the same direction if player is running.
2184 */
2185 if (transport->speed_left < 0.0) {
2186 transport->direction = dir;
2187 op->direction = dir;
2188 return 0;
2189 }
2190 /* Remove transport speed. Give player just a little speed -
2191 * enough so that they will get an action again quickly.
2192 *
2193 */
2194 transport->speed_left -= 1.0;
2195 if (op->speed_left < 0.0) op->speed_left = -0.01;
2196
2197 }
2167 2198
2168 if(op->contr->fire_on) { 2199 if(op->contr->fire_on) {
2169 fire(op,dir); 2200 fire(op,dir);
2170 } 2201 }
2171 else move_player_attack(op,dir); 2202 else move_player_attack(op,dir);
2183 } 2214 }
2184 /* Update how the player looks. Use the facing, so direction may 2215 /* Update how the player looks. Use the facing, so direction may
2185 * get reset to zero. This allows for full animation capabilities 2216 * get reset to zero. This allows for full animation capabilities
2186 * for players. 2217 * for players.
2187 */ 2218 */
2188 animate_object(op, op->facing); 2219 if (!transport) animate_object(op, op->facing);
2189 return 0; 2220 return 0;
2190} 2221}
2191 2222
2192/* This is similar to handle_player, below, but is only used by the 2223/* This is similar to handle_player, below, but is only used by the
2193 * new client/server stuff. 2224 * new client/server stuff.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines