AMFP Enhanced
C++ reference: the code this unofficial fork added
Loading...
Searching...
No Matches
LuxGuidance.h
Go to the documentation of this file.
1/*
2 * AMFP-2026: gentle guidance, one Enhanced option with four levels (Modern = Normal):
3 * Off nothing extra (the original game)
4 * Light the objective line: the latest hint's title and first sentence (the game's own
5 * words), when a hint is new and on request (D-pad down / O)
6 * Normal + the stuck nudge: after 3 minutes without progress the objective comes back up;
7 * after 6 minutes again, now with the clue words coloured (LuxKeywords.h), and the
8 * colour stays until the player makes progress
9 * Full + clue words always coloured, nudge every 3 minutes
10 * No map, no markers, no new hint text (see PLAN.md).
11 * Pure, unit tested in tests/cpp/test_guidance.cpp.
12 */
13#ifndef LUX_GUIDANCE_H
14#define LUX_GUIDANCE_H
15
16#include <string>
17
19{
25};
26
27static const float kLuxStuckNudgeTime = 180.0f; // first nudge: seconds of play without progress
28static const float kLuxStuckColourTime = 360.0f; // second nudge, clue words coloured (Normal)
29static const float kLuxObjectiveShowTime = 8.0f; // seconds the objective line stays up
30
31/** The first sentence of a hint text, on one line, at most alMaxChars (cut at a word, "..."). */
32inline std::wstring LuxFirstSentence(const std::wstring& asText, size_t alMaxChars)
33{
34 std::wstring s;
35 for(size_t i = 0; i < asText.size(); ++i)
36 {
37 wchar_t c = asText[i];
38 if(c == L'\n' || c == L'\r' || c == L'\t') c = L' ';
39 if(c == L' ' && (s.empty() || s[s.size() - 1] == L' ')) continue;
40 s += c;
41 bool bCjkEnd = c == 0x3002 || c == 0xFF1F || c == 0xFF01; // 。?!
42 bool bLatinEnd = (c == L'.' || c == L'?' || c == L'!') &&
43 (i + 1 >= asText.size() || asText[i + 1] == L' ' || asText[i + 1] == L'\n');
44 if(bCjkEnd || bLatinEnd) break;
45 }
46 while(!s.empty() && s[s.size() - 1] == L' ') s.erase(s.size() - 1);
47 if(s.size() <= alMaxChars) return s;
48 size_t lCut = s.rfind(L' ', alMaxChars);
49 if(lCut == std::wstring::npos || lCut == 0) lCut = alMaxChars;
50 return s.substr(0, lCut) + L"...";
51}
52
53inline bool LuxGuidanceObjective(int alLevel) { return alLevel >= eLuxGuidance_Light; }
54inline bool LuxGuidanceNudges(int alLevel) { return alLevel >= eLuxGuidance_Normal; }
55inline bool LuxGuidanceKeywordsAlways(int alLevel) { return alLevel >= eLuxGuidance_Full; }
56/** Nudge times for a level: first nudge, then every alRepeat (colour layer from the repeat on). */
57inline float LuxGuidanceRepeat(int alLevel) { return alLevel >= eLuxGuidance_Full ? kLuxStuckNudgeTime : kLuxStuckColourTime; }
58
59/** Profiles saved before the level existed had two checkboxes (objective reminder, stuck nudge). */
60inline int LuxGuidanceFromChecks(bool abObjectiveReminder, bool abStuckNudge)
61{
62 if(abStuckNudge) return eLuxGuidance_Normal;
63 return abObjectiveReminder ? eLuxGuidance_Light : eLuxGuidance_Off;
64}
65
66/** Play time without progress (a new map, checkpoint, hint, note or diary page). */
68{
69public:
70 /** Nudges at afFirst, then at every multiple of afRepeat (afRepeat defaults to afFirst). */
71 explicit cLuxStuckTimer(float afFirst = kLuxStuckNudgeTime, float afRepeat = 0) { SetTimes(afFirst, afRepeat); }
72
73 void SetTimes(float afFirst, float afRepeat = 0)
74 {
75 mfFirst = afFirst;
76 mfRepeat = afRepeat > afFirst ? afRepeat : afFirst;
77 OnProgress();
78 }
79 void Update(float afTimeStep, bool abPlaying)
80 {
81 if(abPlaying == false || afTimeStep <= 0) return;
82 mfTime += afTimeStep;
83 if(mfTime >= mfNext)
84 {
85 mbDue = true;
86 if(mfNext < mfRepeat) mfNext = mfRepeat;
87 while(mfNext <= mfTime) mfNext += mfRepeat;
88 }
89 }
90 void OnProgress() { mfTime = 0; mfNext = mfFirst; mbDue = false; }
91 /** True once per nudge time without progress. */
92 bool TakeNudge() { bool b = mbDue; mbDue = false; return b; }
93 /** The second layer: stuck past the repeat time (only when it is later than the first nudge). */
94 bool IsColourLayer() const { return mfRepeat > mfFirst && mfTime >= mfRepeat; }
95
96private:
97 float mfFirst;
98 float mfRepeat;
99 float mfNext;
100 float mfTime;
101 bool mbDue;
102};
103
104#endif
int LuxGuidanceFromChecks(bool abObjectiveReminder, bool abStuckNudge)
Profiles saved before the level existed had two checkboxes (objective reminder, stuck nudge).
Definition LuxGuidance.h:60
bool LuxGuidanceKeywordsAlways(int alLevel)
Definition LuxGuidance.h:55
eLuxGuidance
Definition LuxGuidance.h:19
@ eLuxGuidance_Normal
Definition LuxGuidance.h:22
@ eLuxGuidance_Full
Definition LuxGuidance.h:23
@ eLuxGuidance_Off
Definition LuxGuidance.h:20
@ eLuxGuidance_LastEnum
Definition LuxGuidance.h:24
@ eLuxGuidance_Light
Definition LuxGuidance.h:21
static const float kLuxObjectiveShowTime
Definition LuxGuidance.h:29
bool LuxGuidanceNudges(int alLevel)
Definition LuxGuidance.h:54
static const float kLuxStuckNudgeTime
Definition LuxGuidance.h:27
bool LuxGuidanceObjective(int alLevel)
Definition LuxGuidance.h:53
float LuxGuidanceRepeat(int alLevel)
Nudge times for a level: first nudge, then every alRepeat (colour layer from the repeat on).
Definition LuxGuidance.h:57
std::wstring LuxFirstSentence(const std::wstring &asText, size_t alMaxChars)
The first sentence of a hint text, on one line, at most alMaxChars (cut at a word,...
Definition LuxGuidance.h:32
static const float kLuxStuckColourTime
Definition LuxGuidance.h:28
void Update(float afTimeStep, bool abPlaying)
Definition LuxGuidance.h:79
bool TakeNudge()
True once per nudge time without progress.
Definition LuxGuidance.h:92
cLuxStuckTimer(float afFirst=kLuxStuckNudgeTime, float afRepeat=0)
Nudges at afFirst, then at every multiple of afRepeat (afRepeat defaults to afFirst).
Definition LuxGuidance.h:71
void SetTimes(float afFirst, float afRepeat=0)
Definition LuxGuidance.h:73
void OnProgress()
Definition LuxGuidance.h:90
bool IsColourLayer() const
The second layer: stuck past the repeat time (only when it is later than the first nudge).
Definition LuxGuidance.h:94