Skip to content

Commit 836ccd2

Browse files
committed
add rarity filter
1 parent 16c7207 commit 836ccd2

3 files changed

Lines changed: 50 additions & 12 deletions

File tree

TODO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
bugs
22
----
3-
rarity
4-
shooting over a bridge blew it up
53

64
todo
75
----

src/levels_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ void levels_test(Gamep g)
3636
/* line */ (const char *) "xxxxxxxxxxx",
3737
/* line */ (const char *) "xxxxxxxxxxx",
3838
/* line */ (const char *) "xx.......xx",
39-
/* line */ (const char *) "xx...k...xx",
40-
/* line */ (const char *) "xx...$$$.xx",
41-
/* line */ (const char *) "xx.@.$$$.xx",
42-
/* line */ (const char *) "xx...$$$.xx",
43-
/* line */ (const char *) "xx.......xx",
44-
/* line */ (const char *) "xx.......xx",
39+
/* line */ (const char *) "xx...$$$$xx",
40+
/* line */ (const char *) "xx...$$$$xx",
41+
/* line */ (const char *) "xx.@.$$$$xx",
42+
/* line */ (const char *) "xx...$$$$xx",
43+
/* line */ (const char *) "xx...$$$$xx",
44+
/* line */ (const char *) "xx...$$$$xx",
4545
/* line */ (const char *) "xxxxxxxxxxx",
4646
/* line */ (const char *) "xxxxxxxxxxx",
4747
/* end */ nullptr);

src/tp.cpp

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,48 @@ auto tp_first_tile(Tpp tp, ThingAnimType val) -> Tilep
373373
return tp->tiles[ val ][ 0 ];
374374
}
375375

376+
static auto tp_random_select_with_rarity(Gamep g, Levelsp v, Levelp l, TpVec &m) -> Tpp
377+
{
378+
TRACE();
379+
380+
int tries = 100;
381+
while (tries-- > 0) {
382+
auto index = PCG_RAND() % m.size();
383+
auto *tp = m[ index ];
384+
385+
if (tp == nullptr) [[unlikely]] {
386+
break;
387+
}
388+
389+
switch (tp_rarity_get(tp)) {
390+
case THING_RARITY_COMMON : return tp;
391+
case THING_RARITY_UNCOMMON :
392+
if (d100() < 20) {
393+
return tp;
394+
}
395+
break;
396+
case THING_RARITY_RARE :
397+
if (d100() < 10) {
398+
return tp;
399+
}
400+
break;
401+
case THING_RARITY_VERY_RARE :
402+
if (d100() < 5) {
403+
return tp;
404+
}
405+
break;
406+
case THING_RARITY_UNIQUE :
407+
if (d1000() == 0) {
408+
return tp;
409+
}
410+
break;
411+
case THING_RARITY_ENUM_MAX : break;
412+
}
413+
}
414+
415+
return nullptr;
416+
}
417+
376418
static auto tp_random(Gamep g, Levelsp v, Levelp l, TpVec &m) -> Tpp
377419
{
378420
TRACE();
@@ -384,8 +426,7 @@ static auto tp_random(Gamep g, Levelsp v, Levelp l, TpVec &m) -> Tpp
384426

385427
int tries = 100;
386428
while (tries-- > 0) {
387-
auto index = PCG_RAND() % m.size();
388-
auto *tp = m[ index ];
429+
auto *tp = tp_random_select_with_rarity(g, v, l, m);
389430
if (tp == nullptr) [[unlikely]] {
390431
break;
391432
}
@@ -452,8 +493,7 @@ static auto tp_random(Gamep g, Levelsp v, Levelp l, TpVec &m) -> Tpp
452493
//
453494
tries = 100;
454495
while (tries-- > 0) {
455-
auto index = PCG_RAND() % m.size();
456-
auto *tp = m[ index ];
496+
auto *tp = tp_random_select_with_rarity(g, v, l, m);
457497
if (tp == nullptr) [[unlikely]] {
458498
break;
459499
}

0 commit comments

Comments
 (0)