/* * Find an obj in a list. */ obj_data *get_obj_list( char_data * ch, const string & argument, list < obj_data * >source ) { string arg; list < obj_data * >::iterator iobj; int number = number_argument( argument, arg ); int count = 0; for( iobj = source.begin( ); iobj != source.end( ); ++iobj ) { obj_data *obj = *iobj; if( ch->can_see_obj( obj, false ) && hasname( obj->name, arg ) ) if( ( count += obj->count ) >= number ) return obj; } /* * If we didn't find an exact match, run through the list of objects * again looking for prefix matching, ie swo == sword. * Added by Narn, Sept/96 */ count = 0; for( iobj = source.begin( ); iobj != source.end( ); ++iobj ) { obj_data *obj = *iobj; if( ch->can_see_obj( obj, false ) && nifty_is_name_prefix( arg, obj->name ) ) if( ( count += obj->count ) >= number ) return obj; } return NULL; }
Character *get_char_world(Character *ch, const char *argument) { char arg[BUF_SIZ]; long number; Character *wch; int count; if ((wch = get_char_room(ch, argument)) != NULL) { return wch; } number = number_argument(argument, arg); count = 0; for (wch = first_character; wch != NULL; wch = wch->next) { if (wch->inRoom == NULL || !can_see(ch, wch) || !is_name(arg, wch->name)) { continue; } if (++count == number) { return wch; } } return NULL; }
RESET_DATA *find_oreset( ROOM_INDEX_DATA *room, const char *oname ) { RESET_DATA *pReset; OBJ_INDEX_DATA *pobj; char arg[MAX_INPUT_LENGTH]; int cnt = 0, num = number_argument( oname, arg ); for( pReset = room->first_reset; pReset; pReset = pReset->next ) { // Only going to allow traps/hides on room reset objects. Unless someone can come up with a better way to do this. if( pReset->command != 'O' ) continue; if( !( pobj = get_obj_index( pReset->arg1 ) ) ) continue; if( is_name( arg, pobj->name ) && ++cnt == num ) return pReset; } return NULL; }
obj_index *GetObjInRoomByName(room_data *room, CString &arg) { int count, i; obj_index *obj; if(room) { count = number_argument(arg); for(i = 1, obj = room->contents; obj; obj = obj->next, i++) { if(i < count) continue; if(obj->obj) { if(obj->obj->name.Find(arg) > -1) return obj; } } } return NULL; }
mob_index *GetMobInRoomByName(room_data *room, CString &arg) { int count, i; mob_index *mob; if(room) { count = number_argument(arg); for(i = 1, mob = room->people; mob; mob = mob->next, i++) { if(i < count) continue; if(mob->mob) { if(mob->mob->name.Find(arg) > -1) return mob; } } } return NULL; }