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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.289 by root, Sun Oct 11 05:31:54 2009 UTC vs.
Revision 1.309 by root, Sun Nov 29 17:41:07 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009 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,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,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 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * 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>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
36static const uint64 UUID_GAP = 1<<19; 37static const uint64 UUID_GAP = 1<<19;
37uint32_t mapspace::smellcount = 10000; 38uint32_t mapspace::smellcount = 10000;
38 39
39objectvec objects; 40objectvec objects;
40activevec actives; 41activevec actives;
42
43//+GPL
41 44
42short freearr_x[SIZEOFFREE] = { 45short freearr_x[SIZEOFFREE] = {
43 0, 46 0,
44 0, 1, 1, 1, 0, -1, -1, -1, 47 0, 1, 1, 1, 0, -1, -1, -1,
45 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 48 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1,
49 0, 52 0,
50 -1, -1, 0, 1, 1, 1, 0, -1, 53 -1, -1, 0, 1, 1, 1, 0, -1,
51 -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, 54 -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2,
52 -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 55 -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3
53}; 56};
54int maxfree[SIZEOFFREE] = {
55 0,
56 9, 10, 13, 14, 17, 18, 21, 22,
57 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, 48,
58 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49
59};
60int freedir[SIZEOFFREE] = { 57int freedir[SIZEOFFREE] = {
61 0, 58 0,
62 1, 2, 3, 4, 5, 6, 7, 8, 59 1, 2, 3, 4, 5, 6, 7, 8,
63 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, 60 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8,
64 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 61 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8
65}; 62};
66 63
64static int maxfree[SIZEOFFREE] = {
65 0,
66 9, 10, 13, 14, 17, 18, 21, 22,
67 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, 48,
68 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49
69};
70
67static void 71static void
68write_uuid (uval64 skip, bool sync) 72write_uuid (uval64 skip, bool sync)
69{ 73{
70 CALL_BEGIN (2); 74 CALL_BEGIN (2);
71 CALL_ARG_SV (newSVval64 (skip)); 75 CALL_ARG_SV (newSVval64 (skip));
73 CALL_CALL ("cf::write_uuid", G_DISCARD); 77 CALL_CALL ("cf::write_uuid", G_DISCARD);
74 CALL_END; 78 CALL_END;
75} 79}
76 80
77static void 81static void
78read_uuid (void) 82read_uuid ()
79{ 83{
80 char filename[MAX_BUF]; 84 char filename[MAX_BUF];
81 85
82 sprintf (filename, "%s/uuid", settings.localdir); 86 sprintf (filename, "%s/uuid", settings.localdir);
83 87
97 101
98 LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); 102 LOG (llevError, "FATAL: cannot open %s for reading!\n", filename);
99 _exit (1); 103 _exit (1);
100 } 104 }
101 105
102 UUID::BUF buf; 106 char buf [UUID::MAX_LEN];
103 buf[0] = 0; 107 buf[0] = 0;
104 fgets (buf, sizeof (buf), fp); 108 fgets (buf, sizeof (buf), fp);
105 109
106 if (!UUID::cur.parse (buf)) 110 if (!UUID::cur.parse (buf))
107 { 111 {
134 138
135void 139void
136UUID::init () 140UUID::init ()
137{ 141{
138 read_uuid (); 142 read_uuid ();
143}
144
145bool
146UUID::parse (const char *s)
147{
148 if (*s++ != '<' || *s++ != '1' || *s++ != '.')
149 return false;
150
151 seq = 0;
152
153 while (*s != '>')
154 {
155 if (*s < '0')
156 return false;
157
158 // this gives nice branchless code with gcc
159 assert ('0' < 'a' && '0' == 48 && 'a' == 97);
160 int digit = (*s + (*s & 0x40 ? 9 : 0)) & 15;
161
162 seq = (seq << 4) | digit;
163
164 ++s;
165 }
166
167 return true;
168}
169
170char *
171UUID::append (char *buf) const
172{
173 *buf++ = '<';
174 *buf++ = '1';
175 *buf++ = '.';
176
177 uint64_t seq = this->seq;
178 const int bits = 64;
179 char nz = 0;
180 static const char tohex [] = "0123456789abcdef";
181
182 // assert (len >= 3 + bits / 4 + 1 + 1);
183 for (int i = bits / 4; --i; )
184 {
185 uint8_t digit = seq >> (bits - 4);
186
187 *buf = tohex [digit];
188 nz |= digit;
189 buf += nz ? 1 : 0;
190 seq <<= 4;
191 }
192
193 // last digit is special - always emit
194 uint8_t digit = seq >> (bits - 4);
195 *buf++ = tohex [digit];
196
197 *buf++ = '>';
198
199 return buf;
200}
201
202char *
203UUID::c_str () const
204{
205 static char buf [MAX_LEN];
206 *append (buf) = 0;
207 return buf;
139} 208}
140 209
141/* Returns TRUE if every key_values in wants has a partner with the same value in has. */ 210/* Returns TRUE if every key_values in wants has a partner with the same value in has. */
142static bool 211static bool
143compare_ob_value_lists_one (const object *wants, const object *has) 212compare_ob_value_lists_one (const object *wants, const object *has)
182bool object::can_merge_slow (object *ob1, object *ob2) 251bool object::can_merge_slow (object *ob1, object *ob2)
183{ 252{
184 /* A couple quicksanity checks */ 253 /* A couple quicksanity checks */
185 if (ob1 == ob2 254 if (ob1 == ob2
186 || ob1->type != ob2->type 255 || ob1->type != ob2->type
187 || ob1->speed != ob2->speed 256 || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED
188 || ob1->value != ob2->value 257 || ob1->value != ob2->value
189 || ob1->name != ob2->name) 258 || ob1->name != ob2->name)
190 return 0; 259 return 0;
191 260
192 /* Do not merge objects if nrof would overflow, assume nrof 261 /* Do not merge objects if nrof would overflow, assume nrof
217 || ob1->skill != ob2->skill 286 || ob1->skill != ob2->skill
218 || ob1->value != ob2->value 287 || ob1->value != ob2->value
219 || ob1->animation_id != ob2->animation_id 288 || ob1->animation_id != ob2->animation_id
220 || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependent on each other 289 || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependent on each other
221 || ob1->client_type != ob2->client_type 290 || ob1->client_type != ob2->client_type
222 || ob1->materialname != ob2->materialname 291 || ob1->material != ob2->material
223 || ob1->lore != ob2->lore 292 || ob1->lore != ob2->lore
224 || ob1->subtype != ob2->subtype 293 || ob1->subtype != ob2->subtype
225 || ob1->move_type != ob2->move_type 294 || ob1->move_type != ob2->move_type
226 || ob1->move_block != ob2->move_block 295 || ob1->move_block != ob2->move_block
227 || ob1->move_allow != ob2->move_allow 296 || ob1->move_allow != ob2->move_allow
228 || ob1->move_on != ob2->move_on 297 || ob1->move_on != ob2->move_on
229 || ob1->move_off != ob2->move_off 298 || ob1->move_off != ob2->move_off
230 || ob1->move_slow != ob2->move_slow 299 || ob1->move_slow != ob2->move_slow
231 || ob1->move_slow_penalty != ob2->move_slow_penalty 300 || fabs (ob1->move_slow_penalty - ob2->move_slow_penalty) >= (1.f / 1024.f)
232 || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) 301 || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist))
233 || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats))) 302 || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats)))
234 return 0; 303 return 0;
235 304
236 if ((ob1->flag ^ ob2->flag) 305 if ((ob1->flag ^ ob2->flag)
334 403
335 // the player itself is always on a map, so we will find him here 404 // the player itself is always on a map, so we will find him here
336 // even if our inv is in a player. 405 // even if our inv is in a player.
337 if (envest->is_on_map ()) 406 if (envest->is_on_map ())
338 if (object *pl = envest->ms ().player ()) 407 if (object *pl = envest->ms ().player ())
339 if (pl->container == env) 408 if (pl->container_ () == env)
340 return pl; 409 return pl;
341 } 410 }
342 else 411 else
343 { 412 {
344 // maybe there is a player standing on the same mapspace 413 // maybe there is a player standing on the same mapspace
345 // this will catch the case where "this" is a player 414 // this will catch the case where "this" is a player
346 if (object *pl = ms ().player ()) 415 if (object *pl = ms ().player ())
347 if ((!pl->container && pl->contr->ns && !pl->contr->ns->update_look) 416 if ((pl->contr->ns && !pl->container_ () && !pl->contr->ns->update_look)
348 || this == pl->container) 417 || pl->container_ () == this)
349 return pl; 418 return pl;
350 } 419 }
351 } 420 }
352 421
353 return 0; 422 return 0;
435 504
436char * 505char *
437object::as_string () 506object::as_string ()
438{ 507{
439 return dump_object (this); 508 return dump_object (this);
440}
441
442/*
443 * get_nearest_part(multi-object, object 2) returns the part of the
444 * multi-object 1 which is closest to the second object.
445 * If it's not a multi-object, it is returned.
446 */
447object *
448get_nearest_part (object *op, const object *pl)
449{
450 object *tmp, *closest;
451 int last_dist, i;
452
453 if (!op->more)
454 return op;
455
456 for (last_dist = distance (op, pl), closest = op, tmp = op->more;
457 tmp;
458 tmp = tmp->more)
459 if ((i = distance (tmp, pl)) < last_dist)
460 closest = tmp, last_dist = i;
461
462 return closest;
463} 509}
464 510
465/* 511/*
466 * Returns the object which has the count-variable equal to the argument. 512 * Returns the object which has the count-variable equal to the argument.
467 * VERRRY slow. 513 * VERRRY slow.
641 tail = new_link; 687 tail = new_link;
642 } 688 }
643 } 689 }
644 } 690 }
645 691
646 if (speed < 0)
647 dst->speed_left -= rndm ();
648
649 dst->activate (); 692 dst->activate ();
650} 693}
651 694
652void 695void
653object::instantiate () 696object::instantiate ()
654{ 697{
655 if (!uuid.seq) // HACK 698 if (!uuid.seq) // HACK
656 uuid = UUID::gen (); 699 uuid = UUID::gen ();
657 700
701 // TODO: unclean state changes, should nt be done in copy_to AND instantiate
702 if (flag [FLAG_RANDOM_SPEED] && speed)
703 speed_left = - speed - rndm (); // TODO animation
704 else
658 speed_left = -0.1f; 705 speed_left = -1.;
706
659 /* copy the body_info to the body_used - this is only really 707 /* copy the body_info to the body_used - this is only really
660 * need for monsters, but doesn't hurt to do it for everything. 708 * need for monsters, but doesn't hurt to do it for everything.
661 * by doing so, when a monster is created, it has good starting 709 * by doing so, when a monster is created, it has good starting
662 * values for the body_used info, so when items are created 710 * values for the body_used info, so when items are created
663 * for it, they can be properly equipped. 711 * for it, they can be properly equipped.
671object * 719object *
672object::clone () 720object::clone ()
673{ 721{
674 object *neu = create (); 722 object *neu = create ();
675 copy_to (neu); 723 copy_to (neu);
724
725 // TODO: unclean state changes, should not be done in clone AND instantiate
726 if (neu->flag [FLAG_RANDOM_SPEED] && neu->speed)
727 neu->speed_left = - neu->speed - rndm (); // TODO animation
728
676 neu->map = map; // not copied by copy_to 729 neu->map = map; // not copied by copy_to
677 return neu; 730 return neu;
678} 731}
679 732
680/* 733/*
698 * This function needs to be called whenever the speed of an object changes. 751 * This function needs to be called whenever the speed of an object changes.
699 */ 752 */
700void 753void
701object::set_speed (float speed) 754object::set_speed (float speed)
702{ 755{
703 if (flag [FLAG_FREED] && speed)
704 {
705 LOG (llevError, "Object %s is freed but has speed.\n", &name);
706 speed = 0;
707 }
708
709 this->speed = speed; 756 this->speed = speed;
710 757
711 if (has_active_speed ()) 758 if (has_active_speed ())
712 activate (); 759 activate ();
713 else 760 else
763 810
764 if (!(m.flags_ & P_UPTODATE)) 811 if (!(m.flags_ & P_UPTODATE))
765 /* nop */; 812 /* nop */;
766 else if (action == UP_OBJ_INSERT) 813 else if (action == UP_OBJ_INSERT)
767 { 814 {
815#if 0
768 // this is likely overkill, TODO: revisit (schmorp) 816 // this is likely overkill, TODO: revisit (schmorp)
769 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) 817 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW))
770 || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC)) 818 || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC))
771 || (op->is_player () && !(m.flags_ & P_PLAYER)) 819 || (op->is_player () && !(m.flags_ & P_PLAYER))
772 || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE)) 820 || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE))
777 || (m.move_slow | op->move_slow) != m.move_slow 825 || (m.move_slow | op->move_slow) != m.move_slow
778 /* This isn't perfect, but I don't expect a lot of objects to 826 /* This isn't perfect, but I don't expect a lot of objects to
779 * have move_allow right now. 827 * have move_allow right now.
780 */ 828 */
781 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block 829 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block
782 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp)
783 m.invalidate (); 830 m.invalidate ();
831#else
832 // the above is not strong enough a test to skip updating. los maybe? TODO (schmorp)
833 m.invalidate ();
834#endif
784 } 835 }
785 /* if the object is being removed, we can't make intelligent 836 /* if the object is being removed, we can't make intelligent
786 * decisions, because remove_ob can't really pass the object 837 * decisions, because remove_ob can't really pass the object
787 * that is being removed. 838 * that is being removed.
788 */ 839 */
800object::object () 851object::object ()
801{ 852{
802 SET_FLAG (this, FLAG_REMOVED); 853 SET_FLAG (this, FLAG_REMOVED);
803 854
804 //expmul = 1.0; declared const for the time being 855 //expmul = 1.0; declared const for the time being
805 face = blank_face; 856 face = blank_face;
857 material = MATERIAL_NULL;
806} 858}
807 859
808object::~object () 860object::~object ()
809{ 861{
810 unlink (); 862 unlink ();
1040 * the previous environment. 1092 * the previous environment.
1041 */ 1093 */
1042void 1094void
1043object::do_remove () 1095object::do_remove ()
1044{ 1096{
1045 object *tmp, *last = 0;
1046 object *otmp;
1047
1048 if (flag [FLAG_REMOVED]) 1097 if (flag [FLAG_REMOVED])
1049 return; 1098 return;
1050 1099
1051 INVOKE_OBJECT (REMOVE, this); 1100 INVOKE_OBJECT (REMOVE, this);
1052 1101
1084 1133
1085 above = 0; 1134 above = 0;
1086 below = 0; 1135 below = 0;
1087 env = 0; 1136 env = 0;
1088 1137
1089 /* NO_FIX_PLAYER is set when a great many changes are being 1138 if (pl && pl->is_player ())
1090 * made to players inventory. If set, avoiding the call
1091 * to save cpu time.
1092 */
1093 if (pl)
1094 if (pl->is_player () && (glow_radius || !QUERY_FLAG (pl, FLAG_NO_FIX_PLAYER)))
1095 { 1139 {
1096 pl->update_stats (); 1140 pl->contr->queue_stats_update ();
1097 1141
1098 if (glow_radius && pl->is_on_map ()) 1142 if (glow_radius && pl->is_on_map ())
1099 update_all_los (pl->map, pl->x, pl->y); 1143 update_all_los (pl->map, pl->x, pl->y);
1100 } 1144 }
1101 } 1145 }
1102 else if (map) 1146 else if (map)
1103 { 1147 {
1104 map->dirty = true; 1148 map->dirty = true;
1105 mapspace &ms = this->ms (); 1149 mapspace &ms = this->ms ();
1118 close_container (); 1162 close_container ();
1119 1163
1120 --map->players; 1164 --map->players;
1121 map->touch (); 1165 map->touch ();
1122 } 1166 }
1123 else if (pl->container == this) 1167 else if (pl->container_ () == this)
1124 { 1168 {
1125 // removing a container should close it 1169 // removing a container should close it
1126 close_container (); 1170 close_container ();
1127 } 1171 }
1128 1172
1144 1188
1145 int check_walk_off = !flag [FLAG_NO_APPLY]; 1189 int check_walk_off = !flag [FLAG_NO_APPLY];
1146 1190
1147 if (object *pl = ms.player ()) 1191 if (object *pl = ms.player ())
1148 { 1192 {
1149 if (pl->container == this) 1193 if (pl->container_ () == this)
1150 /* If a container that the player is currently using somehow gets 1194 /* If a container that the player is currently using somehow gets
1151 * removed (most likely destroyed), update the player view 1195 * removed (most likely destroyed), update the player view
1152 * appropriately. 1196 * appropriately.
1153 */ 1197 */
1154 pl->close_container (); 1198 pl->close_container ();
1158 //TODO: update floorbox to preserve ordering 1202 //TODO: update floorbox to preserve ordering
1159 if (pl->contr->ns) 1203 if (pl->contr->ns)
1160 pl->contr->ns->floorbox_update (); 1204 pl->contr->ns->floorbox_update ();
1161 } 1205 }
1162 1206
1207 if (check_walk_off)
1163 for (tmp = ms.bot; tmp; tmp = tmp->above) 1208 for (object *above, *tmp = ms.bot; tmp; tmp = above)
1164 { 1209 {
1210 above = tmp->above;
1211
1165 /* No point updating the players look faces if he is the object 1212 /* No point updating the players look faces if he is the object
1166 * being removed. 1213 * being removed.
1167 */ 1214 */
1168 1215
1169 /* See if object moving off should effect something */ 1216 /* See if object moving off should effect something */
1170 if (check_walk_off
1171 && ((move_type & tmp->move_off) 1217 if ((move_type & tmp->move_off)
1172 && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) 1218 && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)
1173 {
1174 move_apply (tmp, this, 0); 1219 move_apply (tmp, this, 0);
1175
1176 if (destroyed ())
1177 LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ());
1178 } 1220 }
1179
1180 last = tmp;
1181 }
1182 1221
1183 if (affects_los ()) 1222 if (affects_los ())
1184 update_all_los (map, x, y); 1223 update_all_los (map, x, y);
1185 } 1224 }
1186} 1225}
1230 1269
1231 object *prev = this; 1270 object *prev = this;
1232 1271
1233 for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more) 1272 for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more)
1234 { 1273 {
1235 object *op = arch_to_object (at); 1274 object *op = at->instance ();
1236 1275
1237 op->name = name; 1276 op->name = name;
1238 op->name_pl = name_pl; 1277 op->name_pl = name_pl;
1239 op->title = title; 1278 op->title = title;
1240 1279
1515 1554
1516 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) 1555 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above)
1517 if (tmp->arch->archname == archname) /* same archetype */ 1556 if (tmp->arch->archname == archname) /* same archetype */
1518 tmp->destroy (); 1557 tmp->destroy ();
1519 1558
1520 object *tmp = arch_to_object (archetype::find (archname)); 1559 object *tmp = archetype::find (archname)->instance ();
1521 1560
1522 tmp->x = op->x; 1561 tmp->x = op->x;
1523 tmp->y = op->y; 1562 tmp->y = op->y;
1524 1563
1525 insert_ob_in_map (tmp, op->map, op, 0); 1564 insert_ob_in_map (tmp, op->map, op, 0);
1530{ 1569{
1531 if (where->env) 1570 if (where->env)
1532 return where->env->insert (this); 1571 return where->env->insert (this);
1533 else 1572 else
1534 return where->map->insert (this, where->x, where->y, originator, flags); 1573 return where->map->insert (this, where->x, where->y, originator, flags);
1574}
1575
1576// check whether we can put this into the map, respect max_volume, max_items
1577bool
1578object::can_drop_at (maptile *m, int x, int y, object *originator)
1579{
1580 mapspace &ms = m->at (x, y);
1581
1582 int items = ms.items ();
1583
1584 if (!items // testing !items ensures we can drop at least one item
1585 || (items < m->max_items
1586 && ms.volume () < m->max_volume))
1587 return true;
1588
1589 if (originator && originator->is_player ())
1590 originator->contr->failmsg (format (
1591 "No matter how hard you try, you just cannot put the %s here H<Try to remove some items from the floor first.>",
1592 query_name ()
1593 ));
1594
1595 return false;
1535} 1596}
1536 1597
1537/* 1598/*
1538 * decrease(object, number) decreases a specified number from 1599 * decrease(object, number) decreases a specified number from
1539 * the amount of an object. If the amount reaches 0, the object 1600 * the amount of an object. If the amount reaches 0, the object
1679 if (op->glow_radius && is_on_map ()) 1740 if (op->glow_radius && is_on_map ())
1680 { 1741 {
1681 update_stats (); 1742 update_stats ();
1682 update_all_los (map, x, y); 1743 update_all_los (map, x, y);
1683 } 1744 }
1684 else if (is_player () && !flag [FLAG_NO_FIX_PLAYER]) 1745 else if (is_player ())
1685 // if this is a player's inventory, update stats 1746 // if this is a player's inventory, update stats
1686 update_stats (); 1747 contr->queue_stats_update ();
1687 1748
1688 INVOKE_OBJECT (INSERT, this); 1749 INVOKE_OBJECT (INSERT, this);
1689 1750
1690 return op; 1751 return op;
1691} 1752}
2178 * This basically means that if direction is 15, then it could either go 2239 * This basically means that if direction is 15, then it could either go
2179 * direction 4, 14, or 16 to get back to where we are. 2240 * direction 4, 14, or 16 to get back to where we are.
2180 * Moved from spell_util.c to object.c with the other related direction 2241 * Moved from spell_util.c to object.c with the other related direction
2181 * functions. 2242 * functions.
2182 */ 2243 */
2183const int reduction_dir[SIZEOFFREE][3] = { 2244static const int reduction_dir[SIZEOFFREE][3] = {
2184 {0, 0, 0}, /* 0 */ 2245 {0, 0, 0}, /* 0 */
2185 {0, 0, 0}, /* 1 */ 2246 {0, 0, 0}, /* 1 */
2186 {0, 0, 0}, /* 2 */ 2247 {0, 0, 0}, /* 2 */
2187 {0, 0, 0}, /* 3 */ 2248 {0, 0, 0}, /* 3 */
2188 {0, 0, 0}, /* 4 */ 2249 {0, 0, 0}, /* 4 */
2459{ 2520{
2460 return map ? map->region (x, y) 2521 return map ? map->region (x, y)
2461 : region::default_region (); 2522 : region::default_region ();
2462} 2523}
2463 2524
2464const materialtype_t *
2465object::dominant_material () const
2466{
2467 if (materialtype_t *mt = name_to_material (materialname))
2468 return mt;
2469
2470 return name_to_material (shstr_unknown);
2471}
2472
2473void 2525void
2474object::open_container (object *new_container) 2526object::open_container (object *new_container)
2475{ 2527{
2476 if (container == new_container) 2528 if (container == new_container)
2477 return; 2529 return;
2511 // TODO: this does not seem to serve any purpose anymore? 2563 // TODO: this does not seem to serve any purpose anymore?
2512#if 0 2564#if 0
2513 // insert the "Close Container" object. 2565 // insert the "Close Container" object.
2514 if (archetype *closer = new_container->other_arch) 2566 if (archetype *closer = new_container->other_arch)
2515 { 2567 {
2516 object *closer = arch_to_object (new_container->other_arch); 2568 object *closer = new_container->other_arch->instance ();
2517 closer->flag [FLAG_NO_MAP_SAVE] = 1; 2569 closer->flag [FLAG_NO_MAP_SAVE] = 1;
2518 new_container->insert (closer); 2570 new_container->insert (closer);
2519 } 2571 }
2520#endif 2572#endif
2521 2573
2547 return splay (tmp); 2599 return splay (tmp);
2548 2600
2549 return 0; 2601 return 0;
2550} 2602}
2551 2603
2604//-GPL
2605
2606void
2607object::force_set_timer (int duration)
2608{
2609 this->duration = 1;
2610 this->speed_left = -1.f;
2611
2612 this->set_speed (duration ? 1.f / duration : 0.f);
2613}
2614
2552object * 2615object *
2553object::force_add (shstr_tmp name, int duration) 2616object::force_add (shstr_tmp name, int duration)
2554{ 2617{
2555 if (object *force = force_find (name)) 2618 if (object *force = force_find (name))
2556 force->destroy (); 2619 force->destroy ();
2557 2620
2558 object *force = get_archetype (FORCE_NAME); 2621 object *force = get_archetype (FORCE_NAME);
2559 2622
2560 force->slaying = name; 2623 force->slaying = name;
2561 force->stats.food = 1; 2624 force->force_set_timer (duration);
2562 force->speed_left = -1.f;
2563
2564 force->set_speed (duration ? 1.f / duration : 0.f);
2565 force->flag [FLAG_IS_USED_UP] = true;
2566 force->flag [FLAG_APPLIED] = true; 2625 force->flag [FLAG_APPLIED] = true;
2567 2626
2568 return insert (force); 2627 return insert (force);
2569} 2628}
2570 2629
2571void 2630void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines