diff --git a/rogueviz/ads/ads-lands.cpp b/rogueviz/ads/ads-lands.cpp new file mode 100644 index 00000000..10c3f81e --- /dev/null +++ b/rogueviz/ads/ads-lands.cpp @@ -0,0 +1,113 @@ +namespace hr { + +namespace ads_game { + +// Crossroads: empty + +// Caves: walls and asteroids + +// Hunting: turrets + +eLand ads_nextland(eLand old) { + vector 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; + } + } + +} +} diff --git a/rogueviz/ads/display.cpp b/rogueviz/ads/display.cpp index da54eb09..510ace76 100644 --- a/rogueviz/ads/display.cpp +++ b/rogueviz/ads/display.cpp @@ -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; diff --git a/rogueviz/ads/ds-game.cpp b/rogueviz/ads/ds-game.cpp index 60819c7b..2d153292 100644 --- a/rogueviz/ads/ds-game.cpp +++ b/rogueviz/ads/ds-game.cpp @@ -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]; diff --git a/rogueviz/ads/globals.cpp b/rogueviz/ads/globals.cpp index 85eae449..ccfbaade 100644 --- a/rogueviz/ads/globals.cpp +++ b/rogueviz/ads/globals.cpp @@ -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* shape; ld last_shot; int hlast; diff --git a/rogueviz/ads/map.cpp b/rogueviz/ads/map.cpp index da65ea7e..c207dbeb 100644 --- a/rogueviz/ads/map.cpp +++ b/rogueviz/ads/map.cpp @@ -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 (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 (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(oResource, c, from, rsrc_color[rsrc]); r->shape = rsrc_shape[rsrc]; diff --git a/rogueviz/ads/resources.cpp b/rogueviz/ads/resources.cpp index 0ea748b7..c978c47f 100644 --- a/rogueviz/ads/resources.cpp +++ b/rogueviz/ads/resources.cpp @@ -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* 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* 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 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]); }