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.164 by root, Fri Oct 16 01:19:12 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 {
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 {
119 bool block = OB_MOVE_BLOCK (ob, tmp);
121 120
122 /* This must be before the checks below. Code for inventory checkers. */ 121 /* This must be before the checks below. Code for inventory checkers. */
123 if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) 122 if (block && tmp->type == CHECK_INV)
124 { 123 {
124 bool have = check_inv_recursive (ob, tmp);
125
125 /* If last_sp is set, the player/monster needs an object, 126 /* If last_sp is set, the player/monster needs an object,
126 * so we check for it. If they don't have it, they can't 127 * so we check for it. If they don't have it, they can't
127 * pass through this space. 128 * pass through this space.
128 */ 129 */
129 if (tmp->last_sp) 130 if (tmp->last_sp)
130 { 131 {
131 if (check_inv_recursive (ob, tmp) == NULL) 132 if (!have)
132 return 1; 133 return 1;
133 else
134 continue;
135 } 134 }
136 else 135 else
137 { 136 {
138 /* In this case, the player must not have the object - 137 /* In this case, the player must not have the object -
139 * if they do, they can't pass through. 138 * if they do, they can't pass through.
140 */ 139 */
141 if (check_inv_recursive (ob, tmp) != NULL) /* player has object */ 140 if (have)
142 return 1; 141 return 1;
143 else
144 continue;
145 } 142 }
146 } /* if check_inv */ 143 }
144 else if (block && tmp->type == T_MATCH)
145 {
146 //TODO
147 }
147 else 148 else
148 { 149 {
149 /* Broke apart a big nasty if into several here to make 150 /* Broke apart a big nasty if into several here to make
150 * this more readable. first check - if the space blocks 151 * this more readable. first check - if the space blocks
151 * movement, can't move here. 152 * movement, can't move here.
152 * second - if a monster, can't move there, unless it is a 153 * second - if a monster, can't move there, unless it is a
153 * hidden dm 154 * dm.
154 */ 155 */
155 if (OB_MOVE_BLOCK (ob, tmp)) 156 if (block)
156 return 1; 157 return 1;
157 158
158 if (tmp->flag [FLAG_ALIVE] 159 if (tmp->flag [FLAG_ALIVE]
159 && tmp->head_ () != ob 160 && tmp->head_ () != ob
160 && tmp != ob 161 && tmp != ob
161 && tmp->type != DOOR 162 && tmp->type != DOOR
162 && !(tmp->flag [FLAG_WIZ] && tmp->contr->hidden)) 163 && !tmp->flag [FLAG_WIZ])
163 return 1; 164 return 1;
164 } 165 }
165
166 } 166 }
167
167 return 0; 168 return 0;
168} 169}
169 170
170/* 171/*
171 * Returns qthe blocking object if the given object can't fit in the given 172 * Returns qthe blocking object if the given object can't fit in the given
565 return items; 566 return items;
566} 567}
567 568
568/* opposite of parse string, this puts the string that was originally fed in to 569/* opposite of parse string, this puts the string that was originally fed in to
569 * the map (or something equivilent) into output_string. */ 570 * the map (or something equivilent) into output_string. */
570static void 571static const char *
571print_shop_string (maptile *m, char *output_string) 572print_shop_string (maptile *m)
572{ 573{
573 int i; 574 static dynbuf_text buf; buf.clear ();
574 char tmp[MAX_BUF];
575 575
576 strcpy (output_string, "");
577 for (i = 0; i < m->shopitems[0].index; i++) 576 for (int i = 0; i < m->shopitems[0].index; i++)
578 { 577 {
579 if (m->shopitems[i].typenum) 578 if (m->shopitems[i].typenum)
580 { 579 {
581 if (m->shopitems[i].strength) 580 if (m->shopitems[i].strength)
582 sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); 581 buf.printf ("%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
583 else 582 else
584 sprintf (tmp, "%s;", m->shopitems[i].name); 583 buf.printf ("%s;", m->shopitems[i].name);
585 } 584 }
586 else 585 else
587 { 586 {
588 if (m->shopitems[i].strength) 587 if (m->shopitems[i].strength)
589 sprintf (tmp, "*:%d;", m->shopitems[i].strength); 588 buf.printf ("*:%d;", m->shopitems[i].strength);
590 else 589 else
591 sprintf (tmp, "*"); 590 buf.printf ("*");
592 } 591 }
593
594 strcat (output_string, tmp);
595 } 592 }
593
594 return buf;
596} 595}
597 596
598/* This loads the header information of the map. The header 597/* This loads the header information of the map. The header
599 * contains things like difficulty, size, timeout, etc. 598 * contains things like difficulty, size, timeout, etc.
600 * this used to be stored in the map object, but with the 599 * this used to be stored in the map object, but with the
735 MAP_OUT (reset_timeout); 734 MAP_OUT (reset_timeout);
736 MAP_OUT (fixed_resettime); 735 MAP_OUT (fixed_resettime);
737 MAP_OUT (no_reset); 736 MAP_OUT (no_reset);
738 MAP_OUT (no_drop); 737 MAP_OUT (no_drop);
739 MAP_OUT (difficulty); 738 MAP_OUT (difficulty);
740
741 if (default_region) MAP_OUT2 (region, default_region->name); 739 if (default_region) MAP_OUT2 (region, default_region->name);
742 740
743 if (shopitems) 741 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); 742 MAP_OUT (shopgreed);
751 MAP_OUT (shopmin); 743 MAP_OUT (shopmin);
752 MAP_OUT (shopmax); 744 MAP_OUT (shopmax);
753 if (shoprace) MAP_OUT (shoprace); 745 if (shoprace) MAP_OUT (shoprace);
746
754 MAP_OUT (darkness); 747 MAP_OUT (darkness);
755 MAP_OUT (width); 748 MAP_OUT (width);
756 MAP_OUT (height); 749 MAP_OUT (height);
757 MAP_OUT (enter_x); 750 MAP_OUT (enter_x);
758 MAP_OUT (enter_y); 751 MAP_OUT (enter_y);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines