jevsnes.git / third-party / c / patches / 0002-goal-choice-hook.patch
0002-goal-choice-hook.patch30 lines · 1.3 KB · raw
1diff --git a/third-party/c/zbanks-alttp/ap_plan.c b/third-party/c/zbanks-alttp/ap_plan.c
2index 03f78390..e1c2bca5 100644
3--- a/third-party/c/zbanks-alttp/ap_plan.c
4+++ b/third-party/c/zbanks-alttp/ap_plan.c
5@@ -9,6 +9,14 @@
6 #define GOAL_SCORE_COMPLETE         (-2)
7 static int ap_goal_score(struct ap_goal * goal, int max_cost);
8 
9+// Carried patch (jev): a host may install this to make the goal choice in
10+// ap_goal_evaluate. It is handed upstream's own pick (the lowest score),
11+// that score, and the scoring function, and returns the goal to pursue.
12+// NULL - the default - leaves upstream's choice exactly as it was.
13+// See third-party/c/patches/.
14+struct ap_goal * (*ap_goal_choose_hook)(struct ap_goal * min_goal, int min_score,
15+        int (*score)(struct ap_goal * goal, int max_score)) = NULL;
16+
17 const char * const ap_goal_type_names[] = {
18 #define X(type) [CONCAT(GOAL_, type)] = #type,
19 AP_GOAL_TYPE_LIST
20@@ -911,6 +919,10 @@ retry_new_goal:;
21             min_goal = goal;
22         }
23     }
24+    if (min_goal != NULL && ap_goal_choose_hook != NULL) {
25+        // Carried patch (jev): see ap_goal_choose_hook.
26+        min_goal = ap_goal_choose_hook(min_goal, min_score, ap_goal_score);
27+    }
28     ap_active_goal = min_goal;
29     if (min_goal == NULL) {
30         //ap_new_goals = false;