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.249 by root, Sun Nov 29 17:41:08 2009 UTC vs.
Revision 1.254 by root, Fri Mar 26 00:05:45 2010 UTC

110 link_skills (); 110 link_skills ();
111 111
112 assign (title, ob->arch->object::name); 112 assign (title, ob->arch->object::name);
113 113
114 /* if it's a dragon player, set the correct title here */ 114 /* if it's a dragon player, set the correct title here */
115 if (is_dragon_pl (ob)) 115 if (ob->is_dragon ())
116 { 116 {
117 object *tmp, *abil = 0, *skin = 0; 117 object *tmp, *abil = 0, *skin = 0;
118 118
119 for (tmp = ob->inv; tmp; tmp = tmp->below) 119 for (tmp = ob->inv; tmp; tmp = tmp->below)
120 if (tmp->type == FORCE) 120 if (tmp->type == FORCE)
134 134
135 ns->floorbox_update (); 135 ns->floorbox_update ();
136 esrv_send_inventory (ob, ob); 136 esrv_send_inventory (ob, ob);
137 esrv_add_spells (this, 0); 137 esrv_add_spells (this, 0);
138 138
139 activate ();
140
141 INVOKE_PLAYER (CONNECT, this);
142 INVOKE_PLAYER (LOGIN, this);
143}
144
145void
146player::disconnect ()
147{
148 if (ob)
149 {
150 ob->close_container (); //TODO: client-specific
151 ob->drop_unpaid_items ();
152 }
153
154 if (ns)
155 {
156 if (active)
157 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
158
159 INVOKE_PLAYER (DISCONNECT, this);
160
161 ns->reset_stats ();
162 ns->pl = 0;
163 ns = 0;
164 }
165
166 // this is important for the player scheduler to get the correct refcount
167 // when ns = 0
168 observe = viewpoint = ob;
169
170 deactivate ();
171}
172
173//-GPL
174
175// the need for this function can be explained
176// by load_object not returning the object
177void
178player::set_object (object *op)
179{
180 ob = observe = viewpoint = op;
181 ob->contr = this; /* this aren't yet in archetype */
182
183 ob->speed = 1.0f;
184 ob->speed_left = 0.5f;
185
186 ob->direction = 5; /* So player faces south */
187
188 ob->flag [FLAG_READY_WEAPON] = false; 139 ob->flag [FLAG_READY_WEAPON] = false;
189 ob->flag [FLAG_READY_SKILL] = false; 140 ob->flag [FLAG_READY_SKILL] = false;
190 ob->flag [FLAG_READY_BOW] = false; 141 ob->flag [FLAG_READY_BOW] = false;
191 142
192 for (object *op = ob->inv; op; op = op->below) 143 for (object *op = ob->inv; op; op = op->below)
193 if (op->flag [FLAG_APPLIED]) 144 if (op->flag [FLAG_APPLIED])
194 switch (op->type) 145 switch (op->type)
195 { 146 {
196 case SKILL: 147 case SKILL:
197 ob->flag [FLAG_APPLIED] = false; 148 op->flag [FLAG_APPLIED] = false;
198 break; 149 break;
199 150
200 case WAND: 151 case WAND:
201 case ROD: 152 case ROD:
202 case HORN: 153 case HORN:
207 case WEAPON: 158 case WEAPON:
208 combat_ob = op; 159 combat_ob = op;
209 break; 160 break;
210 } 161 }
211 162
163 ob->current_weapon = 0;
212 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 164 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
213 ob->deactivate (); // change_weapon activates, fix this better 165 activate (); // change_weapon also activates, but this doesn't hurt
166
167 INVOKE_PLAYER (CONNECT, this);
168 INVOKE_PLAYER (LOGIN, this);
169}
170
171void
172player::disconnect ()
173{
174 if (ob)
175 {
176 ob->close_container (); //TODO: client-specific
177 ob->drop_unpaid_items ();
178 }
179
180 if (ns)
181 {
182 if (active)
183 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
184
185 INVOKE_PLAYER (DISCONNECT, this);
186
187 ns->reset_stats ();
188 ns->pl = 0;
189 ns = 0;
190 }
191
192 // this is important for the player scheduler to get the correct refcount
193 // when ns = 0
194 observe = viewpoint = ob;
195
196 deactivate ();
197}
198
199//-GPL
200
201// the need for this function can be explained
202// by load_object not returning the object
203void
204player::set_object (object *op)
205{
206 ob = observe = viewpoint = op;
207 ob->contr = this; /* this aren't yet in archetype */
208
209 ob->speed = 1.0f;
210 ob->speed_left = 0.5f;
211
212 ob->direction = 5; /* So player faces south */
214} 213}
215 214
216void 215void
217player::set_observe (object *op) 216player::set_observe (object *op)
218{ 217{
1863 { 1862 {
1864 --op->speed_left; 1863 --op->speed_left;
1865 return true; 1864 return true;
1866 } 1865 }
1867 1866
1868 int on_battleground;
1869
1870 sint16 nx = freearr_x[dir] + op->x; 1867 sint16 nx = freearr_x[dir] + op->x;
1871 sint16 ny = freearr_y[dir] + op->y; 1868 sint16 ny = freearr_y[dir] + op->y;
1872
1873 on_battleground = op_on_battleground (op, 0, 0);
1874 1869
1875 if (out_of_map (op->map, nx, ny)) 1870 if (out_of_map (op->map, nx, ny))
1876 return false; 1871 return false;
1877 1872
1878 /* If braced, or can't move to the square, and it is not out of the 1873 /* If braced, or can't move to the square, and it is not out of the
1950 } 1945 }
1951 else 1946 else
1952 return false; 1947 return false;
1953 } 1948 }
1954 1949
1950 bool on_battleground = op_on_battleground (op, 0, 0);
1951
1955 /* in certain circumstances, you shouldn't attack friendly 1952 /* in certain circumstances, you shouldn't attack friendly
1956 * creatures. Note that if you are braced, you can't push 1953 * creatures. Note that if you are braced, you can't push
1957 * someone, but put it inside this loop so that you won't 1954 * someone, but put it inside this loop so that you won't
1958 * attack them either. 1955 * attack them either.
1959 */ 1956 */
2027{ 2024{
2028 if (!op->map || op->map->in_memory != MAP_ACTIVE) 2025 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2029 return 0; 2026 return 0;
2030 2027
2031 /* Sanity check: make sure dir is valid */ 2028 /* Sanity check: make sure dir is valid */
2032 if ((dir < 0) || (dir >= 9)) 2029 if (dir < 0 || dir >= 9)
2033 { 2030 {
2034 LOG (llevError, "move_player: invalid direction %d\n", dir); 2031 LOG (llevError, "move_player: invalid direction %d\n", dir);
2035 return 0; 2032 return 0;
2036 } 2033 }
2037 2034
3046 && tmp->name == shstr_battleground 3043 && tmp->name == shstr_battleground
3047 && EXIT_X (tmp) && EXIT_Y (tmp)) 3044 && EXIT_X (tmp) && EXIT_Y (tmp))
3048 { 3045 {
3049 /* before we assign the exit, check if this is a teambattle */ 3046 /* before we assign the exit, check if this is a teambattle */
3050 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) 3047 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp))
3051 {
3052 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) 3048 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below)
3049 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3053 { 3050 {
3054 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3055 {
3056 if (x && y) 3051 if (x && y)
3057 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); 3052 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp);
3058 3053
3059 return 1; 3054 return 1;
3060 }
3061 } 3055 }
3062 }
3063 3056
3064 if (x && y) 3057 if (x && y)
3065 *x = EXIT_X (tmp), *y = EXIT_Y (tmp); 3058 *x = EXIT_X (tmp), *y = EXIT_Y (tmp);
3066 3059
3067 return 1; 3060 return 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines