ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.160 by root, Mon Oct 12 14:00:57 2009 UTC vs.
Revision 1.166 by root, Wed Oct 21 00:44:39 2009 UTC

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 */
73int 73int
74blocked_link (object *ob, maptile *m, int sx, int sy) 74blocked_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 {
84 LOG (llevError, "blocked_link: Passed map, x, y coordinates outside of map\n"); 81 LOG (llevError, "blocked_link: Passed map, x, y coordinates outside of map\n");
85 return 1; 82 return 1;
86 } 83 }
87 84
88 /* Save some cycles - instead of calling get_map_flags(), just get the value 85 mapspace &ms = m->at (sx, sy);
89 * directly.
90 */
91 mflags = m->at (sx, sy).flags ();
92 86
93 blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); 87 int mflags = ms.flags ();
88 int blocked = ms.move_block;
94 89
95 /* If space is currently not blocked by anything, no need to 90 /* If space is currently not blocked by anything, no need to
96 * go further. Not true for players - all sorts of special 91 * go further. Not true for players - all sorts of special
97 * things we need to do for players. 92 * things we need to do for players.
98 */ 93 */
99 if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && (blocked == 0)) 94 if (ob->type != PLAYER && !(mflags & P_IS_ALIVE) && (blocked == 0))
100 return 0; 95 return 0;
101 96
102 /* if there isn't anytyhing alive on this space, and this space isn't 97 /* 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 98 * 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 99 * 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 100 * or another. Likewise, only if something is blocking us do we
106 * need to investigate if there is a special circumstance that would 101 * need to investigate if there is a special circumstance that would
107 * let the player through (inventory checkers for example) 102 * let the player through (inventory checkers for example)
114 /* We basically go through the stack of objects, and if there is 109 /* 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 110 * some other object that has NO_PASS or FLAG_ALIVE set, return
116 * true. If we get through the entire stack, that must mean 111 * true. If we get through the entire stack, that must mean
117 * ob is blocking it, so return 0. 112 * ob is blocking it, so return 0.
118 */ 113 */
119 for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) 114 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
120 { 115 {
121 116 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 { 117 {
125 /* If last_sp is set, the player/monster needs an object, 118 if (INVOKE_OBJECT (BLOCKED_MOVE, tmp, ob))
126 * so we check for it. If they don't have it, they can't 119 if (RESULT_INT (0))
127 * pass through this space. 120 return 1;
128 */ 121 else
129 if (tmp->last_sp) 122 continue;
123
124 if (tmp->type == CHECK_INV)
130 { 125 {
131 if (check_inv_recursive (ob, tmp) == NULL) 126 bool have = check_inv_recursive (ob, tmp);
127
128 // last_sp set means we block if we don't have.
129 if (logical_xor (have, tmp->last_sp))
132 return 1; 130 return 1;
133 else 131 }
134 continue; 132 else if (tmp->type == T_MATCH)
133 {
134 // T_MATCH allows "entrance" iff the match is true
135 // == blocks if the match fails
136
137 // we could have used an INVOKE_OBJECT, but decided against it, as we
138 // assume that T_MATCH is relatively common.
139 if (!match (tmp->slaying, ob, tmp, ob))
140 return 1;
135 } 141 }
136 else 142 else
137 { 143 return 1; // unconditional block
138 /* In this case, the player must not have the object - 144
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 145 } else {
148 { 146 // space does not block the ob, directly, but
149 /* Broke apart a big nasty if into several here to make 147 // anything alive that is not a door still
150 * this more readable. first check - if the space blocks 148 // 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 149
158 if (tmp->flag [FLAG_ALIVE] 150 if (tmp->flag [FLAG_ALIVE]
159 && tmp->head_ () != ob 151 && tmp->head_ () != ob
160 && tmp != ob 152 && tmp != ob
161 && tmp->type != DOOR 153 && tmp->type != DOOR
162 && !(tmp->flag [FLAG_WIZ] && tmp->contr->hidden)) 154 && !tmp->flag [FLAG_WIZPASS])
163 return 1; 155 return 1;
164 } 156 }
165
166 } 157 }
158
167 return 0; 159 return 0;
168} 160}
169 161
170/* 162/*
171 * Returns qthe blocking object if the given object can't fit in the given 163 * Returns qthe blocking object if the given object can't fit in the given
565 return items; 557 return items;
566} 558}
567 559
568/* opposite of parse string, this puts the string that was originally fed in to 560/* opposite of parse string, this puts the string that was originally fed in to
569 * the map (or something equivilent) into output_string. */ 561 * the map (or something equivilent) into output_string. */
570static void 562static const char *
571print_shop_string (maptile *m, char *output_string) 563print_shop_string (maptile *m)
572{ 564{
573 int i; 565 static dynbuf_text buf; buf.clear ();
574 char tmp[MAX_BUF];
575 566
576 strcpy (output_string, "");
577 for (i = 0; i < m->shopitems[0].index; i++) 567 for (int i = 0; i < m->shopitems[0].index; i++)
578 { 568 {
579 if (m->shopitems[i].typenum) 569 if (m->shopitems[i].typenum)
580 { 570 {
581 if (m->shopitems[i].strength) 571 if (m->shopitems[i].strength)
582 sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); 572 buf.printf ("%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
583 else 573 else
584 sprintf (tmp, "%s;", m->shopitems[i].name); 574 buf.printf ("%s;", m->shopitems[i].name);
585 } 575 }
586 else 576 else
587 { 577 {
588 if (m->shopitems[i].strength) 578 if (m->shopitems[i].strength)
589 sprintf (tmp, "*:%d;", m->shopitems[i].strength); 579 buf.printf ("*:%d;", m->shopitems[i].strength);
590 else 580 else
591 sprintf (tmp, "*"); 581 buf.printf ("*");
592 } 582 }
593
594 strcat (output_string, tmp);
595 } 583 }
584
585 return buf;
596} 586}
597 587
598/* This loads the header information of the map. The header 588/* This loads the header information of the map. The header
599 * contains things like difficulty, size, timeout, etc. 589 * contains things like difficulty, size, timeout, etc.
600 * this used to be stored in the map object, but with the 590 * this used to be stored in the map object, but with the
735 MAP_OUT (reset_timeout); 725 MAP_OUT (reset_timeout);
736 MAP_OUT (fixed_resettime); 726 MAP_OUT (fixed_resettime);
737 MAP_OUT (no_reset); 727 MAP_OUT (no_reset);
738 MAP_OUT (no_drop); 728 MAP_OUT (no_drop);
739 MAP_OUT (difficulty); 729 MAP_OUT (difficulty);
740
741 if (default_region) MAP_OUT2 (region, default_region->name); 730 if (default_region) MAP_OUT2 (region, default_region->name);
742 731
743 if (shopitems) 732 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); 733 MAP_OUT (shopgreed);
751 MAP_OUT (shopmin); 734 MAP_OUT (shopmin);
752 MAP_OUT (shopmax); 735 MAP_OUT (shopmax);
753 if (shoprace) MAP_OUT (shoprace); 736 if (shoprace) MAP_OUT (shoprace);
737
754 MAP_OUT (darkness); 738 MAP_OUT (darkness);
755 MAP_OUT (width); 739 MAP_OUT (width);
756 MAP_OUT (height); 740 MAP_OUT (height);
757 MAP_OUT (enter_x); 741 MAP_OUT (enter_x);
758 MAP_OUT (enter_y); 742 MAP_OUT (enter_y);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines