/* remove an object from an object */ void obj_from_obj(struct obj_data *obj) { struct obj_data *tmp, *obj_from; char buf[100]; if (obj->carried_by) { sprintf(buf, "%s carried by %s in obj_from_obj\n", obj->name, obj->carried_by->player.name); logE(buf); } if (obj->equipped_by) { sprintf(buf, "%s equipped by %s in obj_from_obj\n", obj->name, obj->equipped_by->player.name); logE(buf); } if (obj->in_room != NOWHERE) { sprintf(buf, "%s in room %d in obj_from_obj\n", obj->name, obj->in_room); logE(buf); } assert(!obj->carried_by && !obj->equipped_by && obj->in_room == NOWHERE); if (obj->in_obj) { obj_from = obj->in_obj; if (obj == obj_from->contains) /* head of list */ obj_from->contains = obj->next_content; else { for (tmp = obj_from->contains; tmp && (tmp->next_content != obj); tmp = tmp->next_content); /* locate previous */ if (!tmp) { perror("Fatal error in object structures."); assert(0); } tmp->next_content = obj->next_content; } /* Subtract weight from containers container */ for(tmp = obj->in_obj; tmp->in_obj; tmp = tmp->in_obj) GET_OBJ_WEIGHT(tmp) -= GET_OBJ_WEIGHT(obj); GET_OBJ_WEIGHT(tmp) -= GET_OBJ_WEIGHT(obj); /* Subtract weight from char that carries the object */ if (tmp->carried_by) IS_CARRYING_W(tmp->carried_by) -= GET_OBJ_WEIGHT(obj); obj->in_obj = 0; obj->next_content = 0; } else { perror("Trying to object from object when in no object."); assert(0); } if(obj_from->in_room != NOWHERE) if(IS_SET(real_roomp(obj_from->in_room)->room_flags, SAVE_ROOM)) save_room(obj_from->in_room); }
int seek_step_line(char *line, t_map *map) { if (map->step == 0) { if (is_nbr_ant(line)) save_nbr_ant(ft_atoi(line), map); else return (0); } else if (map->step == 1) { if (is_room(line)) save_room(line, map); else return (0); } else if (map->step == 2) { if (is_link(line)) save_link(line, map); else return (0); } return (1); }
void save_rooms (int fd) { short i; /* First, write the number of rooms */ bwrite(fd, (void *) &nroom, sizeof(nroom)); for(i=0; i<nroom; i++) save_room(fd, &rooms[i]); }
/* * save_rooms : Save all the rooms on disk! */ void save_rooms(struct memfile *mf, struct level *lev) { short i; mfmagic_set(mf, ROOMS_MAGIC); /* "RDAT" */ mtag(mf, ledger_no(&lev->z), MTAG_ROOMS); /* First, write the number of rooms */ mwrite32(mf, lev->nroom); for (i = 0; i < lev->nroom; i++) save_room(mf, &lev->rooms[i]); }
static void save_room (int fd, struct mkroom *r) { short i; /* * Well, I really should write only useful information instead * of writing the whole structure. That is I should not write * the subrooms pointers, but who cares ? */ bwrite(fd, (void *) r, sizeof(struct mkroom)); for(i=0; i<r->nsubrooms; i++) save_room(fd, r->sbrooms[i]); }
/* put an object in an object (quaint) */ void obj_to_obj(struct obj_data *obj, struct obj_data *obj_to) { struct obj_data *tmp_obj; obj->next_content = obj_to->contains; obj_to->contains = obj; obj->in_obj = obj_to; /* (jdb) hopefully this will fix the object problem */ obj->carried_by = 0; obj->equipped_by = 0; for(tmp_obj = obj->in_obj; tmp_obj; GET_OBJ_WEIGHT(tmp_obj) += GET_OBJ_WEIGHT(obj), tmp_obj = tmp_obj->in_obj); if(obj_to->in_room != NOWHERE) if(IS_SET(real_roomp(obj_to->in_room)->room_flags, SAVE_ROOM)) save_room(obj_to->in_room); }
/* * save_room : A recursive function that saves a room and its subrooms * (if any). */ static void save_room(struct memfile *mf, struct mkroom *r) { short i; /* no tag; we tag room saving once per level, because the rooms don't change in number once the level is created */ mwrite8(mf, r->lx); mwrite8(mf, r->hx); mwrite8(mf, r->ly); mwrite8(mf, r->hy); mwrite8(mf, r->rtype); mwrite8(mf, r->rlit); mwrite8(mf, r->doorct); mwrite8(mf, r->fdoor); mwrite8(mf, r->nsubrooms); mwrite8(mf, r->irregular); for (i = 0; i < r->nsubrooms; i++) save_room(mf, r->sbrooms[i]); }
/* put an object in a room */ void obj_to_room(struct obj_data *object, int room) { if (room == -1) room = 4; assert(!object->equipped_by && object->eq_pos == -1); if (object->in_room > NOWHERE) { obj_from_room(object); } object->next_content = real_roomp(room)->contents; real_roomp(room)->contents = object; object->in_room = room; object->carried_by = 0; object->equipped_by = 0; /* should be unnecessary */ if(IS_SET(real_roomp(room)->room_flags, SAVE_ROOM)) save_room(room); }
/* Take an object from a room */ void obj_from_room(struct obj_data *object) { struct obj_data *i; /* remove object from room */ if (object->in_room <= NOWHERE) { if (object->carried_by || object->equipped_by) { logE("Eek.. an object was just taken from a char, instead of a room"); assert(0); } return; /* its not in a room */ } if (object == real_roomp(object->in_room)->contents) /* head of list */ real_roomp(object->in_room)->contents = object->next_content; else /* locate previous element in list */ { for (i = real_roomp(object->in_room)->contents; i && (i->next_content != object); i = i->next_content); if (i) { i->next_content = object->next_content; } else { logE("Couldn't find object in room"); assert(0); } } if(IS_SET(real_roomp(object->in_room)->room_flags, SAVE_ROOM)) save_room(object->in_room); object->in_room = NOWHERE; object->next_content = 0; }
int trs_main(void) { const int value = u.c[UC_VALUE]; int tmp, typ = TRS_NORM; int trs; double adj; if (debug_mode()) printf("trs: l = %d\r\n", value); tmp = roll(1, 100); if (tmp > 80 && tmp <= 90) typ = TRS_CHEST; else if (tmp > 90) typ = TRS_OBJ; switch (typ) { case TRS_CHEST: if ((trs = trs_chest()) == YEP) return(YEP); if (trs == MAYBE) break; /* fall through */ case TRS_OBJ: if (trs_obj() == YEP) return(YEP); break; case TRS_NORM: if (tmp <= 30) { printf("You see a pile of silver...\r\n"); trs = 100 * rnd() * value + 10; } else if (tmp <= 40) { printf("You see a pile of gold...\r\n"); trs = 500 * rnd() * value + 50; } else if (tmp <= 60) { printf("You see a pile of platinum...\r\n"); trs = 1000 * rnd() * value + 100; } else if (tmp <= 72) { printf("You see some gems...\r\n"); trs = 500.0 * sqrt((double)rnd()) * value + 150.0; } else { printf("You see a jewel...\r\n"); trs = 6000.0 * rnd() * rnd() * rnd() * value + 500; } trs_top: utl_dtrp(); printf("Press <CR> to pick it up, <LF> to leave it behind: "); tmp = getchar(); printf("\r\n"); if (tmp < 0) tmp = '\n'; if (tmp == '\n') { u.c[UC_STATE] = XXX_NORM; break; } if (tmp != '\r') { printf("DUMMY!\007\r\n"); goto trs_top; } if (u.i[ROOM_TREASURE_BOOBYTRAPPED] == 1) if (cbt_ohitu((int) (u.c[UC_DGNLVL] / 1.2)) == YEP) return(YEP); printf("The treasure is worth %d gold.\r\n", trs); u.c[UC_GOLDFOUND] += trs; u.c[UC_STATE] = XXX_NORM; adj = u.c[UC_DGNLVL] / (double) u.c[UC_LEVEL]; if (adj > 1.0) adj = 1.0; u.c[UC_EXPGAIN] += trs * adj; break; default: printf("trs: internal error\r\n"); unix_exit(1); } u.i[ROOM_MONSTER] = u.i[ROOM_TREASURE] = u.i[ROOM_TREASURE_BOOBYTRAPPED] = 0; save_room(false); if (u.i[ROOM_SPECIAL] == 0) { u.c[UC_STATE] = DGN_PROMPT; return(NOPE); } utl_pplot(NOPE); return(spc_main()); }