Пример #1
0
int main(object me, string arg)
{
	int i;
	object *inv, ob;

	if( wizardp(me) && arg ) {
		ob = find_player(arg);
		if( !ob ) ob = find_living(arg);
		if( !ob ) ob = present(arg, environment(me));
	}

	if( !ob ) ob = me;

	inv = all_inventory(ob);
	if( !sizeof(inv) ) {
		write((ob==me)? "目前你身上没有任何东西。\n"
			: ob->name() + "身上没有携带任何东西。\n");
		return 1;
	}
	printf("%s身上带著下列这些东西(负重 %d%%):\n%s\n",
		(ob==me)? "你": ob->name(),
		(int)ob->query_encumbrance() * 100 / (int)ob->query_max_encumbrance(),
		implode(map_array(inv, "inventory_desc", this_object()), "\n") );

	return 1;
}
Пример #2
0
void reset(int arg) { 
  int i;
  object r;
  path_thru_maze = map_array(allocate(LENGTH_OF_MAZE), "guess_direction",
	this_object());
  for( i=1; i<=LENGTH_OF_MAZE; i++ )
    if( r = find_object("/room/maze1/maze"+i) )
      add_maze_exits(r);
}
Пример #3
0
add_property(arg1,arg2) {
  mapping map;
  int i,size;    
  if (mappingp(arg1)) {
    prop += arg1;
    map=arg1;
    arg1=m_indices(map);
    arg2=m_values(map);
    for(i=0,size = sizeof(arg1);i<size;i++) 
      map_array("/obj/daemon/propd"->give_me_links(arg1[i]),"add_property",this_object(),arg2[i]);    
    return;
  }
  if (!arg2)
    arg2 = 1;
  if (stringp(arg1)) {
    map_array("/obj/daemon/propd"->give_me_links(arg1),"add_property",this_object(),arg2);
    prop[arg1] = arg2;
    return;
  }
  if (pointerp(arg1))    
    if (pointerp(arg2))
      {
	map = mkmapping(arg1,arg2);
	prop+=map;
	arg1=m_indices(map);
	arg2=m_values(map);
	for(i=0,size = sizeof(arg1);i<size;i++) 
	  map_array("/obj/daemon/propd"->give_me_links(arg1[i]),"add_property",this_object(),arg2[i]);
      }
      else
	{
	  for(i=0,size = sizeof(arg1);i<size;i++) {
	    prop[arg1[i]] = arg2;
	    map_array("/obj/daemon/propd"->give_me_links(arg1[i]),"add_property",this_object(),arg2);
	  }
	}   
}
Пример #4
0
struct Value execute (struct Tree * ast, struct Tree_map * defined, struct Map * let_map){
    struct Value result;
    // first check for special kinds of execution
    if(ast->type == 'k' && string_matches(&ast->content.data.str, &if_const)){
        return if_block(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&let_const, &ast->content.data.str)){
        store_let_binding(ast, defined, let_map);
        result.type = 'u';
    }
    else if(ast->type == 'k' && string_matches(&each_const, &ast->content.data.str)){
        for_each(ast, defined, let_map);
        result.type = 'u';
    }
    else if(ast->type == 'k' && string_matches(&map_const, &ast->content.data.str)){
        return map_array(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&reduce_const, &ast->content.data.str)){
        return reduce_array(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&set_const, &ast->content.data.str)){
        struct Value index = execute(ast->children[0], defined, let_map);
        struct Value item = execute(ast->children[1], defined, let_map);
        struct Value array = execute(ast->children[2], defined, let_map);
        result = array_set(index, item, array);
        return result;
    }
    else if(ast->type == 'k' && string_matches(&for_const, &ast->content.data.str)){
        for_loop(ast, defined, let_map);
        result.type = 'u'; //return undefined
    }
    else if(ast->type == 'k' && string_matches(&do_const, &ast->content.data.str)){
        for(int i = 0; i < ast->size; i++){
            if(i == ast->size-1){
                result = execute(ast->children[i], defined, let_map);
            } else {
                execute(ast->children[i], defined, let_map);
            }
        }
    }
    else if(ast->type == 'k' && string_matches(&read_const, &ast->content.data.str)){
        return read_file(ast->children[0]->content.data.str);
    }
    else if(ast->type == 'k' && string_matches(&substring_const, &ast->content.data.str)){
        struct Value string = execute(ast->children[2], defined, let_map);
        struct Value start = execute(ast->children[0], defined, let_map);
        struct Value end = execute(ast->children[1], defined, let_map);
        if(string.type != 's'){
            ERROR("Non-string value passed into substring: %c.", string.type);
            result.type = 'u';
            return result;
        } else {
            return substring(start.data.ln, end.data.ln, string);
        }
    }
    else if(ast->type == 'k' && string_matches(&switch_const, &ast->content.data.str)){
        return switch_case(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&parallel_const, &ast->content.data.str)){
        parallel_execution(ast, defined, let_map);
        result.type = 'u';
    } else {
        // no special execution types found, check for more basic conditions
        int idx;
        if(!ast->size){
            // ast with no children is either a value or a variable
            if(ast->type == 'k'){
                for(int i = 0; i < let_map->size; i++){
                    if(string_matches(&let_map->members[i]->key->data.str, &ast->content.data.str)){
                        return *let_map->members[i]->val;
                    }
                }
                ERROR("Undefined variable: %s", ast->content.data.str.body);
            } else {
                return ast->content;
            }
        }
        else if(ast->type == 'k' && (idx = is_defined_func(defined, ast->content.data.str)) > -1){
            return execute_defined_func(ast, defined, let_map, idx);
        }
        else if(ast->size == 1){
            struct Value a = execute(ast->children[0], defined, let_map);
            if(ast->type == 'k'){
                if(string_matches(&ast->content.data.str, &print_const)){
                    print(a);
                    printf("\n");
                    result.type = 'u';
                }
                else if(string_matches(&ast->content.data.str, &length_const)){
                    return length(a);
                }
                else if(string_matches(&ast->content.data.str, &return_const)){
                    return execute(ast->children[0], defined, let_map);
                }
            }
        }
        else if(ast->size == 2) {
            struct Value a = execute(ast->children[0], defined, let_map);
            struct Value b = execute(ast->children[1], defined, let_map);
            result = apply_core_function(ast, a, b);
        } else {
            result = reduce_ast(ast, defined, let_map);
        }
    }

    return result;
}
Пример #5
0
mixed *
map(mixed *arr, string fun) {
    return map_array(arr, fun, this_object());
}