1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
71 | * by the caller. |
71 | * by the caller. |
72 | */ |
72 | */ |
73 | int |
73 | int |
74 | blocked_link (object *ob, maptile *m, int sx, int sy) |
74 | blocked_link (object *ob, maptile *m, int sx, int sy) |
75 | { |
75 | { |
76 | object *tmp; |
|
|
77 | int mflags, blocked; |
|
|
78 | |
|
|
79 | /* Make sure the coordinates are valid - they should be, as caller should |
76 | /* Make sure the coordinates are valid - they should be, as caller should |
80 | * have already checked this. |
77 | * have already checked this. |
81 | */ |
78 | */ |
82 | if (OUT_OF_REAL_MAP (m, sx, sy)) |
79 | if (OUT_OF_REAL_MAP (m, sx, sy)) |
83 | { |
80 | { |
… | |
… | |
86 | } |
83 | } |
87 | |
84 | |
88 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
85 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
89 | * directly. |
86 | * directly. |
90 | */ |
87 | */ |
91 | mflags = m->at (sx, sy).flags (); |
88 | mapspace &ms = m->at (sx, sy); |
92 | |
89 | |
93 | blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); |
90 | int mflags = ms.flags (); |
|
|
91 | int blocked = ms.move_block; |
94 | |
92 | |
95 | /* If space is currently not blocked by anything, no need to |
93 | /* If space is currently not blocked by anything, no need to |
96 | * go further. Not true for players - all sorts of special |
94 | * go further. Not true for players - all sorts of special |
97 | * things we need to do for players. |
95 | * things we need to do for players. |
98 | */ |
96 | */ |
99 | if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && (blocked == 0)) |
97 | if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && (blocked == 0)) |
100 | return 0; |
98 | return 0; |
101 | |
99 | |
102 | /* if there isn't anytyhing alive on this space, and this space isn't |
100 | /* if there isn't anything alive on this space, and this space isn't |
103 | * otherwise blocked, we can return now. Only if there is a living |
101 | * otherwise blocked, we can return now. Only if there is a living |
104 | * creature do we need to investigate if it is part of this creature |
102 | * creature do we need to investigate if it is part of this creature |
105 | * or another. Likewise, only if something is blocking us do we |
103 | * or another. Likewise, only if something is blocking us do we |
106 | * need to investigate if there is a special circumstance that would |
104 | * need to investigate if there is a special circumstance that would |
107 | * let the player through (inventory checkers for example) |
105 | * let the player through (inventory checkers for example) |
… | |
… | |
114 | /* We basically go through the stack of objects, and if there is |
112 | /* We basically go through the stack of objects, and if there is |
115 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
113 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
116 | * true. If we get through the entire stack, that must mean |
114 | * true. If we get through the entire stack, that must mean |
117 | * ob is blocking it, so return 0. |
115 | * ob is blocking it, so return 0. |
118 | */ |
116 | */ |
119 | for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) |
117 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
120 | { |
118 | { |
121 | |
119 | if (OB_MOVE_BLOCK (ob, tmp)) |
122 | /* This must be before the checks below. Code for inventory checkers. */ |
|
|
123 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
|
|
124 | { |
120 | { |
125 | /* If last_sp is set, the player/monster needs an object, |
121 | if (tmp->type == CHECK_INV) |
126 | * so we check for it. If they don't have it, they can't |
|
|
127 | * pass through this space. |
|
|
128 | */ |
|
|
129 | if (tmp->last_sp) |
|
|
130 | { |
122 | { |
131 | if (check_inv_recursive (ob, tmp) == NULL) |
123 | bool have = check_inv_recursive (ob, tmp); |
|
|
124 | |
|
|
125 | // last_sp set means we block if we don't have. |
|
|
126 | if (logical_xor (have, tmp->last_sp)) |
132 | return 1; |
127 | return 1; |
133 | else |
128 | } |
134 | continue; |
129 | else if (tmp->type == T_MATCH) |
|
|
130 | { |
|
|
131 | // T_MATCH allows "entrance" iff the match is true |
|
|
132 | // == blocks if the match fails |
|
|
133 | |
|
|
134 | // we could have used an INVOKE_OBJECT, but decided against it, as we |
|
|
135 | // assume that T_MATCH is very common. |
|
|
136 | if (!match (tmp->slaying, ob, tmp, ob)) |
|
|
137 | return 1; |
135 | } |
138 | } |
136 | else |
139 | else |
137 | { |
140 | return 1; // unconditional block |
138 | /* In this case, the player must not have the object - |
141 | |
139 | * if they do, they can't pass through. |
|
|
140 | */ |
|
|
141 | if (check_inv_recursive (ob, tmp) != NULL) /* player has object */ |
|
|
142 | return 1; |
|
|
143 | else |
|
|
144 | continue; |
|
|
145 | } |
|
|
146 | } /* if check_inv */ |
|
|
147 | else |
142 | } else { |
148 | { |
143 | // space does not block the ob, directly, but |
149 | /* Broke apart a big nasty if into several here to make |
144 | // anything alive that is not a door still |
150 | * this more readable. first check - if the space blocks |
145 | // blocks anything but wizards. |
151 | * movement, can't move here. |
|
|
152 | * second - if a monster, can't move there, unless it is a |
|
|
153 | * hidden dm |
|
|
154 | */ |
|
|
155 | if (OB_MOVE_BLOCK (ob, tmp)) |
|
|
156 | return 1; |
|
|
157 | |
146 | |
158 | if (tmp->flag [FLAG_ALIVE] |
147 | if (tmp->flag [FLAG_ALIVE] |
159 | && tmp->head_ () != ob |
148 | && tmp->head_ () != ob |
160 | && tmp != ob |
149 | && tmp != ob |
161 | && tmp->type != DOOR |
150 | && tmp->type != DOOR |
162 | && !(tmp->flag [FLAG_WIZ] && tmp->contr->hidden)) |
151 | && !tmp->flag [FLAG_WIZPASS]) |
163 | return 1; |
152 | return 1; |
164 | } |
153 | } |
165 | |
|
|
166 | } |
154 | } |
|
|
155 | |
167 | return 0; |
156 | return 0; |
168 | } |
157 | } |
169 | |
158 | |
170 | /* |
159 | /* |
171 | * Returns qthe blocking object if the given object can't fit in the given |
160 | * Returns qthe blocking object if the given object can't fit in the given |
… | |
… | |
565 | return items; |
554 | return items; |
566 | } |
555 | } |
567 | |
556 | |
568 | /* opposite of parse string, this puts the string that was originally fed in to |
557 | /* opposite of parse string, this puts the string that was originally fed in to |
569 | * the map (or something equivilent) into output_string. */ |
558 | * the map (or something equivilent) into output_string. */ |
570 | static void |
559 | static const char * |
571 | print_shop_string (maptile *m, char *output_string) |
560 | print_shop_string (maptile *m) |
572 | { |
561 | { |
573 | int i; |
562 | static dynbuf_text buf; buf.clear (); |
574 | char tmp[MAX_BUF]; |
|
|
575 | |
563 | |
576 | strcpy (output_string, ""); |
|
|
577 | for (i = 0; i < m->shopitems[0].index; i++) |
564 | for (int i = 0; i < m->shopitems[0].index; i++) |
578 | { |
565 | { |
579 | if (m->shopitems[i].typenum) |
566 | if (m->shopitems[i].typenum) |
580 | { |
567 | { |
581 | if (m->shopitems[i].strength) |
568 | if (m->shopitems[i].strength) |
582 | sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); |
569 | buf.printf ("%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); |
583 | else |
570 | else |
584 | sprintf (tmp, "%s;", m->shopitems[i].name); |
571 | buf.printf ("%s;", m->shopitems[i].name); |
585 | } |
572 | } |
586 | else |
573 | else |
587 | { |
574 | { |
588 | if (m->shopitems[i].strength) |
575 | if (m->shopitems[i].strength) |
589 | sprintf (tmp, "*:%d;", m->shopitems[i].strength); |
576 | buf.printf ("*:%d;", m->shopitems[i].strength); |
590 | else |
577 | else |
591 | sprintf (tmp, "*"); |
578 | buf.printf ("*"); |
592 | } |
579 | } |
593 | |
|
|
594 | strcat (output_string, tmp); |
|
|
595 | } |
580 | } |
|
|
581 | |
|
|
582 | return buf; |
596 | } |
583 | } |
597 | |
584 | |
598 | /* This loads the header information of the map. The header |
585 | /* This loads the header information of the map. The header |
599 | * contains things like difficulty, size, timeout, etc. |
586 | * contains things like difficulty, size, timeout, etc. |
600 | * this used to be stored in the map object, but with the |
587 | * this used to be stored in the map object, but with the |
… | |
… | |
735 | MAP_OUT (reset_timeout); |
722 | MAP_OUT (reset_timeout); |
736 | MAP_OUT (fixed_resettime); |
723 | MAP_OUT (fixed_resettime); |
737 | MAP_OUT (no_reset); |
724 | MAP_OUT (no_reset); |
738 | MAP_OUT (no_drop); |
725 | MAP_OUT (no_drop); |
739 | MAP_OUT (difficulty); |
726 | MAP_OUT (difficulty); |
740 | |
|
|
741 | if (default_region) MAP_OUT2 (region, default_region->name); |
727 | if (default_region) MAP_OUT2 (region, default_region->name); |
742 | |
728 | |
743 | if (shopitems) |
729 | if (shopitems) MAP_OUT2 (shopitems, print_shop_string (this)); |
744 | { |
|
|
745 | char shop[MAX_BUF]; |
|
|
746 | print_shop_string (this, shop); |
|
|
747 | MAP_OUT2 (shopitems, shop); |
|
|
748 | } |
|
|
749 | |
|
|
750 | MAP_OUT (shopgreed); |
730 | MAP_OUT (shopgreed); |
751 | MAP_OUT (shopmin); |
731 | MAP_OUT (shopmin); |
752 | MAP_OUT (shopmax); |
732 | MAP_OUT (shopmax); |
753 | if (shoprace) MAP_OUT (shoprace); |
733 | if (shoprace) MAP_OUT (shoprace); |
|
|
734 | |
754 | MAP_OUT (darkness); |
735 | MAP_OUT (darkness); |
755 | MAP_OUT (width); |
736 | MAP_OUT (width); |
756 | MAP_OUT (height); |
737 | MAP_OUT (height); |
757 | MAP_OUT (enter_x); |
738 | MAP_OUT (enter_x); |
758 | MAP_OUT (enter_y); |
739 | MAP_OUT (enter_y); |