viewing paste Unknown #7537 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
int instance_create(int owner_id, const char *name, enum instance_owner_type type) {
    struct map_session_data *sd = NULL;
    unsigned short *icptr = NULL;
    struct party_data *p = NULL;
    struct guild *g = NULL;
    short *iptr = NULL;
    int i, j;
    
    switch ( type ) {
        case IOT_NONE:
            break;
        case IOT_CHAR:
            if( ( sd = iMap->id2sd(owner_id) ) == NULL ) {
                ShowError("instance_create: character %d not found for instance '%s'.\n", owner_id, name);
                return -2;
            }
            iptr = sd->instance;
            icptr = &sd->instances;
            break;
        case IOT_PARTY:
            if( ( p = party->search(owner_id) ) == NULL ) {
                ShowError("instance_create: party %d not found for instance '%s'.\n", owner_id, name);
                return -2;
            }
            iptr = p->instance;
            icptr = &p->instances;
            break;
        case IOT_GUILD:
            if( ( g = guild->search(owner_id) ) == NULL ) {
                ShowError("instance_create: guild %d not found for instance '%s'.\n", owner_id, name);
                return -2;
            }
            iptr = g->instance;
            icptr = &g->instances;
            break;
        default:
            ShowError("instance_create: unknown type %d for owner_id %d and name %s.\n", type,owner_id,name);
            return -1;
    }
    
    if( type != IOT_NONE && *icptr ) {
        ARR_FIND(0, *icptr, i, strcmp(instances[iptr[i]].name,name) == 0 );
        if( i != *icptr )
            return -4;/* already got this instance */
    }
        
    ARR_FIND(0, instance->instances, i, instances[i].state == INSTANCE_FREE);
        
    if( i == instance->instances )
        RECREATE(instances, struct instance_data, ++instance->instances);
 
    instances[i].state = INSTANCE_IDLE;
    instances[i].id = i;
    instances[i].idle_timer = INVALID_TIMER;
    instances[i].idle_timeout = instances[i].idle_timeoutval = 0;
    instances[i].progress_timer = INVALID_TIMER;
    instances[i].progress_timeout = 0;
    instances[i].users = 0;
    instances[i].map = NULL;
    instances[i].num_map = 0;
    instances[i].owner_id = owner_id;
    instances[i].owner_type = type;
    instances[i].vars = idb_alloc(DB_OPT_RELEASE_DATA);
 
    safestrncpy( instances[i].name, name, sizeof(instances[i].name) );
    
    if( type != IOT_NONE ) {
        ARR_FIND(0, *icptr, j, iptr[j] == -1);
        if( j == *icptr ) {
            switch( type ) {
                case IOT_CHAR:
                    RECREATE(sd->instance, short, ++*icptr);
                    sd->instance[sd->instances-1] = i;
                    break;
                case IOT_PARTY:
                    RECREATE(p->instance, short, ++*icptr);
                    p->instance[p->instances-1] = i;
                    break;
                case IOT_GUILD:
                    RECREATE(g->instance, short, ++*icptr);
                    g->instance[g->instances-1] = i;
                    break;
            }
        } else
            iptr[j] = i;
    }
    
    clif->instance(i, 1, 0); // Start instancing window
    return i;
}
 
Viewed 662 times, submitted by Guest.