mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-23 13:07:16 +00:00
multiple treasure types and expiries
This commit is contained in:
parent
2b297b21d0
commit
ea92d84b3e
113
rogueviz/ads/ads-lands.cpp
Normal file
113
rogueviz/ads/ads-lands.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
namespace hr {
|
||||
|
||||
namespace ads_game {
|
||||
|
||||
// Crossroads: empty
|
||||
|
||||
// Caves: walls and asteroids
|
||||
|
||||
// Hunting: turrets
|
||||
|
||||
eLand ads_nextland(eLand old) {
|
||||
vector<eLand> lands = { laCrossroads, laCaves, laHunting, laJungle };
|
||||
while(true) {
|
||||
eLand res = hrand_elt(lands);
|
||||
if(res != old) return res;
|
||||
}
|
||||
}
|
||||
|
||||
color_t empty_color(cell *c) {
|
||||
switch(c->land) {
|
||||
case laCrossroads:
|
||||
return 0x101030FF;
|
||||
case laCaves:
|
||||
return 0x303010FF;
|
||||
case laHunting:
|
||||
return 0x301010FF;
|
||||
case laJungle:
|
||||
return 0x103010FF;
|
||||
default:
|
||||
return 0x181818FF;
|
||||
}
|
||||
}
|
||||
|
||||
color_t empty_outline(cell *c) {
|
||||
switch(c->land) {
|
||||
case laCrossroads:
|
||||
return 0x8080C0FF;
|
||||
case laCaves:
|
||||
return 0xC0C080FF;
|
||||
case laHunting:
|
||||
return 0xC08080FF;
|
||||
case laJungle:
|
||||
return 0x80C080FF;
|
||||
default:
|
||||
return 0x181818FF;
|
||||
}
|
||||
}
|
||||
|
||||
int wall_frequency(cell *c) {
|
||||
switch(c->land) {
|
||||
case laCrossroads:
|
||||
return 0;
|
||||
case laCaves:
|
||||
return 6;
|
||||
case laHunting:
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ld turret_frequency(cell *c) {
|
||||
switch(c->land) {
|
||||
case laHunting:
|
||||
forCellEx(c1, c) forCellEx(c2, c) if(c2->land != laHunting) return 0;
|
||||
return 0.02;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ld rock_frequency(cell *c) {
|
||||
switch(c->land) {
|
||||
case laCaves:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int gate_frequency(cell *c) {
|
||||
switch(c->land) {
|
||||
case laJungle:
|
||||
return 50;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int treasure_id(eResourceType r) {
|
||||
switch(r) {
|
||||
case rtGoldRocks: return 0;
|
||||
case rtGoldGate: return 1;
|
||||
case rtGoldTurret: return 2;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
eResourceType treasure_of(cell *c) {
|
||||
switch(c->land) {
|
||||
case laCaves:
|
||||
return rtGoldRocks;
|
||||
case laHunting:
|
||||
return rtGoldTurret;
|
||||
case laJungle:
|
||||
return rtGoldGate;
|
||||
default:
|
||||
return rtNone;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -110,8 +110,8 @@ void draw_game_cell(const cell_to_draw& cd) {
|
||||
auto& rock = *ci.rocks[i];
|
||||
|
||||
if(!paused) {
|
||||
if(rock.type == oRock && rock.expire < pdata.score) { rock.resource = rtNone; rock.col = rock_color[rtNone]; rock.expire = 999999; }
|
||||
if(rock.type == oResource && rock.expire < pdata.score) { rock.resource = rtNone; rock.col = rsrc_color[rtNone]; rock.shape = rsrc_shape[rtNone]; rock.expire = 999999; }
|
||||
if(rock.type == oRock && expired(rock.expire, pdata)) { rock.resource = rtNone; rock.col = rock_color[rtNone]; rock.expire.score = 999999; }
|
||||
if(rock.type == oResource && expired(rock.expire, pdata)) { rock.resource = rtNone; rock.col = rsrc_color[rtNone]; rock.shape = rsrc_shape[rtNone]; rock.expire.score = 999999; }
|
||||
}
|
||||
|
||||
ld ang = 0;
|
||||
|
@ -198,8 +198,7 @@ struct rock_generator {
|
||||
ld alpha = rand_range(0, TAU);
|
||||
cshift += rand_range(0.5, 1) * (1 + cshift / 10);
|
||||
auto r = add(spin(alpha) * cspin(0, 2, step) * spin90() * lorentz(0, 3, rapidity));
|
||||
eResourceType rt = eResourceType(2 + rand() % 4);
|
||||
if(rt == rtGold) rt = rtHull;
|
||||
eResourceType rt = eResourceType(1 + rand() % 4);
|
||||
r->type = oResource;
|
||||
r->resource = rt;
|
||||
r->shape = rsrc_shape[rt];
|
||||
|
@ -75,12 +75,14 @@ color_t missile_color = 0xFF0000FF;
|
||||
|
||||
bool game_over;
|
||||
|
||||
constexpr int score_types = 3;
|
||||
|
||||
struct player_data {
|
||||
int hitpoints;
|
||||
int score;
|
||||
int ammo;
|
||||
ld fuel;
|
||||
ld oxygen;
|
||||
int score[score_types];
|
||||
};
|
||||
|
||||
ld ads_how_much_invincibility = TAU / 4;
|
||||
@ -154,7 +156,7 @@ color_t ghost_color = 0x800080FF;
|
||||
/* types */
|
||||
|
||||
enum eObjType { oRock, oMissile, oParticle, oResource, oMainRock, oTurret, oTurretMissile };
|
||||
enum eResourceType { rtNone, rtHull, rtGold, rtAmmo, rtFuel, rtOxygen };
|
||||
enum eResourceType { rtNone, rtHull, rtAmmo, rtFuel, rtOxygen, rtGoldRocks, rtGoldGate, rtGoldTurret, rtGUARD };
|
||||
enum eWalltype { wtNone, wtDestructible, wtSolid, wtGate, wtBarrier };
|
||||
|
||||
PPR obj_prio[7] = { PPR::MONSTER_BODY, PPR::ITEMa, PPR::ITEM_BELOW, PPR::ITEM, PPR::MONSTER_HEAD, PPR::MONSTER_BODY, PPR::ITEMa };
|
||||
@ -176,13 +178,18 @@ struct turret_state {
|
||||
ld err;
|
||||
};
|
||||
|
||||
struct expiry_data {
|
||||
int score;
|
||||
int score_id;
|
||||
};
|
||||
|
||||
struct ads_object {
|
||||
eObjType type;
|
||||
eResourceType resource;
|
||||
cell *owner;
|
||||
ads_matrix at;
|
||||
color_t col;
|
||||
int expire;
|
||||
expiry_data expire;
|
||||
vector<ld>* shape;
|
||||
ld last_shot;
|
||||
int hlast;
|
||||
|
@ -103,7 +103,7 @@ void add_rock(cell *c, cellinfo& ci, const ads_matrix& T) {
|
||||
eResourceType rt = eResourceType(rand() % 6);
|
||||
auto r = std::make_unique<ads_object> (oRock, c, T, rock_color[rt]);
|
||||
r->resource = rt;
|
||||
r->expire = gen_expire();
|
||||
r->expire = gen_expire(c);
|
||||
r->shape = &(rand() % 2 ? shape_rock2 : shape_rock);
|
||||
if(geometry != gTwistedProduct) { println(hlog, "wrong geometry detected in gen_rocks 2!"); exit(1); }
|
||||
int q = 0;
|
||||
@ -134,7 +134,7 @@ void add_rock(cell *c, cellinfo& ci, const ads_matrix& T) {
|
||||
|
||||
void add_turret(cell *c, cellinfo& ci, const ads_matrix& T) {
|
||||
auto r = std::make_unique<ads_object> (oTurret, c, T, 0xC0C060FF);
|
||||
r->expire = gen_expire();
|
||||
r->expire = gen_expire(c);
|
||||
r->shape = &shape_turret;
|
||||
r->last_shot = -1;
|
||||
r->hlast = 0;
|
||||
@ -155,11 +155,13 @@ void add_turret(cell *c, cellinfo& ci, const ads_matrix& T) {
|
||||
ci.rocks.emplace_back(std::move(r));
|
||||
}
|
||||
|
||||
void gen_resource(cell *c, shiftmatrix from, eResourceType rsrc, int expire);
|
||||
void gen_resource(cell *c, shiftmatrix from, eResourceType rsrc, const expiry_data& expire);
|
||||
|
||||
void add_rsrc(cell *c, cellinfo& ci, const ads_matrix& T) {
|
||||
eResourceType rt = eResourceType(rand() % 6);
|
||||
gen_resource(c, T, rt, gen_expire());
|
||||
if(rt == rtGoldRocks && c->land == laJungle) rt = rtGoldGate;
|
||||
if(rt == rtGoldRocks && c->land == laHunting) rt = rtGoldTurret;
|
||||
gen_resource(c, T, rt, gen_expire(c));
|
||||
}
|
||||
|
||||
int turrets;
|
||||
@ -239,7 +241,7 @@ void gen_particles(int qty, cell *c, shiftmatrix from, color_t col, ld spd, ld t
|
||||
}
|
||||
}
|
||||
|
||||
void gen_resource(cell *c, shiftmatrix from, eResourceType rsrc, int expire) {
|
||||
void gen_resource(cell *c, shiftmatrix from, eResourceType rsrc, const expiry_data& expire) {
|
||||
if(!rsrc) return;
|
||||
auto r = std::make_unique<ads_object>(oResource, c, from, rsrc_color[rsrc]);
|
||||
r->shape = rsrc_shape[rsrc];
|
||||
|
@ -2,33 +2,37 @@ namespace hr {
|
||||
|
||||
namespace ads_game {
|
||||
|
||||
color_t rock_color[6] = { 0x703800FF, 0xC0A080FF, 0xC08010FF, 0xC04000FF, 0x408000FF, 0x8040A0FF, };
|
||||
color_t rsrc_color[6] = { 0x404040FF, 0x40C0C0FF, 0xFFD500FF, 0xFF0000FF, 0x00FF00FF, 0x0000FFFF };
|
||||
color_t rock_color[rtGUARD] = { 0x703800FF, 0xC0A080FF, 0xC04000FF, 0x408000FF, 0x8040A0FF, 0xC08010FF, 0xC08010FF, 0xC08010FF };
|
||||
color_t rsrc_color[rtGUARD] = { 0x404040FF, 0x40C0C0FF, 0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFD500FF, 0x00FFD5FF, 0xD500FFFF };
|
||||
|
||||
vector<ld>* rsrc_shape[6] = { &shape_particle, &shape_heart, &shape_gold, &shape_weapon, &shape_fuel, &shape_airtank };
|
||||
string rsrc_sound[6] = {"", "pickup-potion", "pickup-gold", "pickup-scroll", "pickup-speed", "seen-air" };
|
||||
vector<ld>* rsrc_shape[rtGUARD] = { &shape_particle, &shape_heart, &shape_weapon, &shape_fuel, &shape_airtank, &shape_gold, &shape_gold, &shape_gold };
|
||||
string rsrc_sound[rtGUARD] = {"", "pickup-potion", "pickup-scroll", "pickup-speed", "seen-air", "pickup-gold", "pickup-gold", "pickup-gold" };
|
||||
|
||||
void rsrc_config() {
|
||||
ads_max_pdata.hitpoints = 3;
|
||||
ads_max_pdata.score = 0;
|
||||
for(int i=0; i<score_types; i++)
|
||||
ads_max_pdata.score[i] = 0;
|
||||
ads_max_pdata.ammo = 50;
|
||||
ads_max_pdata.fuel = 12 * TAU;
|
||||
ads_max_pdata.oxygen = 20 * TAU;
|
||||
|
||||
for(int i=0; i<score_types; i++)
|
||||
ads_tank_pdata.score[i] = 1;
|
||||
ads_tank_pdata.hitpoints = 1;
|
||||
ads_tank_pdata.score = 1;
|
||||
ads_tank_pdata.ammo = 20;
|
||||
ads_tank_pdata.fuel = 4 * TAU;
|
||||
ads_tank_pdata.oxygen = 5 * TAU;
|
||||
|
||||
ds_max_pdata.hitpoints = 5;
|
||||
ds_max_pdata.score = 0;
|
||||
for(int i=0; i<score_types; i++)
|
||||
ds_max_pdata.score[i] = 0;
|
||||
ds_max_pdata.ammo = 10;
|
||||
ds_max_pdata.fuel = 12 * TAU;
|
||||
ds_max_pdata.oxygen = 20 * TAU;
|
||||
|
||||
ds_tank_pdata.hitpoints = 1;
|
||||
ds_tank_pdata.score = 1;
|
||||
for(int i=0; i<score_types; i++)
|
||||
ds_tank_pdata.score[i] = 1;
|
||||
ds_tank_pdata.ammo = 2;
|
||||
ds_tank_pdata.fuel = 8 * TAU;
|
||||
ds_tank_pdata.oxygen = 15 * TAU;
|
||||
@ -142,10 +146,12 @@ bool display_rsrc() {
|
||||
|
||||
#define D(id, y, field, unit) display(id, y, pdata.field, DS_(max_pdata).field, DS_(tank_pdata).field, unit)
|
||||
D(1, 1, hitpoints, 1);
|
||||
D(3, 2, ammo, 1);
|
||||
D(4, 3, fuel, TAU);
|
||||
D(5, 4, oxygen, TAU);
|
||||
D(2, 5, score, 10);
|
||||
D(2, 2, ammo, 1);
|
||||
D(3, 3, fuel, TAU);
|
||||
D(4, 4, oxygen, TAU);
|
||||
D(5, 5, score[0], 10);
|
||||
D(6, 6, score[1], 10);
|
||||
D(7, 7, score[2], 10);
|
||||
#undef D
|
||||
|
||||
int next_y = 6;
|
||||
@ -167,16 +173,21 @@ bool display_rsrc() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int treasure_id(eResourceType r);
|
||||
eResourceType treasure_of(cell *c);
|
||||
|
||||
void gain_resource(eResourceType rsrc) {
|
||||
auto& tank_pdata = DS_(tank_pdata);
|
||||
auto& max_pdata = DS_(max_pdata);
|
||||
#define D(id, field) if(rsrc == id) { pdata.field += tank_pdata.field; if(max_pdata.field && pdata.field > max_pdata.field) pdata.field = max_pdata.field; }
|
||||
println(hlog, "gain resource ", int(rsrc));
|
||||
D(1, hitpoints)
|
||||
D(2, score)
|
||||
D(3, ammo)
|
||||
D(4, fuel)
|
||||
D(5, oxygen)
|
||||
D(rtHull, hitpoints)
|
||||
D(rtAmmo, ammo)
|
||||
D(rtFuel, fuel)
|
||||
D(rtOxygen, oxygen)
|
||||
for(auto r: {rtGoldGate, rtGoldRocks, rtGoldTurret}) {
|
||||
D(r, score[treasure_id(r)])
|
||||
}
|
||||
playSound(nullptr, rsrc_sound[rsrc]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user