Ejemplo n.º 1
0
Archivo: gx.c Proyecto: LWSS/gx
void init_game(struct GameMemory *memory)
{
    ASSERT(memory->game_memory_size >= sizeof(struct GameState));
    struct GameState *game_state = (struct GameState *)memory->game_memory;

    struct Camera *camera = &game_state->camera;
    camera->zoom = 20.0f;

    game_state->ship_id_map = create_uint_hash_map();

    uint32 unit_count = 5;
    for (uint32 i = 0; i < unit_count; ++i)
    {
        struct Ship *ship = create_ship(game_state);

        ship->size = vec2_new(1, 1);
        ship->move_velocity = vec2_new(0, 0);

        float xp = 2.0f * ((float)i - unit_count/2.0f);
        float yp = -camera->zoom/4.0f;
        ship->position = vec2_new(xp, yp);

        ship->health = 5;
        ship->fire_cooldown = 2.0f;

        ship->team = TEAM_ALLY;
    }

#if 0
    for (uint32 i = 0; i < unit_count; ++i)
    {
        struct Ship *ship = create_ship(game_state);
        ship->size = vec2_new(1, 1);
        ship->move_velocity = vec2_new(0, 0);

        float xp = 2.0f * ((float)i - unit_count/2.0f);
        float yp = camera->zoom/4.0f;
        ship->position = vec2_new(xp, yp);

        ship->health = 5;
        ship->fire_cooldown = 2.0f;

        ship->team = TEAM_ENEMY;
    }
#endif

    for (uint32 i = 0; i < 4; ++i)
    {
        struct Building *building = create_building(game_state);
        building->position = vec2_new(random_int(-16, 16), random_int(-16, 16));
        building->size = vec2_new(2, 2);
    }

    calc_visibility_graph(game_state, &game_state->visibility_graph);
}
Ejemplo n.º 2
0
void NormalGame::choose_new_ships()
{
	STACKTRACE;
	char tmp[40];
	int i;
	pause();
	message.out("Selecting ships...", 1000);
	int *slot = new int[num_players];
	//choose ships and send them across network
	for (i = 0; i < num_players; i += 1) {
		slot[i] = -2;
		if (player_control[i]->ship) {
		} else {
			//			if (player_panel[i]) player_panel[i]->window->hide();
			//			player_panel[i] = NULL;
			sprintf (tmp, "Player%d", i+1);
			Fleet *fleet = player_fleet[i];
			if (fleet->getSize() == 0) continue;
			char buffy[512];

			if (strlen(fleet->getTitle()) != 0)
				sprintf(buffy, "%s\n%s\n", player_name[i], fleet->getTitle());
			else
				sprintf(buffy, "%s\n", player_name[i]);

			slot[i] = player_control[i]->choose_ship(window, buffy, fleet);
			if (player_control[i]->channel != channel_none) {
				slot[i] = intel_ordering(slot[i]);
				log->buffer(player_control[i]->channel, &slot[i], sizeof(int));
				log->flush();
				//slot[i] = intel_ordering(slot[i]);
			}
		}
	}
	//recieve the ships that were chosen
	log->listen();
	for (i = 0; i < num_players; i += 1) {
		if (slot[i] == -2) continue;
		if (player_control[i]->channel != channel_none) {
			log->unbuffer(player_control[i]->channel, &slot[i], sizeof(int));
			slot[i] = intel_ordering(slot[i]);
		}
	}
	//create the ships that were chosen
	for (i = 0; i < num_players; i += 1) {
		if (slot[i] == -2) continue;
		sprintf (tmp, "Player%d", i+1);
		//fleet->load("./fleets.tmp", tmp);
		Fleet *fleet = player_fleet[i];
		if (slot[i] == -1) slot[i] = random() % fleet->getSize();
		if (slot[i] < 0 || slot[i] >= fleet->getSize()) {tw_error("trying to load invalid ship");}
		Ship *s = create_ship(fleet->getShipType(slot[i])->id, player_control[i], random(size), random(PI2), player_team[i]);
		if (!s) {tw_error("unable to create ship");}
		fleet->clear_slot(slot[i]);
		fleet->Sort();
		//fleet->save("./fleets.tmp", tmp);
		s->locate();
		add ( new WedgeIndicator ( s, 30, i+1 ) );
		ShipPanel *panel = new ShipPanel(s);
		panel->window->init(window);
		panel->window->locate(
			0, 0.9,
			0, i * (100.0/480),
			0, 0.1,
			0, (100.0/480)
			);
		add(panel);
		add(s->get_ship_phaser());

		// add a healthbar for the ship, and also a team indicator.
		add(new HealthBar(s, &indhealthtoggle));
		add(new TeamIndicator(s, &indteamtoggle));

		// CHECK FILE SIZES !! to intercept desynch before they happen.
		int myfsize, otherfsize;

		myfsize = file_size_ex(s->type->data->file);
		otherfsize = myfsize;
		if (player_control[i]->channel != channel_none) {
			log_int(player_control[i]->channel, otherfsize);
		}

		if (otherfsize != myfsize) {
			// the player who loads the ship doesn't get this message, cause his own file is identical by default
			tw_error("DAT files have different size! This may cause a desynch. Press Retry to continue");
		}

	}
	delete[] slot;
	message.out("Finished selecting ships...", 1500);
	unpause();
	return;
}
Ejemplo n.º 3
0
void GobGame::add_new_enemy()
{
	STACKTRACE;
	struct EnemyType
	{
		const char *code;
		int starbucks;
		int buckazoids;
	};
	static EnemyType enemy_types[] = {
		{						 //0
			"thrto", 1, 0
		},
		{						 //1
			"zfpst", 1, 0
		},
		{						 //2
			"shosc", 1, 0
		},
		{						 //3
			"ilwsp", 1, 0
		},
		{						 //4
			"dragr", 1, 1
		},
		{						 //5
			"kahbo", 2, 0
		},
		{						 //6
			"ktesa", 2, 0
		},
		{						 //7
			"syrpe", 2, 0
		},
		{						 //8
			"kzedr", 2, 1
		},
		{						 //9
			"mmrxf", 2, 0
		},
		/*		{						 //10
					"lk_sa", 2, 0
				},
		*/
		{						 //11
			"druma", 2, 1
		},
		{						 //12
			"earcr", 3, 1
		},
		{						 //13
			"virli", 3, 1
		},
		{						 //14
			"yehte", 3, 2
		},
		/*		{						 //15
					"herex", 3, 2
				},
		*/
		{						 //16
			"narlu", 4, 2
		},
		{						 //17
			"vuxin", 3, 1
		},
		{						 //18
			"arisk", 3, 2
		},
		{						 //19
			"chmav", 4, 2
		},
		/*		{						 //20
					"plopl", 4, 2
				},
		*/
		{						 //21
			"alabc", 4, 3
		},
	};
	const int num_enemy_types = sizeof(enemy_types) / sizeof(enemy_types[0]);
	/*	examine_distribution( 30, 0, num_enemy_types);
		examine_distribution( 30, 1, num_enemy_types);
		examine_distribution( 30, 2, num_enemy_types);
		examine_distribution( 30, 3, num_enemy_types);
		examine_distribution( 150, 0, num_enemy_types);
		examine_distribution( 150, 2, num_enemy_types);
		examine_distribution( 150, 4, num_enemy_types);
		examine_distribution( 150, 6, num_enemy_types);
		examine_distribution( 300, 0, num_enemy_types);
		examine_distribution( 300, 3, num_enemy_types);
		examine_distribution( 300, 6, num_enemy_types);
		examine_distribution( 300, 9, num_enemy_types);
		examine_distribution( 600, 0, num_enemy_types);
		examine_distribution( 600, 4, num_enemy_types);
		examine_distribution( 600, 8, num_enemy_types);
		examine_distribution( 600, 12, num_enemy_types);
		examine_distribution( 1200, 0, num_enemy_types);
		examine_distribution( 2400, 0, num_enemy_types);
		examine_distribution( 3600, 0, num_enemy_types);
		examine_distribution( 4800, 0, num_enemy_types);
		examine_distribution( 6000, 0, num_enemy_types);//*/
	/*	const int num_enemy_types = 10;
		static char *enemy_types[num_enemy_types] = {
			"thrto", "zfpst", "shosc",
			"syrpe", "druma", "mmrxf",
			"kzedr", "earcr", "chmav",
			"yehte"
			};*/
	if (gobenemies == max_enemies) return;
	GobEnemy *ge = new GobEnemy();
	gobenemy[gobenemies] = ge;
	gobenemies += 1;
	int e = pick_enemy_type(game_time/1000, gobenemies, num_enemy_types);
	bool buff = e >= num_enemy_types;
	if (buff) e %= num_enemy_types;
	Ship *ship = create_ship(channel_server, enemy_types[e].code, "WussieBot", random(size), random(PI2), enemy_team);
	if (!strcmp(enemy_types[e].code, "shosc")) {
		if (random() & 3) {
			((ShofixtiScout*)ship)->special_drain = 999;
		}
		if (!buff) {
			((ShofixtiScout*)ship)->specialDamage /= 3;
		} else {
			((ShofixtiScout*)ship)->weaponDamage += 1;
			((ShofixtiScout*)ship)->weaponArmour += 1;
			((ShofixtiScout*)ship)->weaponRange *= 2;
		}
	}
	if (!strcmp(enemy_types[e].code, "zfpst")) {
		if (!buff) {
			((ZoqFotPikStinger*)ship)->specialDamage /= 2;
			if (random() & 1) ((ZoqFotPikStinger*)ship)->special_drain = 999;
		} else {
			((ZoqFotPikStinger*)ship)->weaponDamage += 1;
			((ZoqFotPikStinger*)ship)->weaponArmour += 1;
			((ZoqFotPikStinger*)ship)->weaponRange *= 2.5;
		}
	}
	if (!strcmp(enemy_types[e].code, "syrpe")) {
		if (!buff) ((SyreenPenetrator*)ship)->specialDamage /= 1.5;
		else {
			((SyreenPenetrator*)ship)->weaponDamage += 2;
			((SyreenPenetrator*)ship)->weaponArmour += 2;
			((SyreenPenetrator*)ship)->weaponRange *= 1.5;
			((SyreenPenetrator*)ship)->specialRange *= 1.5;
		}
	}
	if (!strcmp(enemy_types[e].code, "dragr")) {
		ship->special_rate *= 4;
	}
	if (!strcmp(enemy_types[e].code, "druma")) {
		if (buff) {
			((DruugeMauler*)ship)->weaponRange *= 1.6;
			((DruugeMauler*)ship)->weaponArmour += 3;
			((DruugeMauler*)ship)->weaponVelocity *= 1.1;
			((DruugeMauler*)ship)->recharge_rate /= 3;
		}
		else ((DruugeMauler*)ship)->recharge_rate *= 3;
	}
	if (!strcmp(enemy_types[e].code, "kzedr")) {
		if (buff) {
			if (random() & 3) {
				((KzerZaDreadnought*)ship)->weaponRange *= 2;
				((KzerZaDreadnought*)ship)->weaponVelocity *= 1.3;
				((KzerZaDreadnought*)ship)->weaponArmour += 3;
				ship->special_rate *= 3;
			} else {
				((KzerZaDreadnought*)ship)->specialVelocity *= 3;
				((KzerZaDreadnought*)ship)->specialRange *= 3;
				((KzerZaDreadnought*)ship)->specialLaserRange *= 1.25;
			}
		}
		ship->special_rate *= 3;
	}
	if (!strcmp(enemy_types[e].code, "earcr")) {
		if (buff) {
			((EarthlingCruiser*)ship)->weaponArmour += 3;
			((EarthlingCruiser*)ship)->weaponVelocity *= 1.3;
		}
	}
	if (!strcmp(enemy_types[e].code, "chmav")) {
		if (buff) {
			((ChmmrAvatar*)ship)->specialForce *= 2.2;
			((ChmmrAvatar*)ship)->specialRange *= 2.4;
			((ChmmrAvatar*)ship)->weaponRange *= 1.25;
			((ChmmrAvatar*)ship)->extraDamage *= 2;
			((ChmmrAvatar*)ship)->extraRange  *= 1.25;
			((ChmmrAvatar*)ship)->extraArmour *= 10;
		} else {
			((ChmmrAvatar*)ship)->weaponDamage += 1;
			((ChmmrAvatar*)ship)->weaponDamage /= 2;
			((ChmmrAvatar*)ship)->specialForce *= 1.8;
			((ChmmrAvatar*)ship)->specialRange *= 1.6;
		}
	}
	if (buff) {
		ship->crew_max *= 2.0;
		ship->crew *= 2.0;
		ship->crew_max += 6;
		ship->crew += 6;
		ship->speed_max  *= 1.5;
		ship->accel_rate *= 1.35;
		ship->turn_rate  *= 1.35;
		RepairSystem *rs = new RepairSystem ( ship );
		rs->rate = 0.025 * (tw_random(2.0) * tw_random(2.0) * tw_random(2.0) + 0.1);
		rs->efficiency = 0.5 + tw_random(0.5);
		rs->reset();
		game->add(rs);
	}
	ge->init(ship, enemy_types[e].starbucks * (buff ? 2 : 1), enemy_types[e].buckazoids * (buff ? 2 : 1));
	add(ship->get_ship_phaser());
	//add(ship);
	return;
}