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.168 by root, Fri Nov 6 13:03:34 2009 UTC vs.
Revision 1.174 by root, Tue Nov 10 05:05:22 2009 UTC

218 218
219 return 0; 219 return 0;
220} 220}
221 221
222/* When the map is loaded, load_object does not actually insert objects 222/* When the map is loaded, load_object does not actually insert objects
223 * into inventory, but just links them. What this does is go through 223 * into inventory, but just links them. What this does is go through
224 * and insert them properly. 224 * and insert them properly.
225 * The object 'container' is the object that contains the inventory. 225 * The object 'container' is the object that contains the inventory.
226 * This is needed so that we can update the containers weight. 226 * This is needed so that we can update the containers weight.
227 */ 227 */
228static void 228static void
448 * map archetype. Mimic that behaviour. 448 * map archetype. Mimic that behaviour.
449 */ 449 */
450 width = 16; 450 width = 16;
451 height = 16; 451 height = 16;
452 timeout = 300; 452 timeout = 300;
453 max_nrof = 1000; // 1000 items of anything 453 max_items = MAX_ITEM_PER_ACTION;
454 max_volume = 2000000; // 2m³ 454 max_volume = 2000000; // 2m³
455} 455}
456 456
457maptile::maptile (int w, int h) 457maptile::maptile (int w, int h)
458{ 458{
1027 */ 1027 */
1028void 1028void
1029mapspace::update_ () 1029mapspace::update_ ()
1030{ 1030{
1031 object *last = 0; 1031 object *last = 0;
1032 uint8 flags = P_UPTODATE, anywhere = 0; 1032 uint8 flags = P_UPTODATE;
1033 sint8 light = 0; 1033 sint8 light = 0;
1034 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; 1034 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1035 uint64_t volume = 0;
1036 uint32_t items = 0;
1037 object *anywhere = 0;
1038 uint8_t middle_visibility = 0;
1035 1039
1036 //object *middle = 0; 1040 //object *middle = 0;
1037 //object *top = 0; 1041 //object *top = 0;
1038 //object *floor = 0; 1042 //object *floor = 0;
1039 // this seems to generate better code than using locals, above 1043 // this seems to generate better code than using locals, above
1040 object *&top = faces_obj[0] = 0; 1044 object *&top = faces_obj[0] = 0;
1041 object *&middle = faces_obj[1] = 0; 1045 object *&middle = faces_obj[1] = 0;
1042 object *&floor = faces_obj[2] = 0; 1046 object *&floor = faces_obj[2] = 0;
1047
1048 object::flags_t allflags; // all flags of all objects or'ed together
1043 1049
1044 for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) 1050 for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above)
1045 { 1051 {
1046 // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) 1052 // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C)
1047 light += tmp->glow_radius; 1053 light += tmp->glow_radius;
1052 * 3 times each time the player moves, because many of the 1058 * 3 times each time the player moves, because many of the
1053 * functions the move_player calls eventualy call this. 1059 * functions the move_player calls eventualy call this.
1054 * 1060 *
1055 * Always put the player down for drawing. 1061 * Always put the player down for drawing.
1056 */ 1062 */
1057 if (!tmp->invisible) 1063 if (expect_true (!tmp->invisible))
1058 { 1064 {
1059 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) 1065 if (expect_false (tmp->type == PLAYER || tmp->flag [FLAG_MONSTER]))
1060 top = tmp; 1066 top = tmp;
1061 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1067 else if (expect_false (tmp->flag [FLAG_IS_FLOOR]))
1062 { 1068 {
1063 /* If we got a floor, that means middle and top were below it, 1069 /* If we got a floor, that means middle and top were below it,
1064 * so should not be visible, so we clear them. 1070 * so should not be visible, so we clear them.
1065 */ 1071 */
1066 middle = 0; 1072 middle = 0;
1067 top = 0; 1073 top = 0;
1068 floor = tmp; 1074 floor = tmp;
1075 volume = 0;
1076 items = 0;
1069 } 1077 }
1070 /* Flag anywhere have high priority */ 1078 else
1071 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE))
1072 { 1079 {
1080 if (expect_true (!tmp->flag [FLAG_NO_PICK]))
1081 {
1082 ++items;
1083 volume += tmp->volume ();
1084 }
1085
1086 /* Flag anywhere have high priority */
1087 if (expect_false (tmp->flag [FLAG_SEE_ANYWHERE]))
1088 anywhere = tmp;
1089
1090 /* Find the highest visible face around. If equal
1091 * visibilities, we still want the one nearer to the
1092 * top
1093 */
1094 if (expect_false (::faces [tmp->face].visibility >= middle_visibility))
1095 {
1096 middle_visibility = ::faces [tmp->face].visibility;
1073 middle = tmp; 1097 middle = tmp;
1074 anywhere = 1; 1098 }
1075 } 1099 }
1076
1077 /* Find the highest visible face around. If equal
1078 * visibilities, we still want the one nearer to the
1079 * top
1080 */
1081 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere))
1082 middle = tmp;
1083 }
1084
1085 if (tmp == tmp->above)
1086 {
1087 LOG (llevError, "Error in structure of map\n");
1088 exit (-1);
1089 } 1100 }
1090 1101
1091 move_slow |= tmp->move_slow; 1102 move_slow |= tmp->move_slow;
1092 move_block |= tmp->move_block; 1103 move_block |= tmp->move_block;
1093 move_on |= tmp->move_on; 1104 move_on |= tmp->move_on;
1094 move_off |= tmp->move_off; 1105 move_off |= tmp->move_off;
1095 move_allow |= tmp->move_allow; 1106 move_allow |= tmp->move_allow;
1096 1107
1097 if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; 1108 allflags |= tmp->flag;
1098 if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; 1109
1099 if (tmp->type == PLAYER) flags |= P_PLAYER; 1110 if (tmp->type == PLAYER) flags |= P_PLAYER;
1100 if (tmp->type == SAFE_GROUND) flags |= P_SAFE; 1111 if (tmp->type == SAFE_GROUND) flags |= P_SAFE;
1101 if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE;
1102 if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC;
1103 } 1112 }
1113
1114 // FLAG_SEE_ANYWHERE takes precedence
1115 if (anywhere)
1116 middle = anywhere;
1117
1118 // ORing all flags together and checking them here is much faster
1119 if (allflags [FLAG_BLOCKSVIEW]) flags |= P_BLOCKSVIEW;
1120 if (allflags [FLAG_NO_MAGIC] ) flags |= P_NO_MAGIC;
1121 if (allflags [FLAG_ALIVE] ) flags |= P_IS_ALIVE;
1122 if (allflags [FLAG_DAMNED] ) flags |= P_NO_CLERIC;
1104 1123
1105 this->light = min (light, MAX_LIGHT_RADIUS); 1124 this->light = min (light, MAX_LIGHT_RADIUS);
1106 this->flags_ = flags; 1125 this->flags_ = flags;
1107 this->move_block = move_block & ~move_allow; 1126 this->move_block = move_block & ~move_allow;
1108 this->move_on = move_on; 1127 this->move_on = move_on;
1109 this->move_off = move_off; 1128 this->move_off = move_off;
1110 this->move_slow = move_slow; 1129 this->move_slow = move_slow;
1130 this->volume_ = (volume + 1023) / 1024;
1131 this->items_ = upos_min (items, 65535); // assume nrof <= 2**31
1111 1132
1112 /* At this point, we have a floor face (if there is a floor), 1133 /* At this point, we have a floor face (if there is a floor),
1113 * and the floor is set - we are not going to touch it at 1134 * and the floor is set - we are not going to touch it at
1114 * this point. 1135 * this point.
1115 * middle contains the highest visibility face. 1136 * middle contains the highest visibility face.
1181 faces_obj [1] = middle; 1202 faces_obj [1] = middle;
1182 faces_obj [2] = floor; 1203 faces_obj [2] = floor;
1183#endif 1204#endif
1184} 1205}
1185 1206
1186uint64
1187mapspace::volume () const
1188{
1189 uint64 vol = 0;
1190
1191 for (object *op = top; op && !op->flag [FLAG_NO_PICK]; op = op->below)
1192 vol += op->volume ();
1193
1194 return vol;
1195}
1196
1197maptile * 1207maptile *
1198maptile::tile_available (int dir, bool load) 1208maptile::tile_available (int dir, bool load)
1199{ 1209{
1200 if (tile_path[dir]) 1210 if (tile_path[dir])
1201 { 1211 {
1586 if (pick && pick->is_head ()) 1596 if (pick && pick->is_head ())
1587 return pick->head_ (); 1597 return pick->head_ ();
1588 } 1598 }
1589 1599
1590 // instead of crashing in the unlikely(?) case, try to return *something* 1600 // instead of crashing in the unlikely(?) case, try to return *something*
1591 return archetype::find ("bug"); 1601 return archetype::find (shstr_bug);
1592} 1602}
1593 1603
1594//-GPL 1604//-GPL
1595 1605
1596void 1606void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines