… | |
… | |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
|
|
25 | //+GPL |
|
|
26 | |
25 | #include <global.h> |
27 | #include <global.h> |
26 | #include <sproto.h> |
28 | #include <sproto.h> |
27 | #include <sounds.h> |
29 | #include <sounds.h> |
28 | #include <living.h> |
30 | #include <living.h> |
29 | #include <object.h> |
31 | #include <object.h> |
… | |
… | |
105 | ob->race = ob->arch->race; |
107 | ob->race = ob->arch->race; |
106 | |
108 | |
107 | ob->update_weight (); |
109 | ob->update_weight (); |
108 | link_skills (); |
110 | link_skills (); |
109 | |
111 | |
110 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
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 | |
|
|
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 | observe = ob; |
|
|
167 | |
|
|
168 | deactivate (); |
|
|
169 | } |
|
|
170 | |
|
|
171 | // the need for this function can be explained |
|
|
172 | // by load_object not returning the object |
|
|
173 | void |
|
|
174 | player::set_object (object *op) |
|
|
175 | { |
|
|
176 | ob = observe = op; |
|
|
177 | ob->contr = this; /* this aren't yet in archetype */ |
|
|
178 | |
|
|
179 | ob->speed = 1.0f; |
|
|
180 | ob->speed_left = 0.5f; |
|
|
181 | |
|
|
182 | ob->direction = 5; /* So player faces south */ |
|
|
183 | |
|
|
184 | ob->flag [FLAG_READY_WEAPON] = false; |
139 | ob->flag [FLAG_READY_WEAPON] = false; |
185 | ob->flag [FLAG_READY_SKILL] = false; |
140 | ob->flag [FLAG_READY_SKILL] = false; |
186 | ob->flag [FLAG_READY_BOW] = false; |
141 | ob->flag [FLAG_READY_BOW] = false; |
187 | |
142 | |
188 | for (object *op = ob->inv; op; op = op->below) |
143 | for (object *op = ob->inv; op; op = op->below) |
189 | if (op->flag [FLAG_APPLIED]) |
144 | if (op->flag [FLAG_APPLIED]) |
190 | switch (op->type) |
145 | switch (op->type) |
191 | { |
146 | { |
192 | case SKILL: |
147 | case SKILL: |
193 | ob->flag [FLAG_APPLIED] = false; |
148 | op->flag [FLAG_APPLIED] = false; |
194 | break; |
149 | break; |
195 | |
150 | |
196 | case WAND: |
151 | case WAND: |
197 | case ROD: |
152 | case ROD: |
198 | case HORN: |
153 | case HORN: |
… | |
… | |
203 | case WEAPON: |
158 | case WEAPON: |
204 | combat_ob = op; |
159 | combat_ob = op; |
205 | break; |
160 | break; |
206 | } |
161 | } |
207 | |
162 | |
|
|
163 | ob->current_weapon = 0; |
208 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
164 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
209 | 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 */ |
210 | } |
213 | } |
211 | |
214 | |
212 | void |
215 | void |
213 | player::set_observe (object *op) |
216 | player::set_observe (object *op) |
214 | { |
217 | { |
215 | observe = op ? op : ob; |
218 | observe = viewpoint = op ? op : ob; |
216 | do_los = 1; |
219 | do_los = 1; |
217 | } |
220 | } |
|
|
221 | |
|
|
222 | void |
|
|
223 | player::set_viewpoint (object *op) |
|
|
224 | { |
|
|
225 | viewpoint = op ? op : (object *)observe; |
|
|
226 | do_los = 1; |
|
|
227 | } |
|
|
228 | |
|
|
229 | //+GPL |
218 | |
230 | |
219 | player::player () |
231 | player::player () |
220 | { |
232 | { |
221 | /* There are some elements we want initialised to non zero value - |
233 | /* There are some elements we want initialised to non zero value - |
222 | * we deal with that below this point. |
234 | * we deal with that below this point. |
… | |
… | |
249 | { |
261 | { |
250 | ob->destroy_inv (false); |
262 | ob->destroy_inv (false); |
251 | ob->destroy (); |
263 | ob->destroy (); |
252 | } |
264 | } |
253 | |
265 | |
254 | ob = observe = 0; |
266 | ob = observe = viewpoint = 0; |
255 | } |
267 | } |
256 | |
268 | |
257 | player::~player () |
269 | player::~player () |
258 | { |
270 | { |
259 | /* Clear item stack */ |
271 | /* Clear item stack */ |
260 | free (stack_items); |
272 | free (stack_items); |
|
|
273 | } |
|
|
274 | |
|
|
275 | /* |
|
|
276 | * get_player_archetype() return next player archetype from archetype |
|
|
277 | * list. Not very efficient routine, but used only creating new players. |
|
|
278 | * Note: there MUST be at least one player archetype! |
|
|
279 | */ |
|
|
280 | static archetype * |
|
|
281 | get_player_archetype (archetype *at) |
|
|
282 | { |
|
|
283 | // archetypes could have been reloaded |
|
|
284 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
285 | |
|
|
286 | if (!nat) |
|
|
287 | return at; |
|
|
288 | |
|
|
289 | archvec::iterator i = archetypes.find (nat); |
|
|
290 | |
|
|
291 | for (;;) |
|
|
292 | { |
|
|
293 | if (++i == archetypes.end ()) |
|
|
294 | i = archetypes.begin (); |
|
|
295 | else if (*i == at) |
|
|
296 | cleanup ("not a single player archetype found"); |
|
|
297 | |
|
|
298 | if ((*i)->type == PLAYER) |
|
|
299 | return *i; |
|
|
300 | } |
261 | } |
301 | } |
262 | |
302 | |
263 | /* Tries to add player on the connection passed in ns. |
303 | /* Tries to add player on the connection passed in ns. |
264 | * All we can really get in this is some settings like host and display |
304 | * All we can really get in this is some settings like host and display |
265 | * mode. |
305 | * mode. |
… | |
… | |
267 | player * |
307 | player * |
268 | player::create () |
308 | player::create () |
269 | { |
309 | { |
270 | player *pl = new player; |
310 | player *pl = new player; |
271 | |
311 | |
272 | pl->set_object (arch_to_object (get_player_archetype (0))); |
312 | pl->set_object (get_player_archetype (0)->instance ()); |
273 | |
313 | |
274 | pl->ob->roll_stats (); |
314 | pl->ob->roll_stats (); |
275 | pl->ob->stats.wc = 2; |
315 | pl->ob->stats.wc = 2; |
276 | pl->ob->run_away = 25; /* Then we panick... */ |
316 | pl->ob->run_away = 25; /* Then we panick... */ |
277 | |
317 | |
278 | set_first_map (pl->ob); |
318 | set_first_map (pl->ob); |
279 | |
319 | |
280 | return pl; |
320 | return pl; |
281 | } |
|
|
282 | |
|
|
283 | /* |
|
|
284 | * get_player_archetype() return next player archetype from archetype |
|
|
285 | * list. Not very efficient routine, but used only creating new players. |
|
|
286 | * Note: there MUST be at least one player archetype! |
|
|
287 | */ |
|
|
288 | archetype * |
|
|
289 | get_player_archetype (archetype *at) |
|
|
290 | { |
|
|
291 | // archetypes could have been reloaded |
|
|
292 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
293 | |
|
|
294 | if (!nat) |
|
|
295 | return at; |
|
|
296 | |
|
|
297 | archvec::iterator i = archetypes.find (nat); |
|
|
298 | |
|
|
299 | for (;;) |
|
|
300 | { |
|
|
301 | if (++i == archetypes.end ()) |
|
|
302 | i = archetypes.begin (); |
|
|
303 | else if (*i == at) |
|
|
304 | cleanup ("not a single player archetype found"); |
|
|
305 | |
|
|
306 | if ((*i)->type == PLAYER) |
|
|
307 | return *i; |
|
|
308 | } |
|
|
309 | } |
321 | } |
310 | |
322 | |
311 | object * |
323 | object * |
312 | get_nearest_player (object *mon) |
324 | get_nearest_player (object *mon) |
313 | { |
325 | { |
… | |
… | |
622 | 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:"); |
623 | } |
635 | } |
624 | |
636 | |
625 | /* 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. */ |
626 | static int |
638 | static int |
627 | roll_stat (void) |
639 | roll_stat () |
628 | { |
640 | { |
629 | int a[4], i, j, k; |
641 | int a[4], i, j, k; |
630 | |
642 | |
631 | for (i = 0; i < 4; i++) |
643 | for (i = 0; i < 4; i++) |
632 | a[i] = (int) rndm (6) + 1; |
644 | a[i] = (int) rndm (6) + 1; |
… | |
… | |
729 | player::chargen_race_done () |
741 | player::chargen_race_done () |
730 | { |
742 | { |
731 | /* this must before then initial items are given */ |
743 | /* this must before then initial items are given */ |
732 | esrv_new_player (ob->contr); |
744 | esrv_new_player (ob->contr); |
733 | |
745 | |
734 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
746 | treasurelist *tl = treasurelist::find (shstr_starting_wealth); |
735 | if (tl) |
747 | if (tl) |
736 | create_treasure (tl, ob, 0, 0, 0); |
748 | create_treasure (tl, ob, 0, 0, 0); |
737 | |
749 | |
738 | INVOKE_PLAYER (BIRTH, ob->contr); |
750 | INVOKE_PLAYER (BIRTH, ob->contr); |
739 | INVOKE_PLAYER (LOGIN, ob->contr); |
751 | INVOKE_PLAYER (LOGIN, ob->contr); |
… | |
… | |
792 | ob->stats.hp = ob->stats.maxhp; |
804 | ob->stats.hp = ob->stats.maxhp; |
793 | ob->stats.sp = ob->stats.maxsp; |
805 | ob->stats.sp = ob->stats.maxsp; |
794 | ob->stats.grace = 0; |
806 | ob->stats.grace = 0; |
795 | } |
807 | } |
796 | |
808 | |
797 | void |
809 | static void |
798 | flee_player (object *op) |
810 | flee_player (object *op) |
799 | { |
811 | { |
800 | int dir, diff; |
812 | int dir, diff; |
801 | rv_vector rv; |
813 | rv_vector rv; |
802 | |
814 | |
… | |
… | |
826 | dir = absdir (4 + rv.direction); |
838 | dir = absdir (4 + rv.direction); |
827 | for (diff = 0; diff < 3; diff++) |
839 | for (diff = 0; diff < 3; diff++) |
828 | { |
840 | { |
829 | int m = 1 - rndm (2) * 2; |
841 | int m = 1 - rndm (2) * 2; |
830 | |
842 | |
831 | if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) |
843 | if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) |
832 | return; |
844 | return; |
833 | } |
845 | } |
834 | |
846 | |
835 | /* Cornered, get rid of scared */ |
847 | /* Cornered, get rid of scared */ |
836 | CLEAR_FLAG (op, FLAG_SCARED); |
848 | CLEAR_FLAG (op, FLAG_SCARED); |
… | |
… | |
852 | if (op->move_type & MOVE_FLYING) |
864 | if (op->move_type & MOVE_FLYING) |
853 | return 1; |
865 | return 1; |
854 | |
866 | |
855 | next = op->below; |
867 | next = op->below; |
856 | |
868 | |
857 | int cnt = MAX_ITEM_PER_DROP; |
869 | int cnt = MAX_ITEM_PER_ACTION; |
858 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
870 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
859 | |
871 | |
860 | /* loop while there are items on the floor that are not marked as |
872 | /* loop while there are items on the floor that are not marked as |
861 | * destroyed */ |
873 | * destroyed */ |
862 | while (next && !next->destroyed ()) |
874 | while (next && !next->destroyed ()) |
… | |
… | |
888 | if (op->contr->mode & PU_DEBUG) |
900 | if (op->contr->mode & PU_DEBUG) |
889 | { |
901 | { |
890 | /* some debugging code to figure out item information */ |
902 | /* some debugging code to figure out item information */ |
891 | const char *str = tmp->name |
903 | const char *str = tmp->name |
892 | ? format ("item name: %s item type: %d weight/value: %d", |
904 | ? format ("item name: %s item type: %d weight/value: %d", |
893 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))) |
905 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))) |
894 | : format ("item name: %s item type: %d weight/value: %d", |
906 | : format ("item name: %s item type: %d weight/value: %d", |
895 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
907 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
896 | |
908 | |
897 | new_draw_info (NDI_UNIQUE, 0, op, str); |
909 | new_draw_info (NDI_UNIQUE, 0, op, str); |
898 | } |
910 | } |
899 | |
911 | |
900 | if (op->contr->mode & PU_INHIBIT) |
912 | if (op->contr->mode & PU_INHIBIT) |
… | |
… | |
987 | continue; |
999 | continue; |
988 | } |
1000 | } |
989 | |
1001 | |
990 | /* wands/staves/rods/horns */ |
1002 | /* wands/staves/rods/horns */ |
991 | if (op->contr->mode & PU_MAGIC_DEVICE) |
1003 | if (op->contr->mode & PU_MAGIC_DEVICE) |
992 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) |
1004 | if (tmp->type == WAND |
|
|
1005 | || tmp->type == ROD |
|
|
1006 | || tmp->type == HORN |
|
|
1007 | || tmp->type == POWER_CRYSTAL) |
993 | { |
1008 | { |
994 | CHK_PICK_PICKUP; |
1009 | CHK_PICK_PICKUP; |
995 | continue; |
1010 | continue; |
996 | } |
1011 | } |
997 | |
1012 | |
998 | /* pick up all magical items */ |
1013 | /* pick up all magical items */ |
999 | if (op->contr->mode & PU_MAGICAL) |
1014 | if (op->contr->mode & PU_MAGICAL) |
1000 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1015 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) |
|
|
1016 | && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1001 | { |
1017 | { |
1002 | CHK_PICK_PICKUP; |
1018 | CHK_PICK_PICKUP; |
1003 | continue; |
1019 | continue; |
1004 | } |
1020 | } |
1005 | |
1021 | |
… | |
… | |
1012 | } |
1028 | } |
1013 | } |
1029 | } |
1014 | |
1030 | |
1015 | /* rings & amulets - talismans seems to be typed AMULET */ |
1031 | /* rings & amulets - talismans seems to be typed AMULET */ |
1016 | if (op->contr->mode & PU_JEWELS) |
1032 | if (op->contr->mode & PU_JEWELS) |
1017 | if (tmp->type == RING || tmp->type == AMULET) |
1033 | if (tmp->type == RING |
|
|
1034 | || tmp->type == AMULET |
|
|
1035 | || tmp->type == GIRDLE |
|
|
1036 | || tmp->type == SKILL_TOOL) |
1018 | { |
1037 | { |
1019 | CHK_PICK_PICKUP; |
1038 | CHK_PICK_PICKUP; |
1020 | continue; |
1039 | continue; |
1021 | } |
1040 | } |
1022 | |
1041 | |
… | |
… | |
1071 | CHK_PICK_PICKUP; |
1090 | CHK_PICK_PICKUP; |
1072 | continue; |
1091 | continue; |
1073 | } |
1092 | } |
1074 | |
1093 | |
1075 | if (op->contr->mode & PU_GLOVES) |
1094 | if (op->contr->mode & PU_GLOVES) |
1076 | if (tmp->type == GLOVES) |
1095 | if (tmp->type == GLOVES || tmp->type == BRACERS) |
1077 | { |
1096 | { |
1078 | CHK_PICK_PICKUP; |
1097 | CHK_PICK_PICKUP; |
1079 | continue; |
1098 | continue; |
1080 | } |
1099 | } |
1081 | |
1100 | |
… | |
… | |
1131 | fprintf (stderr, "%s", tmp->name); |
1150 | fprintf (stderr, "%s", tmp->name); |
1132 | } |
1151 | } |
1133 | else |
1152 | else |
1134 | fprintf (stderr, "%s", tmp->arch->archname); |
1153 | fprintf (stderr, "%s", tmp->arch->archname); |
1135 | fprintf (stderr, ",%d] = ", tmp->type); |
1154 | fprintf (stderr, ",%d] = ", tmp->type); |
1136 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1155 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
1137 | #endif |
1156 | #endif |
1138 | CHK_PICK_PICKUP; |
1157 | CHK_PICK_PICKUP; |
1139 | continue; |
1158 | continue; |
1140 | } |
1159 | } |
1141 | } /* the new pickup model */ |
1160 | } /* the new pickup model */ |
1142 | } |
1161 | } |
1143 | |
1162 | |
1144 | return !stop; |
1163 | return !stop; |
1145 | } |
1164 | } |
1146 | |
1165 | |
|
|
1166 | /* routine for both players and monsters. We call this when |
|
|
1167 | * there is a possibility for our action distrubing our hiding |
|
|
1168 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
1169 | * "noise" instead. If we arent invisible to begin with, we |
|
|
1170 | * return 0. |
|
|
1171 | */ |
|
|
1172 | static int |
|
|
1173 | action_makes_visible (object *op) |
|
|
1174 | { |
|
|
1175 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
1176 | { |
|
|
1177 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
1178 | { |
|
|
1179 | // artefact invisibility is permanent, but we still make noise |
|
|
1180 | // this is important for game-balance. |
|
|
1181 | if (op->contr) |
|
|
1182 | op->make_noise (); |
|
|
1183 | |
|
|
1184 | return 0; |
|
|
1185 | } |
|
|
1186 | |
|
|
1187 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
1188 | return 0; |
|
|
1189 | |
|
|
1190 | /* If monsters, they should become visible */ |
|
|
1191 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
1192 | { |
|
|
1193 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
1194 | return 1; |
|
|
1195 | } |
|
|
1196 | } |
|
|
1197 | |
|
|
1198 | return 0; |
|
|
1199 | } |
|
|
1200 | |
1147 | /* |
1201 | /* |
1148 | * Find an arrow in the inventory and after that |
1202 | * Find an arrow in the inventory and after that |
1149 | * in the right type container (quiver). Pointer to the |
1203 | * in the right type container (quiver). Pointer to the |
1150 | * found object is returned. |
1204 | * found object is returned. |
1151 | */ |
1205 | */ |
1152 | object * |
1206 | static object * |
1153 | find_arrow (object *op, const char *type) |
1207 | find_arrow (object *op, const char *type) |
1154 | { |
1208 | { |
1155 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1209 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1156 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1210 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1157 | return splay (tmp); |
1211 | return splay (tmp); |
… | |
… | |
1171 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1225 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1172 | * against the target. A full test is not performed, simply a basic test |
1226 | * against the target. A full test is not performed, simply a basic test |
1173 | * of resistances. The archer is making a quick guess at what he sees down |
1227 | * of resistances. The archer is making a quick guess at what he sees down |
1174 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1228 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1175 | */ |
1229 | */ |
1176 | object * |
1230 | static object * |
1177 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1231 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1178 | { |
1232 | { |
1179 | object *tmp = NULL, *arrow, *ntmp; |
1233 | object *tmp = NULL, *arrow, *ntmp; |
1180 | int attacknum, attacktype, betterby = 0, i; |
1234 | int attacknum, attacktype, betterby = 0, i; |
1181 | |
1235 | |
… | |
… | |
1250 | * find_better_arrow to find a decent arrow to use. |
1304 | * find_better_arrow to find a decent arrow to use. |
1251 | * op = the shooter |
1305 | * op = the shooter |
1252 | * type = bow->race |
1306 | * type = bow->race |
1253 | * dir = fire direction |
1307 | * dir = fire direction |
1254 | */ |
1308 | */ |
1255 | object * |
1309 | static object * |
1256 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1310 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1257 | { |
1311 | { |
1258 | object *tmp = NULL; |
1312 | object *tmp = NULL; |
1259 | maptile *m; |
1313 | maptile *m; |
1260 | int i, mflags, found, number; |
1314 | int i, mflags, found, number; |
… | |
… | |
1475 | * but monsters can't. Putting that code here |
1529 | * but monsters can't. Putting that code here |
1476 | * makes the fire_bow code much cleaner. |
1530 | * makes the fire_bow code much cleaner. |
1477 | * this function should only be called if 'op' is a player, |
1531 | * this function should only be called if 'op' is a player, |
1478 | * hence the function name. |
1532 | * hence the function name. |
1479 | */ |
1533 | */ |
1480 | int |
1534 | static int |
1481 | player_fire_bow (object *op, int dir) |
1535 | player_fire_bow (object *op, int dir) |
1482 | { |
1536 | { |
1483 | int ret; |
1537 | int ret; |
1484 | |
1538 | |
1485 | if (op->contr->bowtype == bow_bestarrow) |
1539 | if (op->contr->bowtype == bow_bestarrow) |
… | |
… | |
1513 | } |
1567 | } |
1514 | |
1568 | |
1515 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1569 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1516 | * Broken apart from 'fire' to keep it more readable. |
1570 | * Broken apart from 'fire' to keep it more readable. |
1517 | */ |
1571 | */ |
1518 | void |
1572 | static void |
1519 | fire_misc_object (object *op, int dir) |
1573 | fire_misc_object (object *op, int dir) |
1520 | { |
1574 | { |
1521 | object *item = op->contr->ranged_ob; |
1575 | object *item = op->contr->ranged_ob; |
1522 | |
1576 | |
1523 | if (!item) |
1577 | if (!item) |
… | |
… | |
1545 | return; |
1599 | return; |
1546 | } |
1600 | } |
1547 | } |
1601 | } |
1548 | else if (item->type == ROD || item->type == HORN) |
1602 | else if (item->type == ROD || item->type == HORN) |
1549 | { |
1603 | { |
1550 | sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); |
1604 | sint16 spell_sp = max (item->inv->stats.sp, item->inv->stats.grace); |
1551 | |
1605 | |
1552 | // using the maximum of the rods charge allows at least one spell cast |
1606 | // using the maximum of the rods charge allows at least one spell cast |
1553 | // for a rod or horn, this fixes some broken rods. |
1607 | // for a rod or horn, this fixes some broken rods. |
1554 | if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) |
1608 | if (item->stats.hp < min (spell_sp, item->stats.maxhp)) |
1555 | { |
1609 | { |
1556 | op->contr->play_sound (sound_find ("wand_poof")); |
1610 | op->contr->play_sound (sound_find ("wand_poof")); |
1557 | |
1611 | |
1558 | if (item->type == ROD) |
1612 | if (item->type == ROD) |
1559 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
1613 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
… | |
… | |
1646 | } |
1700 | } |
1647 | |
1701 | |
1648 | return true; |
1702 | return true; |
1649 | } |
1703 | } |
1650 | |
1704 | |
1651 | /* find_key |
1705 | static object * |
1652 | * We try to find a key for the door as passed. If we find a key |
|
|
1653 | * and successfully use it, we return the key, otherwise NULL |
|
|
1654 | * This function merges both normal and locked door, since the logic |
|
|
1655 | * for both is the same - just the specific key is different. |
|
|
1656 | * pl is the player, |
|
|
1657 | * inv is the objects inventory to searched |
|
|
1658 | * door is the door we are trying to match against. |
|
|
1659 | * This function can be called recursively to search containers. |
|
|
1660 | */ |
|
|
1661 | object * |
|
|
1662 | find_key (object *pl, object *container, object *door) |
1706 | find_key_ (object *pl, object *container, object *door) |
1663 | { |
1707 | { |
1664 | object *tmp, *key; |
1708 | object *tmp, *key; |
1665 | |
1709 | |
1666 | /* Should not happen, but sanity checking is never bad */ |
1710 | /* Should not happen, but sanity checking is never bad */ |
1667 | if (!container->inv) |
1711 | if (!container->inv) |
… | |
… | |
1688 | if (!tmp) |
1732 | if (!tmp) |
1689 | { |
1733 | { |
1690 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1734 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1691 | /* No reason to search empty containers */ |
1735 | /* No reason to search empty containers */ |
1692 | if (tmp->type == CONTAINER && tmp->inv) |
1736 | if (tmp->type == CONTAINER && tmp->inv) |
1693 | if ((key = find_key (pl, tmp, door))) |
1737 | if ((key = find_key_ (pl, tmp, door))) |
1694 | return key; |
1738 | return key; |
1695 | |
1739 | |
1696 | if (!tmp) |
1740 | if (!tmp) |
1697 | return 0; |
1741 | return 0; |
1698 | } |
1742 | } |
… | |
… | |
1717 | * inv must have been an container and must have been active. |
1761 | * inv must have been an container and must have been active. |
1718 | * |
1762 | * |
1719 | * Change the color so that the message doesn't disappear with |
1763 | * Change the color so that the message doesn't disappear with |
1720 | * all the others. |
1764 | * all the others. |
1721 | */ |
1765 | */ |
1722 | if (pl->contr->usekeys == key_inventory || |
1766 | if (pl->contr->usekeys == key_inventory |
1723 | !QUERY_FLAG (container, FLAG_APPLIED) || |
1767 | || !QUERY_FLAG (container, FLAG_APPLIED) |
1724 | (pl->contr->usekeys == keyrings && container->race != shstr_keys)) |
1768 | || (pl->contr->usekeys == keyrings && container->race != shstr_keys)) |
1725 | { |
1769 | { |
1726 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1770 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1727 | "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); |
1771 | "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); |
1728 | return NULL; |
1772 | return NULL; |
1729 | } |
1773 | } |
1730 | } |
1774 | } |
1731 | |
1775 | |
1732 | return tmp; |
1776 | return tmp; |
|
|
1777 | } |
|
|
1778 | |
|
|
1779 | /* find_key |
|
|
1780 | * We try to find a key for the door as passed. If we find a key |
|
|
1781 | * and successfully use it, we return the key, otherwise NULL |
|
|
1782 | * This function merges both normal and locked door, since the logic |
|
|
1783 | * for both is the same - just the specific key is different. |
|
|
1784 | * pl is the player, |
|
|
1785 | * inv is the objects inventory to searched |
|
|
1786 | * door is the door we are trying to match against. |
|
|
1787 | * This function can be called recursively to search containers. |
|
|
1788 | */ |
|
|
1789 | object * |
|
|
1790 | find_key (object *pl, object *container, object *door) |
|
|
1791 | { |
|
|
1792 | if (door->slaying && is_match_expr (door->slaying)) |
|
|
1793 | { |
|
|
1794 | // for match expressions, we try to find the key by applying the match |
|
|
1795 | // to the op itself, which is supposed to find the "key", instead |
|
|
1796 | // of searching through containers ourselves. |
|
|
1797 | |
|
|
1798 | return match_one (door->slaying, container, door, pl, pl); |
|
|
1799 | } |
|
|
1800 | else |
|
|
1801 | return find_key_ (pl, container, door); |
1733 | } |
1802 | } |
1734 | |
1803 | |
1735 | /* moved door processing out of move_player_attack. |
1804 | /* moved door processing out of move_player_attack. |
1736 | * returns 1 if player has opened the door with a key |
1805 | * returns 1 if player has opened the door with a key |
1737 | * such that the caller should not do anything more, |
1806 | * such that the caller should not do anything more, |
… | |
… | |
1787 | * going to try and move (not fire weapons). |
1856 | * going to try and move (not fire weapons). |
1788 | */ |
1857 | */ |
1789 | bool |
1858 | bool |
1790 | move_player_attack (object *op, int dir) |
1859 | move_player_attack (object *op, int dir) |
1791 | { |
1860 | { |
1792 | if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) |
1861 | if (!op->contr->braced && op->speed_left > 0.f && op->move (dir)) |
1793 | { |
1862 | { |
1794 | --op->speed_left; |
1863 | --op->speed_left; |
1795 | return true; |
1864 | return true; |
1796 | } |
1865 | } |
1797 | |
1866 | |
1798 | int on_battleground; |
|
|
1799 | |
|
|
1800 | sint16 nx = freearr_x[dir] + op->x; |
1867 | sint16 nx = freearr_x[dir] + op->x; |
1801 | sint16 ny = freearr_y[dir] + op->y; |
1868 | sint16 ny = freearr_y[dir] + op->y; |
1802 | |
|
|
1803 | on_battleground = op_on_battleground (op, 0, 0); |
|
|
1804 | |
1869 | |
1805 | if (out_of_map (op->map, nx, ny)) |
1870 | if (out_of_map (op->map, nx, ny)) |
1806 | return false; |
1871 | return false; |
1807 | |
1872 | |
1808 | /* 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 |
… | |
… | |
1880 | } |
1945 | } |
1881 | else |
1946 | else |
1882 | return false; |
1947 | return false; |
1883 | } |
1948 | } |
1884 | |
1949 | |
|
|
1950 | bool on_battleground = op_on_battleground (op, 0, 0); |
|
|
1951 | |
1885 | /* in certain circumstances, you shouldn't attack friendly |
1952 | /* in certain circumstances, you shouldn't attack friendly |
1886 | * creatures. Note that if you are braced, you can't push |
1953 | * creatures. Note that if you are braced, you can't push |
1887 | * 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 |
1888 | * attack them either. |
1955 | * attack them either. |
1889 | */ |
1956 | */ |
… | |
… | |
1953 | } |
2020 | } |
1954 | |
2021 | |
1955 | bool |
2022 | bool |
1956 | move_player (object *op, int dir) |
2023 | move_player (object *op, int dir) |
1957 | { |
2024 | { |
1958 | int pick; |
|
|
1959 | |
|
|
1960 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2025 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
1961 | return 0; |
2026 | return 0; |
1962 | |
2027 | |
1963 | /* Sanity check: make sure dir is valid */ |
2028 | /* Sanity check: make sure dir is valid */ |
1964 | if ((dir < 0) || (dir >= 9)) |
2029 | if (dir < 0 || dir >= 9) |
1965 | { |
2030 | { |
1966 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2031 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
1967 | return 0; |
2032 | return 0; |
1968 | } |
2033 | } |
1969 | |
2034 | |
… | |
… | |
1975 | |
2040 | |
1976 | if (op->flag [FLAG_HIDDEN]) |
2041 | if (op->flag [FLAG_HIDDEN]) |
1977 | do_hidden_move (op); |
2042 | do_hidden_move (op); |
1978 | |
2043 | |
1979 | bool retval; |
2044 | bool retval; |
|
|
2045 | int pick = 0; |
1980 | |
2046 | |
1981 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2047 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
1982 | retval = RESULT_INT (0); |
2048 | retval = RESULT_INT (0); |
1983 | else if (op->contr->fire_on) |
2049 | else if (op->contr->fire_on) |
1984 | retval = fire (op, dir); |
2050 | retval = fire (op, dir); |
… | |
… | |
2041 | return move_player (op, op->direction); |
2107 | return move_player (op, op->direction); |
2042 | |
2108 | |
2043 | return false; |
2109 | return false; |
2044 | } |
2110 | } |
2045 | |
2111 | |
2046 | int |
2112 | static int |
2047 | save_life (object *op) |
2113 | save_life (object *op) |
2048 | { |
2114 | { |
2049 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2115 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2050 | return 0; |
2116 | return 0; |
2051 | |
2117 | |
… | |
… | |
2098 | void |
2164 | void |
2099 | object::drop_unpaid_items () |
2165 | object::drop_unpaid_items () |
2100 | { |
2166 | { |
2101 | if (!flag [FLAG_REMOVED]) |
2167 | if (!flag [FLAG_REMOVED]) |
2102 | ::drop_unpaid_items (inv, this); |
2168 | ::drop_unpaid_items (inv, this); |
2103 | } |
|
|
2104 | |
|
|
2105 | /* |
|
|
2106 | * Returns pointer a static string containing gravestone text |
|
|
2107 | * Moved from apply.c to player.c - player.c is what |
|
|
2108 | * actually uses this function. player.c may not be quite the |
|
|
2109 | * best, a misc file for object actions is probably better, |
|
|
2110 | * but there isn't one in the server directory. |
|
|
2111 | */ |
|
|
2112 | const char * |
|
|
2113 | gravestone_text (object *op) |
|
|
2114 | { |
|
|
2115 | static dynbuf_text buf; |
|
|
2116 | |
|
|
2117 | buf << "---- R.I.P. ----\n\n" |
|
|
2118 | << op->name; |
|
|
2119 | |
|
|
2120 | if (op->type == PLAYER) |
|
|
2121 | buf << " the " << op->contr->title; |
|
|
2122 | |
|
|
2123 | buf << "\n\n"; |
|
|
2124 | |
|
|
2125 | buf << "who was level "; |
|
|
2126 | buf << (sint32)op->level << "\n\n" // OO breakdown |
|
|
2127 | << " when " << (op->contr ? "killed" : "died") << "\n\n"; |
|
|
2128 | |
|
|
2129 | if (op->type == PLAYER) |
|
|
2130 | buf << "by " << op->contr->killer_name () << ".\n\n"; |
|
|
2131 | |
|
|
2132 | { |
|
|
2133 | static char buf2[128]; |
|
|
2134 | time_t now = time (NULL); |
|
|
2135 | strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now)); |
|
|
2136 | buf << buf2; |
|
|
2137 | } |
|
|
2138 | |
|
|
2139 | return buf; |
|
|
2140 | } |
2169 | } |
2141 | |
2170 | |
2142 | void |
2171 | void |
2143 | do_some_living (object *op) |
2172 | do_some_living (object *op) |
2144 | { |
2173 | { |
… | |
… | |
2399 | return; |
2428 | return; |
2400 | |
2429 | |
2401 | dynbuf_text deathtab; |
2430 | dynbuf_text deathtab; |
2402 | |
2431 | |
2403 | /* restore player */ |
2432 | /* restore player */ |
2404 | at = archetype::find ("poisoning"); |
2433 | at = archetype::find (shstr_poisoning); |
2405 | if (object *tmp = present_arch_in_ob (at, op)) |
2434 | if (object *tmp = present_arch_in_ob (at, op)) |
2406 | { |
2435 | { |
2407 | tmp->destroy (); |
2436 | tmp->destroy (); |
2408 | deathtab << "Your body feels cleansed...\r"; |
2437 | deathtab << "Your body feels cleansed...\r"; |
2409 | } |
2438 | } |
2410 | |
2439 | |
2411 | at = archetype::find ("confusion"); |
2440 | at = archetype::find (shstr_confusion); |
2412 | if (object *tmp = present_arch_in_ob (at, op)) |
2441 | if (object *tmp = present_arch_in_ob (at, op)) |
2413 | { |
2442 | { |
2414 | tmp->destroy (); |
2443 | tmp->destroy (); |
2415 | deathtab << "Your mind feels clearer...\r"; |
2444 | deathtab << "Your mind feels clearer...\r"; |
2416 | } |
2445 | } |
… | |
… | |
2443 | if (op_on_battleground (op, &x, &y)) |
2472 | if (op_on_battleground (op, &x, &y)) |
2444 | { |
2473 | { |
2445 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2474 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2446 | |
2475 | |
2447 | /* create a bodypart-trophy to make the winner happy */ |
2476 | /* create a bodypart-trophy to make the winner happy */ |
2448 | if (object *tmp = arch_to_object (archetype::find ("finger"))) |
2477 | object *tmp = archetype::find (shstr_finger)->instance (); |
2449 | { |
2478 | |
2450 | tmp->name = format ("%s's finger" , &op->name); |
2479 | tmp->name = format ("%s's finger" , &op->name); |
2451 | tmp->name_pl = format ("%s's fingers", &op->name); |
2480 | tmp->name_pl = format ("%s's fingers", &op->name); |
2452 | tmp->msg = format ( |
2481 | tmp->msg = format ( |
2453 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2482 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2454 | &op->name, op->contr->title, |
2483 | &op->name, op->contr->title, |
2455 | (int)op->level, |
2484 | (int)op->level, |
2456 | op->contr->killer_name () |
2485 | op->contr->killer_name () |
2457 | ); |
2486 | ); |
2458 | tmp->value = 0, tmp->type = 0; |
2487 | tmp->value = 0, tmp->type = 0; |
2459 | tmp->materialname = "organics"; |
2488 | tmp->material = name_to_material (shstr_organic); |
2460 | tmp->insert_at (op, tmp); |
2489 | tmp->insert_at (op, tmp); |
2461 | } |
|
|
2462 | |
2490 | |
2463 | /* teleport defeated player to new destination */ |
2491 | /* teleport defeated player to new destination */ |
2464 | transfer_ob (op, x, y, 0, NULL); |
2492 | transfer_ob (op, x, y, 0, NULL); |
2465 | op->contr->braced = 0; |
2493 | op->contr->braced = 0; |
2466 | |
2494 | |
… | |
… | |
2528 | lost_a_stat = 1; |
2556 | lost_a_stat = 1; |
2529 | } |
2557 | } |
2530 | else |
2558 | else |
2531 | { |
2559 | { |
2532 | /* deplete a stat */ |
2560 | /* deplete a stat */ |
2533 | archetype *deparch = archetype::find ("depletion"); |
2561 | archetype *deparch = archetype::find (shstr_depletion); |
2534 | object *dep; |
2562 | object *dep; |
2535 | |
2563 | |
2536 | dep = present_arch_in_ob (deparch, op); |
2564 | dep = present_arch_in_ob (deparch, op); |
2537 | if (!dep) |
2565 | if (!dep) |
2538 | { |
2566 | { |
2539 | dep = arch_to_object (deparch); |
2567 | dep = deparch->instance (); |
2540 | insert_ob_in_ob (dep, op); |
2568 | insert_ob_in_ob (dep, op); |
2541 | } |
2569 | } |
2542 | lose_this_stat = 1; |
2570 | lose_this_stat = 1; |
2543 | if (settings.balanced_stat_loss) |
2571 | if (settings.balanced_stat_loss) |
2544 | { |
2572 | { |
… | |
… | |
2610 | #endif |
2638 | #endif |
2611 | |
2639 | |
2612 | /* Put a gravestone up where the character 'almost' died. List the |
2640 | /* Put a gravestone up where the character 'almost' died. List the |
2613 | * exp loss on the stone. |
2641 | * exp loss on the stone. |
2614 | */ |
2642 | */ |
2615 | tmp = arch_to_object (archetype::find ("gravestone")); |
2643 | tmp = archetype::find (shstr_gravestone)->instance (); |
2616 | tmp->name = format ("%s's gravestone", &op->name); |
2644 | tmp->name = format ("%s's gravestone", &op->name); |
2617 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2645 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2618 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2646 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2619 | &op->name, op->contr->title, op->contr->killer_name ()); |
2647 | &op->name, op->contr->title, op->contr->killer_name ()); |
2620 | tmp->x = op->x, tmp->y = op->y; |
2648 | tmp->x = op->x, tmp->y = op->y; |
… | |
… | |
2675 | } |
2703 | } |
2676 | |
2704 | |
2677 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2705 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2678 | } |
2706 | } |
2679 | |
2707 | |
2680 | void |
2708 | static void |
2681 | loot_object (object *op) |
2709 | loot_object (object *op) |
2682 | { /* Grab and destroy some treasure */ |
2710 | { /* Grab and destroy some treasure */ |
2683 | object *tmp, *tmp2, *next; |
2711 | object *tmp, *tmp2, *next; |
2684 | |
2712 | |
2685 | op->close_container (); /* close open sack first */ |
2713 | op->close_container (); /* close open sack first */ |
… | |
… | |
2716 | * fix_weight(): Check recursively the weight of all players, and fix |
2744 | * fix_weight(): Check recursively the weight of all players, and fix |
2717 | * what needs to be fixed. Refresh windows and fix speed if anything |
2745 | * what needs to be fixed. Refresh windows and fix speed if anything |
2718 | * was changed. |
2746 | * was changed. |
2719 | */ |
2747 | */ |
2720 | void |
2748 | void |
2721 | fix_weight (void) |
2749 | fix_weight () |
2722 | { |
2750 | { |
2723 | for_all_players (pl) |
2751 | for_all_players (pl) |
2724 | { |
2752 | { |
2725 | sint32 old = pl->ob->carrying; |
2753 | sint32 old = pl->ob->carrying; |
2726 | |
2754 | |
… | |
… | |
2733 | } |
2761 | } |
2734 | } |
2762 | } |
2735 | } |
2763 | } |
2736 | |
2764 | |
2737 | void |
2765 | void |
2738 | fix_luck (void) |
2766 | fix_luck () |
2739 | { |
2767 | { |
2740 | for_all_players (pl) |
2768 | for_all_players (pl) |
2741 | if (!pl->ob->contr->ns->state) |
2769 | if (!pl->ob->contr->ns->state) |
2742 | pl->ob->change_luck (0); |
2770 | pl->ob->change_luck (0); |
2743 | } |
2771 | } |
… | |
… | |
2987 | } |
3015 | } |
2988 | |
3016 | |
2989 | return 0; |
3017 | return 0; |
2990 | } |
3018 | } |
2991 | |
3019 | |
2992 | /* routine for both players and monsters. We call this when |
|
|
2993 | * there is a possibility for our action distrubing our hiding |
|
|
2994 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
2995 | * "noise" instead. If we arent invisible to begin with, we |
|
|
2996 | * return 0. |
|
|
2997 | */ |
|
|
2998 | int |
|
|
2999 | action_makes_visible (object *op) |
|
|
3000 | { |
|
|
3001 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
3002 | { |
|
|
3003 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
3004 | { |
|
|
3005 | // artefact invisibility is permanent, but we still make noise |
|
|
3006 | // this is important for game-balance. |
|
|
3007 | if (op->contr) |
|
|
3008 | op->make_noise (); |
|
|
3009 | |
|
|
3010 | return 0; |
|
|
3011 | } |
|
|
3012 | |
|
|
3013 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
3014 | return 0; |
|
|
3015 | |
|
|
3016 | /* If monsters, they should become visible */ |
|
|
3017 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
3018 | { |
|
|
3019 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
3020 | return 1; |
|
|
3021 | } |
|
|
3022 | } |
|
|
3023 | |
|
|
3024 | return 0; |
|
|
3025 | } |
|
|
3026 | |
|
|
3027 | /* op_on_battleground - checks if the given object op (usually |
3020 | /* op_on_battleground - checks if the given object op (usually |
3028 | * a player) is standing on a valid battleground-tile, |
3021 | * a player) is standing on a valid battleground-tile, |
3029 | * function returns TRUE/FALSE. If true x, y returns the battleground |
3022 | * function returns TRUE/FALSE. If true x, y returns the battleground |
3030 | * -exit-coord. (and if x, y not NULL) |
3023 | * -exit-coord. (and if x, y not NULL) |
3031 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
3024 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
… | |
… | |
3050 | && tmp->name == shstr_battleground |
3043 | && tmp->name == shstr_battleground |
3051 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3044 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3052 | { |
3045 | { |
3053 | /* before we assign the exit, check if this is a teambattle */ |
3046 | /* before we assign the exit, check if this is a teambattle */ |
3054 | 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)) |
3055 | { |
|
|
3056 | 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) |
3057 | { |
3050 | { |
3058 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
|
|
3059 | { |
|
|
3060 | if (x && y) |
3051 | if (x && y) |
3061 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3052 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3062 | |
3053 | |
3063 | return 1; |
3054 | return 1; |
3064 | } |
|
|
3065 | } |
3055 | } |
3066 | } |
|
|
3067 | |
3056 | |
3068 | if (x && y) |
3057 | if (x && y) |
3069 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3058 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3070 | |
3059 | |
3071 | return 1; |
3060 | return 1; |
… | |
… | |
3228 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3217 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3229 | } |
3218 | } |
3230 | else |
3219 | else |
3231 | { |
3220 | { |
3232 | /* generate misc. treasure */ |
3221 | /* generate misc. treasure */ |
3233 | tmp = arch_to_object (tr->item); |
3222 | tmp = tr->item->instance (); |
3234 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3223 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3235 | who->insert (tmp); |
3224 | who->insert (tmp); |
3236 | } |
3225 | } |
3237 | } |
3226 | } |
3238 | |
3227 | |
… | |
… | |
3251 | |
3240 | |
3252 | if (pl->ranged_ob == ob) |
3241 | if (pl->ranged_ob == ob) |
3253 | pl->ranged_ob = 0; |
3242 | pl->ranged_ob = 0; |
3254 | } |
3243 | } |
3255 | |
3244 | |
|
|
3245 | //-GPL |
|
|
3246 | |
3256 | sint8 |
3247 | sint8 |
3257 | player::darkness_at (maptile *map, int x, int y) const |
3248 | player::darkness_at (maptile *map, int x, int y) const |
3258 | { |
3249 | { |
3259 | if (!ns) |
3250 | if (!ns) |
3260 | return LOS_BLOCKED; |
3251 | return LOS_BLOCKED; |