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.1.1.2 by elmex, Wed Feb 22 18:01:22 2006 UTC vs.
Revision 1.9 by elmex, Sun Aug 13 17:16:00 2006 UTC

1/* 1/*
2 * static char *rcsid_object_c = 2 * static char *rcsid_object_c =
3 * "$Id: object.c,v 1.1.1.2 2006/02/22 18:01:22 elmex Exp $"; 3 * "$Id: object.c,v 1.9 2006/08/13 17:16:00 elmex dead $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
52 52
53object *objects; /* Pointer to the list of used objects */ 53object *objects; /* Pointer to the list of used objects */
54object *free_objects; /* Pointer to the list of unused objects */ 54object *free_objects; /* Pointer to the list of unused objects */
55object *active_objects; /* List of active objects that need to be processed */ 55object *active_objects; /* List of active objects that need to be processed */
56 56
57void (*object_free_callback)(object *ob);
57 58
58short freearr_x[SIZEOFFREE]= 59short freearr_x[SIZEOFFREE]=
59 {0,0,1,1,1,0,-1,-1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1, 60 {0,0,1,1,1,0,-1,-1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,
60 0,1,2,3,3,3,3,3,3,3,2,1,0,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1}; 61 0,1,2,3,3,3,3,3,3,3,2,1,0,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1};
61short freearr_y[SIZEOFFREE]= 62short freearr_y[SIZEOFFREE]=
212 * some items equipped, and we don't want those to merge. 213 * some items equipped, and we don't want those to merge.
213 */ 214 */
214 if (QUERY_FLAG(ob1, FLAG_APPLIED) || QUERY_FLAG(ob2, FLAG_APPLIED)) 215 if (QUERY_FLAG(ob1, FLAG_APPLIED) || QUERY_FLAG(ob2, FLAG_APPLIED))
215 return 0; 216 return 0;
216 217
218 switch (ob1->type) {
219 case SCROLL:
220 if (ob1->level != ob2->level) return 0;
221 break;
222
223 }
217 if (ob1->key_values != NULL || ob2->key_values != NULL) { 224 if (ob1->key_values != NULL || ob2->key_values != NULL) {
218 /* At least one of these has key_values. */ 225 /* At least one of these has key_values. */
219 if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) { 226 if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) {
220 /* One has fields, but the other one doesn't. */ 227 /* One has fields, but the other one doesn't. */
221 return 0; 228 return 0;
222 } else {
223 return compare_ob_value_lists(ob1, ob2); 229 } else if (!compare_ob_value_lists(ob1, ob2)) {
230 return 0;
224 } 231 }
225 } 232 }
226 233
227 switch (ob1->type) {
228 case SCROLL:
229 if (ob1->level != ob2->level) return 0;
230 break;
231
232 }
233 /* Everything passes, must be OK. */ 234 /* Everything passes, must be OK. */
234 return 1; 235 return 1;
235} 236}
236 237
237/* 238/*
1065void free_object(object *ob) { 1066void free_object(object *ob) {
1066 free_object2(ob, 0); 1067 free_object2(ob, 0);
1067} 1068}
1068void free_object2(object *ob, int free_inventory) { 1069void free_object2(object *ob, int free_inventory) {
1069 object *tmp,*op; 1070 object *tmp,*op;
1071
1072 if (object_free_callback)
1073 object_free_callback (ob);
1070 1074
1071 if (!QUERY_FLAG(ob,FLAG_REMOVED)) { 1075 if (!QUERY_FLAG(ob,FLAG_REMOVED)) {
1072 LOG(llevDebug,"Free object called with non removed object\n"); 1076 LOG(llevDebug,"Free object called with non removed object\n");
1073 dump_object(ob); 1077 dump_object(ob);
1074#ifdef MANY_CORES 1078#ifdef MANY_CORES
1540 CLEAR_FLAG(op,FLAG_REMOVED); 1544 CLEAR_FLAG(op,FLAG_REMOVED);
1541 1545
1542 /* Debugging information so you can see the last coordinates this object had */ 1546 /* Debugging information so you can see the last coordinates this object had */
1543 op->ox=op->x; 1547 op->ox=op->x;
1544 op->oy=op->y; 1548 op->oy=op->y;
1549
1550 /* Ideally, the caller figures this out. However, it complicates a lot
1551 * of areas of callers (eg, anything that uses find_free_spot would now
1552 * need extra work
1553 */
1554 op->map=get_map_from_coord(m, &op->x, &op->y);
1545 x = op->x; 1555 x = op->x;
1546 y = op->y; 1556 y = op->y;
1547 op->map=get_map_from_coord(m, &x, &y);
1548 1557
1549 /* this has to be done after we translate the coordinates. 1558 /* this has to be done after we translate the coordinates.
1550 */ 1559 */
1551 if(op->nrof && !(flag & INS_NO_MERGE)) { 1560 if(op->nrof && !(flag & INS_NO_MERGE)) {
1552 for(tmp=GET_MAP_OB(op->map,x,y);tmp!=NULL;tmp=tmp->above) 1561 for(tmp=GET_MAP_OB(op->map,x,y);tmp!=NULL;tmp=tmp->above)
1553 if (CAN_MERGE(op,tmp)) { 1562 if (CAN_MERGE(op,tmp)) {
1554 op->nrof+=tmp->nrof; 1563 op->nrof+=tmp->nrof;
1555 remove_ob(tmp); 1564 remove_ob(tmp);
1556 free_object(tmp); 1565 free_object(tmp);
1557 } 1566 }
1558 }
1559
1560 /* Ideally, the caller figures this out. However, it complicates a lot
1561 * of areas of callers (eg, anything that uses find_free_spot would now
1562 * need extra work
1563 */
1564 if (op->map != m) {
1565 /* coordinates should not change unless map also changes */
1566 op->x = x;
1567 op->y = y;
1568 } 1567 }
1569 1568
1570 CLEAR_FLAG(op,FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ 1569 CLEAR_FLAG(op,FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */
1571 CLEAR_FLAG(op, FLAG_INV_LOCKED); 1570 CLEAR_FLAG(op, FLAG_INV_LOCKED);
1572 if (!QUERY_FLAG(op, FLAG_ALIVE)) 1571 if (!QUERY_FLAG(op, FLAG_ALIVE))
1602 */ 1601 */
1603 1602
1604 while (top != NULL) { 1603 while (top != NULL) {
1605 if (QUERY_FLAG(top, FLAG_IS_FLOOR) || 1604 if (QUERY_FLAG(top, FLAG_IS_FLOOR) ||
1606 QUERY_FLAG(top, FLAG_OVERLAY_FLOOR)) floor = top; 1605 QUERY_FLAG(top, FLAG_OVERLAY_FLOOR)) floor = top;
1607 if (QUERY_FLAG(top, FLAG_NO_PICK) && 1606 if (QUERY_FLAG(top, FLAG_NO_PICK)
1608 (top->move_type & (MOVE_FLY_LOW |MOVE_FLY_HIGH))) { 1607 && (top->move_type & (MOVE_FLY_LOW |MOVE_FLY_HIGH))
1608 && !QUERY_FLAG(top, FLAG_IS_FLOOR))
1609 {
1609 /* We insert above top, so we want this object below this */ 1610 /* We insert above top, so we want this object below this */
1610 top=top->below; 1611 top=top->below;
1611 break; 1612 break;
1612 } 1613 }
1614
1613 last = top; 1615 last = top;
1614 top = top->above; 1616 top = top->above;
1615 } 1617 }
1616 /* Don't want top to be NULL, so set it to the last valid object */ 1618 /* Don't want top to be NULL, so set it to the last valid object */
1617 top = last; 1619 top = last;
1630 if (!(flag & INS_ON_TOP) && 1632 if (!(flag & INS_ON_TOP) &&
1631 (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_BLOCKSVIEW) && 1633 (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_BLOCKSVIEW) &&
1632 (op->face && !op->face->visibility)) { 1634 (op->face && !op->face->visibility)) {
1633 for (last=top; last != floor; last=last->below) 1635 for (last=top; last != floor; last=last->below)
1634 if (QUERY_FLAG(last, FLAG_BLOCKSVIEW)&&(last->type != EXIT)) break; 1636 if (QUERY_FLAG(last, FLAG_BLOCKSVIEW)&&(last->type != EXIT)) break;
1635 /* Check to see i we found the object that blocks view, 1637 /* Check to see if we found the object that blocks view,
1636 * and make sure we have a below pointer for it so that 1638 * and make sure we have a below pointer for it so that
1637 * we can get inserted below this one, which requires we 1639 * we can get inserted below this one, which requires we
1638 * set top to the object below us. 1640 * set top to the object below us.
1639 */ 1641 */
1640 if (last && last->below && last != floor) top=last->below; 1642 if (last && last->below && last != floor) top=last->below;
2393 * object, needs to travel toward it. 2395 * object, needs to travel toward it.
2394 */ 2396 */
2395 2397
2396int find_dir_2(int x, int y) { 2398int find_dir_2(int x, int y) {
2397 int q; 2399 int q;
2400
2398 if(!y) 2401 if(y)
2402 q=x*100/y;
2403 else if (x)
2399 q= -300*x; 2404 q= -300*x;
2400 else 2405 else
2401 q=x*100/y; 2406 return 0;
2407
2402 if(y>0) { 2408 if(y>0) {
2403 if(q < -242) 2409 if(q < -242)
2404 return 3 ; 2410 return 3 ;
2405 if (q < -41) 2411 if (q < -41)
2406 return 2 ; 2412 return 2 ;
2408 return 1 ; 2414 return 1 ;
2409 if (q < 242) 2415 if (q < 242)
2410 return 8 ; 2416 return 8 ;
2411 return 7 ; 2417 return 7 ;
2412 } 2418 }
2419
2413 if (q < -242) 2420 if (q < -242)
2414 return 7 ; 2421 return 7 ;
2415 if (q < -41) 2422 if (q < -41)
2416 return 6 ; 2423 return 6 ;
2417 if (q < 41) 2424 if (q < 41)
2418 return 5 ; 2425 return 5 ;
2419 if (q < 242) 2426 if (q < 242)
2420 return 4 ; 2427 return 4 ;
2428
2421 return 3 ; 2429 return 3 ;
2422} 2430}
2423 2431
2424/* 2432/*
2425 * absdir(int): Returns a number between 1 and 8, which represent 2433 * absdir(int): Returns a number between 1 and 8, which represent
2721 * Returns TRUE on success. 2729 * Returns TRUE on success.
2722 */ 2730 */
2723int set_ob_key_value_s(object * op, const char * canonical_key, const char * value, int add_key) { 2731int set_ob_key_value_s(object * op, const char * canonical_key, const char * value, int add_key) {
2724 key_value * field = NULL, *last=NULL; 2732 key_value * field = NULL, *last=NULL;
2725 2733
2726 LOG(llevDebug, "set_ob_value_s: '%s' '%s' %d\n", canonical_key, value, add_key);
2727
2728 for (field=op->key_values; field != NULL; field=field->next) { 2734 for (field=op->key_values; field != NULL; field=field->next) {
2729 if (field->key != canonical_key) { 2735 if (field->key != canonical_key) {
2730 last = field; 2736 last = field;
2731 continue; 2737 continue;
2732 } 2738 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines