void commerce_create(Commerce *commerce, Planet *planet, unsigned level) { int randNumWeapon = rand_born(0, MAX_WEAPON_ITEM); int randNumArmor = rand_born(0, MAX_ARMOR_ITEM); int randNumEngine = rand_born(0, MAX_ENGINE_ITEM); int randNumHull = rand_born(0, MAX_HULL_ITEM); for (int i = 0; i < MAX_WEAPON_ITEM; ++i) { if (i < randNumWeapon) { Weapon w = weapon_create_rand(level); commerce_add_item(commerce, I_WEAPON, &w, i); } else commerce->weapon[i].isVisible = false; } for (int i = 0; i < MAX_ARMOR_ITEM; ++i) { if (i < randNumArmor) { Armor a = armor_create_rand(level); commerce_add_item(commerce, I_ARMOR, &a, i); } else commerce->armor[i].isVisible = false; } }
Weapon weapon_create_rand(unsigned level) { static float table_weapon[] = { 1.f, 1.2f, 1.5f, 1.8f, 1.9f, 2.3f, 3.2f }; static int table_damage[] = { 10, 2, 30, 20 }; static float table_penArmor[] = { 5.0, 3.0, 7.0, 15.0 }; static float table_castTime[] = { 1.0f, 0.1f, 3.0f, 2.0f }; Weapon w; WeaponType wt = rand_born(0, W_LAST - 1); int mark = rand_born(0, MAXMARK(level)); float offset = table_weapon[mark]; float critic = rand_float(5.f, 21.f); w.damage = (int)(table_damage[wt] * offset + rand_born(0, 4 + (offset / 1.5))); w.penArmor = table_penArmor[wt] * offset; w.criticalChance = critic + (9 * offset); w.castTime = table_castTime[wt] / (offset); w.isVisible = true; w.type = wt; w.price = rand_float(1, 10) * ((mark + 1) * 1000); strcpy(w.name, gTable_markName[mark]); return w; }
Engine engine_create_rand(unsigned level) { static int table_evasion[] = { 10, 15, 25, 40, 50, 60, 70 }; Engine e; //EngineType et = rand_born(0, A_LAST); int mark = rand_born(0, MAXMARK(level)); e.evasionChance = table_evasion[mark]; e.isVisible = true; e.speed = 0; e.type = 0; e.price = rand_float(2, 11) * ((mark + 1) * 10000);; strcpy(e.name, gTable_markName[mark]); return e; }
void drop_scrap(Player *player) { if (CHANCE(3)) { unsigned addmoney = rand_born(5, 20); printf("\t- Vous prenez %u scraps\n", addmoney); player->money += addmoney; } }
void drop_scrap(Player *player) { if (CHANCE(3)) { unsigned addmoney = rand_born(20, 60); printf("\t- Vous trouvez %u$\n", addmoney); player->money += addmoney; } }
void drop_staff(Player *player) { if (CHANCE(7)) { Staff staff = staff_create(); char c; printf("Vous trouvez un membre du vaisseau: "); staff_set_life(&staff, rand_born(10, 80)); staff_display(staff); printf("Voulez vous le recruter [o/n]?"); scanf("%c", &c); purge_stdin(); if (c == 'o') { if (CHANCE(10)) { int rep = rand_born(1, 2); int money; static const char *sentence[] = { "C'etait un piege! La personne que vous venez de recruter est une kamikaze!\nElle explose dans le vaisseau et fait de serieux degats...", "La personne vous remercies, et vous donnes %d d'argent." }; switch (rep) { case 1: puts(sentence[rep - 1]); ship_get_damage(&player->ship, rand_born(50, player->ship.hull.life.max / 2)); break; case 2: money = rand_born(100, 1000); player->money += money; printf(sentence[rep - 1], money); break; default: break; } } crew_add_staff(&player->ship.crew, staff); } } }
Armor armor_create_rand(unsigned level) { static float table_armor[] = { 10.0, 15.0, 25.0, 40.0, 50.0, 60.0, 70.0, 90.0f }; // A revoir static float table_armor_life[] = { 100.0, 400.0, 800.0, 1000.0, 1500.0, 2000.0, 3000.0, 5000.0 }; Armor a; ArmorType at = rand_born(0, A_LAST); int mark = rand_born(0, MAXMARK(level)); a.armor = table_armor[mark]; a.life = table_armor_life[mark]; a.isVisible = true; a.type = at; a.price = rand_float(1, 10) * ((mark + 1) * 1000); strcpy(a.name, gTable_markName[mark]); return a; }
Armor armor_create_rand(unsigned level) { static float table_armor[] = { 10, 15, 25, 40, 50, 60, 70, 90 }; // A revoir static float table_armor_life[] = { 100, 400, 800, 1000, 1500, 2000, 3000, 5000 }; Armor a; ArmorType at = rand_born(0, A_LAST); int mark = rand_born(0, MAXMARK(level)); a.armor = table_armor[mark]; a.life = table_armor_life[mark]; a.isVisible = true; a.type = at; strcpy(a.name, gTable_markName[mark]); return a; }
void drop_staff(Player *player) { if (CHANCE(8)) { Staff staff = staff_create(); char c; printf("Vous trouvez un membre du vaisseau: "); staff_set_life(&staff, rand_born(10, 80)); staff_display(staff); printf("Voulez vous le recruter [o/n]?"); scanf("%c", &c); if (c == 'o') { crew_add_staff(&player->crew, staff); } } }
Hull hull_create_rand(unsigned level) { Hull h; HullType ht; static const int table_life[] = { 500, 1500, 2000, 2500, 4000 }; static const int table_max_staff[] = { 4, 5, 6, 8, 10 }; static const int table_max_weapon_slot[] = { 2, 3, 4, 6, 8 }; static const int table_price[] = { 500, 1000, 1500, 2000, 5000 }; static const float table_fuel[] = { 50.f, 120.f, 200.f, 300.f, 500.f }; h.isVisible = true; if (level == 0) ht = H_SMALL; else ht = rand_born(0, H_LAST - 1); h.life.actual = table_life[ht]; h.nMaxStaff = table_max_staff[ht]; h.nWeaponsSlot = table_max_weapon_slot[ht]; h.fuel.actual = h.fuel.max = table_fuel[ht]; h.price = table_price[ht]; h.type = ht; return h; }