int main() { printf("init result:%d\n", init_bitmap(34, &bitmap_objects)); dump_bitmap(&bitmap_objects); printf("firt set result:%d\n", first_set_index(&bitmap_objects)); OBJECT_TYPE *obj = NULL; for (int i = 0; i < bitmap_objects.num_of_objs; ++i) { //for (int i = 0; i < 30; ++i) { obj = alloc_obj(&bitmap_objects); } dump_bitmap(&bitmap_objects); printf("firt set result:%d\n", first_set_index(&bitmap_objects)); obj = bitmap_objects.objects; //for (int i = 0; i < bitmap_objects.num_of_objs; ++i) { for (int i = 0; i < 30; ++i) { free_obj(&bitmap_objects, obj++); } printf("firt set result:%d\n", first_set_index(&bitmap_objects)); dump_bitmap(&bitmap_objects); printf("firt set result:%d\n", first_set_index(&bitmap_objects)); free_obj(&bitmap_objects, obj++); free_obj(&bitmap_objects, obj++); free_obj(&bitmap_objects, obj++); free_obj(&bitmap_objects, obj++); printf("firt set result:%d\n", first_set_index(&bitmap_objects)); printf("uninit result:%d\n", uninit_bitmap(&bitmap_objects)); }
void free_crt( creature *crt_ptr ) { otag *op, *tempo; etag *ep, *tempe; ctag *cp, *tempc; ttag *tp, *tempt; int i; for(i=0; i<20; i++) if(crt_ptr->ready[i]) { free_obj(crt_ptr->ready[i]); crt_ptr->ready[i] = 0; } op = crt_ptr->first_obj; while(op) { tempo = op->next_tag; free_obj(op->obj); free(op); op = tempo; } cp = crt_ptr->first_fol; while(cp) { tempc = cp->next_tag; free(cp); cp = tempc; } ep = crt_ptr->first_enm; while(ep) { tempe = ep->next_tag; free(ep); ep = tempe; } tp = crt_ptr->first_tlk; crt_ptr->first_tlk = 0; while(tp) { tempt = tp->next_tag; if(tp->key) free(tp->key); if(tp->response) free(tp->response); if(tp->action) free(tp->action); if(tp->target) free(tp->target); free(tp); tp = tempt; } /* make sure the creature is not active before we free it */ if (crt_ptr->type == MONSTER ) del_active( crt_ptr ); free(crt_ptr); }
obj_t * apply(obj_t *args, obj_t *env) { assert(IS_LIST(args)); if (IS_LIST(CAR(args)) && IS_FUNC(CAR(CAR(args)))) { return (FUNC(CAR(CAR(args))))(CDR(args), env); } else if (IS_LIST(CAR(args)) && IS_DEFUNC(CAR(CAR(args)))) { obj_t * func_args; obj_t * call_args; obj_t * body; obj_t * result; body = clone_obj(BODY(CAR(CAR(args)))); func_args = ARGS(CAR(CAR(args))); call_args = CDR(args); /* ((<DEFUNC:[args=(X)][body=(TIMES X X)]>) 3) */ while (IS_LIST(func_args) && IS_LIST(call_args)) { obj_t * func_arg = CAR(func_args); obj_t * call_arg = CAR(call_args); replace_obj(func_arg, call_arg, body); func_args = CDR(func_args); call_args = CDR(call_args); } if ((IS_LIST(func_args) && !IS_LIST(call_args)) || (!IS_LIST(func_args) && IS_LIST(call_args))) { free_obj(body); /* clean up */ fprintf(stdout, "Unexpected number of arguments\n"); return alloc_fail(); } result = eval(body, env); free_obj(body); return result; } else { return clone_obj(args); } }
/* List all objects in a house file */ void House_listrent(struct char_data * ch, room_vnum vnum) { FILE *fl; char fname[MAX_STRING_LENGTH]; char buf[MAX_STRING_LENGTH]; struct obj_file_elem object; struct obj_data *obj; if (!House_get_filename(vnum, fname)) return; if (!(fl = fopen(fname, "rb"))) { sprintf(buf, "No objects on file for house #%d.\r\n", vnum); send_to_char(buf, ch); return; } *buf = '\0'; while (!feof(fl)) { fread(&object, sizeof(struct obj_file_elem), 1, fl); if (ferror(fl)) { fclose(fl); return; } if (!feof(fl) && (obj = Obj_from_store(object)) != NULL) { sprintf(buf, "%s [%5d] (%5dau) %s\r\n", buf, GET_OBJ_VNUM(obj), GET_OBJ_RENT(obj), obj->short_description); free_obj(obj); } } send_to_char(buf, ch); fclose(fl); }
static BOOL table_grow(table_t table) { table_entry_t oldArray, newArray; size_t i, oldLength, newLength; oldLength = table->length; oldArray = table->array; newLength = table->length * 2; newArray = alloc_obj(sizeof(table_entry_s) * newLength); if (newArray == NULL) return FALSE; for (i = 0; i < newLength; ++i) { newArray[i].key = 0; newArray[i].value = NULL; newArray[i].status = TABLE_UNUSED; } table->length = newLength; table->array = newArray; for (i = 0; i < oldLength; ++i) { table_entry_t entry; assert(oldArray[i].status == TABLE_ACTIVE); /* should be full */ entry = table_find(table, oldArray[i].key, 0 /* none deleted */); assert(entry->status == TABLE_UNUSED); /* shouldn't be defined yet */ entry->key = oldArray[i].key; entry->value = oldArray[i].value; entry->status = TABLE_ACTIVE; } free_obj(oldArray, sizeof(table_entry_s) * oldLength); return TRUE; }
/* Extract an object from the world */ void extract_obj(struct obj_data * obj) { struct obj_data *temp; if (obj->worn_by != NULL) if (unequip_char(obj->worn_by, obj->worn_on) != obj) log("SYSERR: Inconsistent worn_by and worn_on pointers!!"); if (obj->in_room != NOWHERE) obj_from_room(obj); else if (obj->carried_by) obj_from_char(obj); else if (obj->in_obj) obj_from_obj(obj); /* Get rid of the contents of the object, as well. */ while (obj->contains) extract_obj(obj->contains); REMOVE_FROM_LIST(obj, object_list, next); if (GET_OBJ_RNUM(obj) >= 0) (obj_index[GET_OBJ_RNUM(obj)].number)--; if (SCRIPT(obj)) extract_script(SCRIPT(obj)); free_obj(obj); }
extern BOOL table_create(table_t *tableReturn, size_t length) { table_t table; size_t i; assert(tableReturn != NULL); table = alloc_obj(sizeof(table_s)); if (table == NULL) goto failMallocTable; table->length = length; table->count = 0; table->array = alloc_obj(sizeof(table_entry_s) * length); if (table->array == NULL) goto failMallocArray; for (i = 0; i < length; ++i) { table->array[i].key = 0; table->array[i].value = NULL; table->array[i].status = TABLE_UNUSED; } *tableReturn = table; return TRUE; failMallocArray: free_obj(table, sizeof(table_s)); failMallocTable: return FALSE; }
/* make a random new object, returning pointer */ Object* create_object(int itemlevel) { Object* newObject; int r; int ok = false; while (! ok) { newObject = ((Object*) checkmalloc(sizeof(Object))); r= random_range(135); if (r < 20) make_thing(newObject,-1); else if (r < 40) make_food(newObject,-1); else if (r < 50) make_scroll(newObject,-1); else if (r < 60) make_potion(newObject,-1); else if (r < 70) make_weapon(newObject,-1); else if (r < 80) make_armor(newObject,-1); else if (r < 90) make_shield(newObject,-1); else if (r < 100) make_stick(newObject,-1); else if (r < 110) make_boots(newObject,-1); else if (r < 120) make_cloak(newObject,-1); else if (r < 130) make_ring(newObject,-1); else make_artifact(newObject,-1); /* not ok if object is too good for level, or if unique and already made */ /* 1/100 chance of finding object if too good for level */ ok = ((newObject->uniqueness < UNIQUE_MADE) && ((newObject->level < itemlevel+random_range(3)) || (random_range(100)==23))); if (!ok) { free_obj( newObject, true ); } } if (newObject->uniqueness == UNIQUE_UNMADE) Objects[newObject->id].uniqueness=UNIQUE_MADE; return(newObject); }
static void free_obj(tmx_object *o) { if (o) { free_obj(o->next); tmx_free_func(o->name); if (o->points) tmx_free_func(*(o->points)); tmx_free_func(o->points); tmx_free_func(o); } }
static void free_tiles(tmx_tile *t) { if (t) { free_tiles(t->next); free_props(t->properties); free_image(t->image); free_obj(t->collision); tmx_free_func(t->animation); tmx_free_func(t); } }
/* Extract an object from the world */ void extract_obj(struct obj_data *obj) { struct char_data *ch, *next = NULL; struct obj_data *temp; if (obj->worn_by != NULL) if (unequip_char(obj->worn_by, obj->worn_on) != obj) log("SYSERR: Inconsistent worn_by and worn_on pointers!!"); if (IN_ROOM(obj) != NOWHERE) obj_from_room(obj); else if (obj->carried_by) obj_from_char(obj); else if (obj->in_obj) obj_from_obj(obj); if (OBJ_SAT_IN_BY(obj)){ for (ch = OBJ_SAT_IN_BY(obj); OBJ_SAT_IN_BY(obj); ch = next){ if (!NEXT_SITTING(ch)) OBJ_SAT_IN_BY(obj) = NULL; else OBJ_SAT_IN_BY(obj) = (next = NEXT_SITTING(ch)); SITTING(ch) = NULL; NEXT_SITTING(ch) = NULL; } } /* Get rid of the contents of the object, as well. */ while (obj->contains) extract_obj(obj->contains); REMOVE_FROM_LIST(obj, object_list, next); if (GET_OBJ_RNUM(obj) != NOTHING) (obj_index[GET_OBJ_RNUM(obj)].number)--; if (SCRIPT(obj)) extract_script(obj, OBJ_TRIGGER); if (obj->events != NULL) { if (obj->events->iSize > 0) { struct event * pEvent; while ((pEvent = simple_list(obj->events)) != NULL) event_cancel(pEvent); } free_list(obj->events); obj->events = NULL; } if (GET_OBJ_RNUM(obj) == NOTHING || obj->proto_script != obj_proto[GET_OBJ_RNUM(obj)].proto_script) free_proto_script(obj, OBJ_TRIGGER); free_obj(obj); }
void free_all_obj(t_obj *obj) { t_obj *tmp; obj = first_obj(obj); while (obj) { tmp = obj; obj = obj->next; free_obj(tmp); } }
static void free_layers(tmx_layer l) { if (l) { free_layers(l->next); tmx_free_func(l->name); if (l->type == L_LAYER) tmx_free_func(l->content.gids); else if (l->type == L_OBJGR) free_obj(l->content.head); free_props(l->properties); tmx_free_func(l); } }
void free_obj( object *obj_ptr ) { otag *op, *temp; op = obj_ptr->first_obj; while(op) { temp = op->next_tag; free_obj(op->obj); free(op); op = temp; } free(obj_ptr); }
void free_rom( room *rom_ptr ) { xtag *xp, *xtemp; otag *op, *otemp; ctag *cp, *ctemp; #ifdef DMALLOC dmalloc_verify (rom_ptr); #endif /* DMALLOC */ if(rom_ptr->short_desc) free(rom_ptr->short_desc); if(rom_ptr->long_desc) free(rom_ptr->long_desc); if(rom_ptr->obj_desc) free(rom_ptr->obj_desc); xp = rom_ptr->first_ext; while(xp) { xtemp = xp->next_tag; free(xp->ext); free(xp); xp = xtemp; } op = rom_ptr->first_obj; while(op) { otemp = op->next_tag; free_obj(op->obj); free(op); op = otemp; } cp = rom_ptr->first_mon; while(cp) { ctemp = cp->next_tag; free_crt(cp->crt); free(cp); cp = ctemp; } cp = rom_ptr->first_ply; while(cp) { ctemp = cp->next_tag; free(cp); cp = ctemp; } free(rom_ptr); }
void main(int argc, char **argv) { struct char_data ch; struct obj_data *o,*p; FILE *f,*g; char s[80]; int i,look,count; object_list=NULL; if (argc!=2) { fprintf(stderr,"purge <min days>\n"); exit(1); } time_frame=atoi(argv[1])*DAY; if (time_frame<30*DAY) { fprintf(stderr,"purge <min days>\n\nmin days must be>=30.\n"); exit(1); } f=fopen("players.new","r"); if (!f) { perror("players.new"); exit(1); } g=fopen("immortals","w"); if (!g) { perror("immortals"); exit(1); } count=0; while (fgets(s,80,f)) { s[strlen(s)-1]='\0'; fprintf(stderr, "%d:%s%c[K",count++,s,27); bzero(&ch,sizeof(struct char_data)); if (new_load_char(&ch,s)>0) { if (should_delete(&ch)) { printf("%-20s %4d %3d\n",s,ch.player.level, (time(0)-ch.specials.last_logon)/DAY); unlink(name_to_path(s)); } else if (ch.player.level>=2000) fprintf(g,"%-20s %4d %7d %7d\n",ch.player.name,ch.player.level, ch.build_lo, ch.build_hi); while (object_list) { struct obj_data *o; o=object_list->next; free_obj(object_list); object_list=o; } } else { printf("Couldn't load %s\n",s); unlink(name_to_path(s)); } } fclose(f); fclose(g); }
void sweep(VM *vm) { HeapObject **obj = &vm->heap; while (*obj) { if (!(*obj)->marked) { HeapObject *temp = *obj; *obj = temp->next; free_obj(temp); vm->numobjects--; } else { (*obj)->marked = 0; obj = &(*obj)->next; } } }
void gc_cleanup(void) { node_t * g = garbage; node_t * temp; while (g != NULL) { free_obj(g); temp = g; g = g->next; free(temp); } garbage = NULL; }
/* Extract an object from the world */ void extract_obj(struct obj_data *obj) { struct obj_data *temp1, *temp2; if(obj->in_room != NOWHERE) obj_from_room(obj); else if(obj->carried_by) obj_from_char(obj); else if(obj->in_obj) { temp1 = obj->in_obj; if(temp1->contains == obj) /* head of list */ temp1->contains = obj->next_content; else { for( temp2 = temp1->contains ; temp2 && (temp2->next_content != obj); temp2 = temp2->next_content ); if(temp2) { temp2->next_content = obj->next_content; } } } for( ; obj->contains; extract_obj(obj->contains)) ; /* leaves nothing ! */ if (object_list == obj ) /* head of list */ object_list = obj->next; else { for(temp1 = object_list; temp1 && (temp1->next != obj); temp1 = temp1->next) ; if(temp1) temp1->next = obj->next; } if(obj->item_number>=0) (obj_index[obj->item_number].number)--; free_obj(obj); }
void read_all_obj() { char str[256]; object *obj; long offset; FILE *fp; int num; /* open ascii source file */ fp=fopen(object_file, "r"); if ( fp == NULL ) { printf("Cannot open %s, room_file\n" ); return; } while(!feof(fp)) { offset = ftell(fp); if (EOF == fscanf(fp, "%s", str)) break; fseek(fp, offset, 0); /* 0=SEEK_SET ? */ if (strcmp(str, "#begobj") == 0) { obj = (object *)malloc(sizeof(object)); if ( obj ) { zero(obj, sizeof(object)); num = read_object(fp, obj); if (num == -1) printf("Error reading ascii object\n"); else if (save_obj_to_file(num, obj)) printf("Error saving object %d to binary file\n", num); else printf("Object #%d:%s converted to binary.\n", num, obj->name); free_obj(obj); } } } }
void write_all_obj() { HFINDFILE hff; char filename[256]; object *obj; int num; int index; FILE *fp; fp = fopen( object_file, "w"); if ( fp != NULL ) { hff = find_first_file(get_object_path(), filename, 256); if ( hff ) { do { if ( filename[0] != '.' && toupper(filename[0]) == 'O' && strlen(filename) == 3) { index = OFILESIZE * atoi(&filename[1]); for (num=0; num < OFILESIZE ; num++) { if (load_obj_from_file(index + num, &obj ) == 0 ) { write_object(fp, index+num,obj); free_obj(obj); } } } } while( find_next_file( hff, filename, 256 )); close_find_file(hff); } fclose(fp); } return; }
void spark_selfkill(obj *o) // время жизни кончилось { int i; evt *e,*de; lnk *l,*dl; obj *co; if(o->pl->tag==T_WORLD) loc_obj_unreg(o); co=o->bo; while(co!=NULL) { spark_selfkill(co); co=o->bo; } // удаляю очередь событий e=o->bevt; if(e!=NULL) e=e->next; while(e!=NULL) { de=e->next; del_evt(o,e); free_evt(o,e); e=de; } e=o->bevt; if(e!=NULL) { del_evt(o,e); free_evt(o,e); } // удаляю список ссылок на зависимые события for(i=0;i<ELST_NUM;i++) while(o->elst[i]!=NULL) { l=dl=o->elst[i]; o->elst[i]=l->next; if(dl->l==l) { if(l->e->e!=NULL) l->e->e->e=NULL; free_evt(o,l->e); evt_lnk_del(l); } else { while(dl->l!=l) dl=dl->l; dl->l=l->l; if(l->e!=NULL) { dl->e=l->e; l->e->l=dl; evt_lnk_del(l); } } } // удаляю буферы if(o->mem!=NULL) myfree(o->mem); // удаляю объект del_obj(o); free_obj(o); }
void pop_call_stack(){ obj * o = stack_pop(call_stack); free_obj(o); free_table(call_stack_top->names); call_stack_top = call_stack_top->next; }
static int free_objects(osm_obj_t *o, void * UNUSED(p)) { free_obj(o); return 0; }
extern void table_destroy(table_t table) { assert(table != NULL); free_obj(table->array, sizeof(table_entry_s) * table->length); free_obj(table, sizeof(table_s)); }
/* Extract an object from the world */ void extract_obj(struct obj_data *obj) { struct obj_data *temp1, *temp2; extern long obj_count; #if 0 if(IS_SET(obj->obj_flags.extra_flags, ITEM_FIGURINE) && obj->link) extract_char(obj->link); #endif if(obj->in_room != NOWHERE) obj_from_room(obj); else if(obj->carried_by) obj_from_char(obj); else if (obj->equipped_by) { if (obj->eq_pos > -1) { /* ** set players equipment slot to 0; that will avoid the garbage items. */ obj->equipped_by->equipment[obj->eq_pos] = 0; } else { logE("Extract on equipped item in slot -1 on:"); logE(obj->equipped_by->player.name); logE(obj->name); return; } } else if(obj->in_obj) { temp1 = obj->in_obj; if(temp1->contains == obj) /* head of list */ temp1->contains = obj->next_content; else { for( temp2 = temp1->contains ; temp2 && (temp2->next_content != obj); temp2 = temp2->next_content ); if(temp2) { temp2->next_content = obj->next_content; } } } for( ; obj->contains; extract_obj(obj->contains)); /* leaves nothing ! */ if (object_list == obj ) /* head of list */ object_list = obj->next; else { for(temp1 = object_list; temp1 && (temp1->next != obj); temp1 = temp1->next); if(temp1) { temp1->next = obj->next; } else { logE("Couldn't find object in object list."); assert(0); } } if(obj->item_number>=0) { (obj_index[obj->item_number].number)--; obj_count--; } free_obj(obj); }
static void free_objgr(tmx_object_group *o) { if (o) { free_obj(o->head); tmx_free_func(o); } }
void* load_model_begin(const char *path, uint flags) { ObjFileData *data = malloc(sizeof(ObjFileData)); GenericModelVertex *verts; if(!parse_obj(path, data)) { free(data); return NULL; } uint *indices = calloc(data->icount, sizeof(uint)); uint icount = data->icount; verts = calloc(data->icount, sizeof(GenericModelVertex)); #define BADREF(filename,aux,n) { \ log_error("OBJ file '%s': Index %d: bad %s index reference\n", filename, n, aux); \ goto fail; \ } memset(verts, 0, data->icount*sizeof(GenericModelVertex)); for(uint i = 0; i < data->icount; i++) { int xi, ni, ti; xi = data->indices[i][0]-1; if(xi < 0 || xi >= data->xcount) BADREF(path, "vertex", i); memcpy(verts[i].position, data->xs[xi], sizeof(vec3_noalign)); if(data->tcount) { ti = data->indices[i][1]-1; if(ti < 0 || ti >= data->tcount) BADREF(path, "texcoord", i); verts[i].uv.s = data->texcoords[ti][0]; verts[i].uv.t = data->texcoords[ti][1]; } if(data->ncount) { ni = data->indices[i][2]-1; if(ni < 0 || ni >= data->ncount) BADREF(path, "normal", ni); memcpy(verts[i].normal, data->normals[ni], sizeof(vec3_noalign)); } indices[i] = i; } free_obj(data); free(data); #undef BADREF ModelLoadData *ldata = malloc(sizeof(ModelLoadData)); ldata->verts = verts; ldata->indices = indices; ldata->icount = icount; return ldata; fail: free(indices); free(verts); free_obj(data); free(data); return NULL; }
// NOTE: To hit "you" with a potion p, call "potionhit(NULL, p)". no "youmonst" void potionhit(monst_t *mon, obj_t *obj) { Char *botlnam = bottlenames[rund(MAX_BOTTLES)]; Boolean uclose; // , isyou = (mon==NULL); if (!mon) { uclose = true; StrPrintF(ScratchBuffer, "The %s crashes on your head and breaks into shivers.", botlnam); message(ScratchBuffer); losehp(rnd(2), "thrown potion"); } else { uclose = (dist(mon->mx,mon->my) < 3); /* perhaps 'E' and 'a' have no head? */ StrPrintF(ScratchBuffer, "The %s crashes on %s's head and breaks into shivers.", botlnam, monnam(mon)); message(ScratchBuffer); if (rund(5) && mon->mhp > 1) mon->mhp--; } StrPrintF(ScratchBuffer, "The %s evaporates.", xname(obj)); message(ScratchBuffer); if (mon && !rund(3)) { switch(obj->otype) { case POT_RESTORE_STRENGTH: case POT_GAIN_STRENGTH: case POT_HEALING: case POT_EXTRA_HEALING: if (mon->mhp < mon->mhpmax) { mon->mhp = mon->mhpmax; StrPrintF(ScratchBuffer, "%s looks sound and hale again!", Monnam(mon)); message(ScratchBuffer); } break; case POT_SICKNESS: if (mon->mhpmax > 3) mon->mhpmax /= 2; if (mon->mhp > 2) mon->mhp /= 2; break; case POT_CONFUSION: case POT_BOOZE: mon->bitflags |= M_IS_CONFUSED; // mon->mconf = 1; break; case POT_INVISIBILITY: unpmon(mon); mon->bitflags |= M_IS_INVISIBLE; // mon->minvis = 1; pmon(mon); break; case POT_PARALYSIS: mon->bitflags |= M_IS_FROZEN; // mon->mfroz = 1; break; case POT_SPEED: mon->mspeed = MFAST; break; case POT_BLINDNESS: mon->mcansee_and_blinded |= 64 + rund(64); // "|="? "=" to turn off SEE? break; /* case POT_GAIN_LEVEL: case POT_LEVITATION: case POT_FRUIT_JUICE: case POT_MONSTER_DETECTION: case POT_OBJECT_DETECTION: break; */ default: break; } } if (uclose && rund(5)) potionbreathe(obj); free_obj(obj, NULL); }