… | |
… | |
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 | |
|
|
145 | void |
|
|
146 | player::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 |
|
|
177 | void |
|
|
178 | player::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 | |
|
|
171 | void |
|
|
172 | player::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 |
|
|
203 | void |
|
|
204 | player::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 | |
216 | void |
215 | void |
217 | player::set_observe (object *op) |
216 | player::set_observe (object *op) |
218 | { |
217 | { |
… | |
… | |
308 | player * |
307 | player * |
309 | player::create () |
308 | player::create () |
310 | { |
309 | { |
311 | player *pl = new player; |
310 | player *pl = new player; |
312 | |
311 | |
313 | pl->set_object (arch_to_object (get_player_archetype (0))); |
312 | pl->set_object (get_player_archetype (0)->instance ()); |
314 | |
313 | |
315 | pl->ob->roll_stats (); |
314 | pl->ob->roll_stats (); |
316 | pl->ob->stats.wc = 2; |
315 | pl->ob->stats.wc = 2; |
317 | pl->ob->run_away = 25; /* Then we panick... */ |
316 | pl->ob->run_away = 25; /* Then we panick... */ |
318 | |
317 | |
… | |
… | |
635 | send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
634 | send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
636 | } |
635 | } |
637 | |
636 | |
638 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
637 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
639 | static int |
638 | static int |
640 | roll_stat (void) |
639 | roll_stat () |
641 | { |
640 | { |
642 | int a[4], i, j, k; |
641 | int a[4], i, j, k; |
643 | |
642 | |
644 | for (i = 0; i < 4; i++) |
643 | for (i = 0; i < 4; i++) |
645 | a[i] = (int) rndm (6) + 1; |
644 | a[i] = (int) rndm (6) + 1; |
… | |
… | |
2475 | if (op_on_battleground (op, &x, &y)) |
2474 | if (op_on_battleground (op, &x, &y)) |
2476 | { |
2475 | { |
2477 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2476 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2478 | |
2477 | |
2479 | /* create a bodypart-trophy to make the winner happy */ |
2478 | /* create a bodypart-trophy to make the winner happy */ |
2480 | if (object *tmp = arch_to_object (archetype::find (shstr_finger))) |
2479 | object *tmp = archetype::find (shstr_finger)->instance (); |
2481 | { |
2480 | |
2482 | tmp->name = format ("%s's finger" , &op->name); |
2481 | tmp->name = format ("%s's finger" , &op->name); |
2483 | tmp->name_pl = format ("%s's fingers", &op->name); |
2482 | tmp->name_pl = format ("%s's fingers", &op->name); |
2484 | tmp->msg = format ( |
2483 | tmp->msg = format ( |
2485 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2484 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2486 | &op->name, op->contr->title, |
2485 | &op->name, op->contr->title, |
2487 | (int)op->level, |
2486 | (int)op->level, |
2488 | op->contr->killer_name () |
2487 | op->contr->killer_name () |
2489 | ); |
2488 | ); |
2490 | tmp->value = 0, tmp->type = 0; |
2489 | tmp->value = 0, tmp->type = 0; |
2491 | tmp->material = name_to_material (shstr_organic); |
2490 | tmp->material = name_to_material (shstr_organic); |
2492 | tmp->insert_at (op, tmp); |
2491 | tmp->insert_at (op, tmp); |
2493 | } |
|
|
2494 | |
2492 | |
2495 | /* teleport defeated player to new destination */ |
2493 | /* teleport defeated player to new destination */ |
2496 | transfer_ob (op, x, y, 0, NULL); |
2494 | transfer_ob (op, x, y, 0, NULL); |
2497 | op->contr->braced = 0; |
2495 | op->contr->braced = 0; |
2498 | |
2496 | |
… | |
… | |
2566 | object *dep; |
2564 | object *dep; |
2567 | |
2565 | |
2568 | dep = present_arch_in_ob (deparch, op); |
2566 | dep = present_arch_in_ob (deparch, op); |
2569 | if (!dep) |
2567 | if (!dep) |
2570 | { |
2568 | { |
2571 | dep = arch_to_object (deparch); |
2569 | dep = deparch->instance (); |
2572 | insert_ob_in_ob (dep, op); |
2570 | insert_ob_in_ob (dep, op); |
2573 | } |
2571 | } |
2574 | lose_this_stat = 1; |
2572 | lose_this_stat = 1; |
2575 | if (settings.balanced_stat_loss) |
2573 | if (settings.balanced_stat_loss) |
2576 | { |
2574 | { |
… | |
… | |
2642 | #endif |
2640 | #endif |
2643 | |
2641 | |
2644 | /* Put a gravestone up where the character 'almost' died. List the |
2642 | /* Put a gravestone up where the character 'almost' died. List the |
2645 | * exp loss on the stone. |
2643 | * exp loss on the stone. |
2646 | */ |
2644 | */ |
2647 | tmp = arch_to_object (archetype::find (shstr_gravestone)); |
2645 | tmp = archetype::find (shstr_gravestone)->instance (); |
2648 | tmp->name = format ("%s's gravestone", &op->name); |
2646 | tmp->name = format ("%s's gravestone", &op->name); |
2649 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2647 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2650 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2648 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2651 | &op->name, op->contr->title, op->contr->killer_name ()); |
2649 | &op->name, op->contr->title, op->contr->killer_name ()); |
2652 | tmp->x = op->x, tmp->y = op->y; |
2650 | tmp->x = op->x, tmp->y = op->y; |
… | |
… | |
2748 | * fix_weight(): Check recursively the weight of all players, and fix |
2746 | * fix_weight(): Check recursively the weight of all players, and fix |
2749 | * what needs to be fixed. Refresh windows and fix speed if anything |
2747 | * what needs to be fixed. Refresh windows and fix speed if anything |
2750 | * was changed. |
2748 | * was changed. |
2751 | */ |
2749 | */ |
2752 | void |
2750 | void |
2753 | fix_weight (void) |
2751 | fix_weight () |
2754 | { |
2752 | { |
2755 | for_all_players (pl) |
2753 | for_all_players (pl) |
2756 | { |
2754 | { |
2757 | sint32 old = pl->ob->carrying; |
2755 | sint32 old = pl->ob->carrying; |
2758 | |
2756 | |
… | |
… | |
2765 | } |
2763 | } |
2766 | } |
2764 | } |
2767 | } |
2765 | } |
2768 | |
2766 | |
2769 | void |
2767 | void |
2770 | fix_luck (void) |
2768 | fix_luck () |
2771 | { |
2769 | { |
2772 | for_all_players (pl) |
2770 | for_all_players (pl) |
2773 | if (!pl->ob->contr->ns->state) |
2771 | if (!pl->ob->contr->ns->state) |
2774 | pl->ob->change_luck (0); |
2772 | pl->ob->change_luck (0); |
2775 | } |
2773 | } |
… | |
… | |
3225 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3223 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3226 | } |
3224 | } |
3227 | else |
3225 | else |
3228 | { |
3226 | { |
3229 | /* generate misc. treasure */ |
3227 | /* generate misc. treasure */ |
3230 | tmp = arch_to_object (tr->item); |
3228 | tmp = tr->item->instance (); |
3231 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3229 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3232 | who->insert (tmp); |
3230 | who->insert (tmp); |
3233 | } |
3231 | } |
3234 | } |
3232 | } |
3235 | |
3233 | |