Skip to content

Instantly share code, notes, and snippets.

@SciresM
Created June 20, 2020 04:12
Show Gist options
  • Save SciresM/e50648f8e30136c4f99883fe1652d407 to your computer and use it in GitHub Desktop.
Save SciresM/e50648f8e30136c4f99883fe1652d407 to your computer and use it in GitHub Desktop.
#include <cstdint>
#include <cstddef>
#include <cstdbool>
using u32 = uint32_t;
u32 GetRandom(u32 range);
u32 GetCurrentHour();
bool IsFishing();
enum Weather {
Weather_None = 0,
Weather_Cloudy = 1,
Weather_Rainy = 2,
Weather_Stormy = 3,
Weather_Snowy = 4,
Weather_Blizzard = 5,
Weather_Dry = 6,
Weather_Sandstorm = 7,
Weather_Misty = 8,
};
Weather GetCurrentWeather();
enum Mark {
Mark_Lunchtime = 53,
Mark_SleepyTime = 54,
Mark_Dusk = 55,
Mark_Dawn = 56,
Mark_Cloudy = 57,
Mark_Rainy = 58,
Mark_Stormy = 59,
Mark_Snowy = 60,
Mark_Blizzard = 61,
Mark_Dry = 62,
Mark_Sandstorm = 63,
Mark_Misty = 64,
Mark_Destiny = 65,
Mark_Fishing = 66,
Mark_Curry = 67,
Mark_Uncommon = 68,
Mark_Rare = 69,
Mark_Rowdy = 70,
Mark_AbsentMinded = 71,
Mark_Jittery = 72,
Mark_Excited = 73,
Mark_Charismatic = 74,
Mark_Calmness = 75,
Mark_Intense = 76,
Mark_ZonedOut = 77,
Mark_Joyful = 78,
Mark_Angry = 79,
Mark_Smiley = 80,
Mark_Teary = 81,
Mark_Upbeat = 82,
Mark_Peeved = 83,
Mark_Intellectual = 84,
Mark_Ferocious = 85,
Mark_Crafty = 86,
Mark_Scowling = 87,
Mark_Kindly = 88,
Mark_Flustered = 89,
Mark_PumpedUp = 90,
Mark_ZeroEnergy = 91,
Mark_Prideful = 92,
Mark_Unsure = 93,
Mark_Humble = 94,
Mark_Thorny = 95,
Mark_Vigor = 96,
Mark_Slump = 97,
Mark_None = 255,
};
static constexpr const Mark PersonalityMarks[] = {
Mark_Rowdy,
Mark_AbsentMinded,
Mark_Jittery,
Mark_Excited,
Mark_Charismatic,
Mark_Calmness,
Mark_Intense,
Mark_ZonedOut,
Mark_Joyful,
Mark_Angry,
Mark_Smiley,
Mark_Teary,
Mark_Upbeat,
Mark_Peeved,
Mark_Intellectual,
Mark_Ferocious,
Mark_Crafty,
Mark_Scowling,
Mark_Kindly,
Mark_Flustered,
Mark_PumpedUp,
Mark_ZeroEnergy,
Mark_Prideful,
Mark_Unsure,
Mark_Humble,
Mark_Thorny,
Mark_Vigor,
Mark_Slump,
};
static constexpr const size_t NumPersonalityMarks = sizeof(PersonalityMarks) / sizeof(PersonalityMarks[0]);
Mark ChooseRandomMark() {
/* Roll to decide what kind of mark to give. */
u32 random_rare_mark = GetRandom(1000);
u32 random_personality_mark = GetRandom(100);
u32 random_uncommon_mark = GetRandom(50);
u32 random_weather_mark = GetRandom(50);
u32 random_time_mark = GetRandom(50);
u32 random_fish_mark = GetRandom(25);
/* Rare mark is a 1/1000 chance. */
if (random_rare_mark == 0) {
return Mark_Rare;
}
/* If we should give a personality mark (1/100 chance), give a random one. */
if (random_personality_mark == 0) {
return PersonalityMarks[GetRandom(NumPersonalityMarks)];
}
/* Uncommon mark is a 1/50 chance. */
if (random_uncommon_mark == 0) {
return Mark_Uncommon;
}
/* Weather-specific mark is a 1/50 chance. */
if (random_weather_mark == 0) {
switch (GetCurrentWeather()) {
/* If there is active weather, give the appropriate mark. */
case Weather_Cloudy: return Mark_Cloudy;
case Weather_Rainy: return Mark_Rainy;
case Weather_Stormy: return Mark_Stormy;
case Weather_Snowy: return Mark_Snowy;
case Weather_Blizzard: return Mark_Blizzard;
case Weather_Dry: return Mark_Dry;
case Weather_Sandstorm: return Mark_Sandstorm;
case Weather_Misty: return Mark_Misty;
/* Otherwise, continue trying other marks. */
case Weather_None:
default:
break;
}
}
/* Time-specific mark is a 1/50 chance. */
if (random_time_mark == 0) {
switch (GetCurrentHour()) {
/* Give sleepy-time mark from 8 PM to 5:59 AM. */
case 20:
case 21:
case 22:
case 23:
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
return Mark_SleepyTime;
/* Give dawn mark from 6 AM - 11:59 AM. */
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
return Mark_Dawn;
/* Give lunchtime mark from 12 PM - 6:59 PM. */
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
return Mark_Lunchtime;
/* Give dusk mark from 7 PM - 7:59 PM. */
case 19:
return Mark_Dusk;
}
}
/* Give fishing mark 1/25 of the time when fishing. */
if (random_fish_mark == 0 && IsFishing()) {
return Mark_Fishing;
}
/* Give no mark. */
return Mark_None;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment