std::shared_ptr<IObject> ObjectManager::create_object(int x, int y, float x_vel, float y_vel, ObjIndex object, Owner owner) { // TODO: Redo to use a Factory pattern. // TODO: Read all parameters from file. std::shared_ptr<IObject> new_obj; // Create formation if (object >= ObjIndex::enemystd_v_formation) create_formation(x, y, x_vel, y_vel, object); // Create single entity else { //Object* new_obj = allocate_object(object, owner); new_obj = allocate_object(object, owner); new_obj->set_x((float)x - (float)new_obj->width() / 2.0f); new_obj->set_y((float)y - (float)new_obj->height() / 2.0f + (float)world_y_pos_); new_obj->set_x_vel(x_vel); new_obj->set_y_vel(y_vel); queue.push_back(new_obj); } return new_obj; }
void create_wave2( game_state_t* GS, int tier, int amount, int nr_units, int* formation_index ) { int fsize; int fi = *formation_index; formation_t* f; if (amount < 1) return; for( fsize = MAX_FORMATION_SIZE ; fsize > 1 ; fsize-- ) { while (amount > 2*fsize*fsize) { f = &(GS->formations[fi]); f->nr_ranks = create_formation( GS, f, tier, fsize, fi, nr_units ); create_formation_enemies( GS, f, tier, fsize*fsize ); ++fi; amount -= fsize*fsize; } } // Create remaining amount as single enemies for( fsize = 1 ; amount > 0 ; amount-- ) { f = &(GS->formations[fi]); f->nr_ranks = create_formation( GS, f, tier, fsize, fi, nr_units ); create_formation_enemies( GS, f, tier, fsize*fsize ); ++fi; --amount; } *formation_index = fi; }
void advance_to_next_level( game_state_t* GS ) { int i, j, k; // Reset formations for( i = 0 ; i < MAX_FORMATIONS ; i++ ) { GS->formations[i].nr_ranks = 0; for( j = 0 ; j < MAX_FORMATION_RANKS ; j++ ) { GS->formations[i].ranks[j].occupied_by = NULL; for( k = 0 ; k < NR_FILLFROM_RANKS ; k++ ) { GS->formations[i].ranks[j].fillfrom_index[k] = -1; } } } //...! record score //...GS->shots_fired = 0; //...GS->shots_missed = 0; //...GS->best_resource = 0; ++GS->current_level; #if TEST_LEVELS int L = GS->current_level; formation_t* f = &(GS->formations[0]); f->nr_ranks = create_formation( GS, f, TIER_1, L, 0, 1 ); create_formation_enemies( GS, f, TIER_1, L*L ); #elif LEVEL_DESIGN_V2 int L = GS->current_level; int formation_index = 0; create_wave( GS, L, &formation_index ); create_wave( GS, L+1, &formation_index ); #else create_units( GS ); #endif }
void create_wave( game_state_t* GS, int level, int* formation_index ) { int fi = *formation_index; int i, n; int a1, a2, a3, a4; // Amount per tier int s1, s2, s3, s4; // Width (formation size) per tier formation_t* f; /* Amount and size per level * * Wave: 1 2 3 4 5 6 7 8 9 10 * Tier1: 1 1,1 4 4,4 9 9,9 16 16,16 25 25,25 ... * Tier2: - - 1 1,1 4 4,4 9 9,9 16 16,16 ... * Tier3: - - - - 1 1,1 4 4,4 9 9,9 ... * Tier4: - - - - - - 1 1,1 4 4,4 ... * * Levels: '--1--' '--3--' '--5--' '--7--' '--9--' ... * '--2--' '--4--' '--6--' '--8--' '--10--' * * This function is usually called several times like shown under "Waves" * above, to make up more nicely populated levels. */ // Calculate, which formations per tier to create.. const int fmax = sqrt( MAX_FORMATION_RANKS ); s1 = a1 = min( fmax, max(0, (level+1)/2) ); a1 *= a1; // ..and the.. s2 = a2 = min( fmax, max(0, (level-1)/2) ); a2 *= a2; // ..amount.. s3 = a3 = min( fmax, max(0, (level-3)/2) ); a3 *= a3; // ..of enemies s4 = a4 = min( fmax, max(0, (level-5)/2) ); a4 *= a4; // Clamp sizes s1 = a1 = min( 2, s1 ); a1 *= a1; s3 = a3 = min( 4, s3 ); a3 *= a3; s4 = a4 = min( 2, s4 ); a4 *= a4; n = !(level & 1); // Odd level numbers: n=1, .. ++n; // .. even: n=2 (*) #ifdef DISABLED_CODE s1 = a1 = 1; s2 = a2 = 0; s3 = a3 = 0; s4 = a4 = 0; n = level; #endif int fi_max = n * (s1 + s2 + s3 + s4); // Number of formatios to create for( i = 0 ; i < n ; i++ ) { if (fi < MAX_FORMATIONS) { f = &(GS->formations[fi]); f->nr_ranks = create_formation( GS, f, TIER_1, s1, fi, fi_max ); create_formation_enemies( GS, f, TIER_1, a1 ); ++fi; } } for( i = 0 ; i < n ; i++ ) { if (fi < MAX_FORMATIONS) { f = &(GS->formations[fi]); f->nr_ranks = create_formation( GS, f, TIER_2, s2, fi, fi_max ); create_formation_enemies( GS, f, TIER_2, a2 ); ++fi; } } for( i = 0 ; i < n ; i++ ) { if (fi < MAX_FORMATIONS) { f = &(GS->formations[fi]); f->nr_ranks = create_formation( GS, f, TIER_3, s3, fi, fi_max ); create_formation_enemies( GS, f, TIER_3, a3 ); ++fi; } } for( i = 0 ; i < n ; i++ ) { if (fi < MAX_FORMATIONS) { f = &(GS->formations[fi]); f->nr_ranks = create_formation( GS, f, TIER_4, s1, fi, fi_max ); create_formation_enemies( GS, f, TIER_4, a4 ); ++fi; } } *formation_index = fi; }