Debian Codegraph @

prboom2/src/dsda/analysis.c

raw
1 //
2 // Copyright(C) 2020 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Analysis
16 //
17
18 #include "doomstat.h"
19 #include "m_file.h"
20
21 #include "dsda/excmd.h"
22 #include "dsda/exdemo.h"
23 #include "dsda/settings.h"
24
25 #include "analysis.h"
26
27 int dsda_analysis;
28
29 dboolean dsda_pacifist = true;
30 dboolean dsda_reality = true;
31 dboolean dsda_almost_reality = true;
32 dboolean dsda_reborn = false;
33 int dsda_missed_monsters = 0;
34 int dsda_missed_secrets = 0;
35 int dsda_missed_weapons = 0;
36 dboolean dsda_tyson_weapons = true;
37 dboolean dsda_100k = true;
38 dboolean dsda_100s = true;
39 dboolean dsda_any_counted_monsters = false;
40 dboolean dsda_any_monsters = false;
41 dboolean dsda_any_secrets = false;
42 dboolean dsda_any_weapons = false;
43 dboolean dsda_stroller = true;
44 dboolean dsda_nomo = false;
45 dboolean dsda_respawn = false;
46 dboolean dsda_fast = false;
47 dboolean dsda_turbo = false;
48 dboolean dsda_weapon_collector = true;
49
50 int dsda_kills_on_map = 0;
51 dboolean dsda_100k_on_map = false;
52 dboolean dsda_100k_note_shown = false;
53 dboolean dsda_pacifist_note_shown = false;
54 dboolean dsda_reality_note_shown = false;
55 dboolean dsda_almost_reality_note_shown = false;
56
57 void dsda_ResetAnalysis(void) {
58 dsda_pacifist = true;
59 dsda_reality = true;
60 dsda_almost_reality = true;
61 dsda_reborn = false;
62 dsda_missed_monsters = 0;
63 dsda_missed_secrets = 0;
64 dsda_missed_weapons = 0;
65 dsda_tyson_weapons = true;
66 dsda_100k = true;
67 dsda_100s = true;
68 dsda_any_counted_monsters = false;
69 dsda_any_monsters = false;
70 dsda_any_secrets = false;
71 dsda_any_weapons = false;
72 dsda_stroller = true;
73 dsda_turbo = false;
74 dsda_weapon_collector = true;
75 }
76
77 void dsda_WriteAnalysis(void) {
78 FILE *fstream = NULL;
79 const char* category = NULL;
80 int is_signed;
81
82 if (!dsda_analysis) return;
83
84 fstream = M_OpenFile("analysis.txt", "w");
85
86 if (fstream == NULL) {
87 fprintf(stderr, "Unable to open analysis.txt for writing!\n");
88 return;
89 }
90
91 category = dsda_DetectCategory();
92 is_signed = dsda_IsExDemoSigned();
93
94 fprintf(fstream, "skill %d\n", gameskill + 1);
95 fprintf(fstream, "nomonsters %d\n", dsda_nomo);
96 fprintf(fstream, "respawn %d\n", dsda_respawn);
97 fprintf(fstream, "fast %d\n", dsda_fast);
98 fprintf(fstream, "pacifist %d\n", dsda_pacifist);
99 fprintf(fstream, "stroller %d\n", dsda_stroller);
100 fprintf(fstream, "reality %d\n", dsda_reality);
101 fprintf(fstream, "almost_reality %d\n", dsda_almost_reality);
102 fprintf(fstream, "reborn %d\n", dsda_reborn);
103 fprintf(fstream, "100k %d\n", dsda_100k);
104 fprintf(fstream, "100s %d\n", dsda_100s);
105 fprintf(fstream, "missed_monsters %d\n", dsda_missed_monsters);
106 fprintf(fstream, "missed_secrets %d\n", dsda_missed_secrets);
107 fprintf(fstream, "weapon_collector %d\n", dsda_weapon_collector);
108 fprintf(fstream, "tyson_weapons %d\n", dsda_tyson_weapons);
109 fprintf(fstream, "turbo %d\n", dsda_turbo);
110 fprintf(fstream, "solo_net %d\n", solo_net);
111 fprintf(fstream, "coop_spawns %d\n", coop_spawns);
112 fprintf(fstream, "category %s\n", category);
113 fprintf(fstream, "signature %d\n", is_signed);
114
115 fclose(fstream);
116
117 return;
118 }
119
120 #define SKILL4 3
121 #define SKILL5 4
122
123 const char* dsda_DetectCategory(void) {
124 dboolean satisfies_max;
125 dboolean satisfies_respawn;
126 dboolean satisfies_tyson;
127 dboolean satisfies_100s;
128
129 if (dsda_reality) dsda_almost_reality = false;
130 if (!dsda_pacifist) dsda_stroller = false;
131 if (!dsda_any_weapons) dsda_weapon_collector = false;
132
133 dsda_nomo = nomonsters > 0;
134 dsda_respawn = respawnparm > 0;
135 dsda_fast = fastparm > 0;
136
137 satisfies_max = (
138 dsda_missed_monsters == 0 \
139 && dsda_100s \
140 && (dsda_any_secrets || dsda_any_counted_monsters)
141 );
142 satisfies_respawn = (
143 dsda_100s \
144 && dsda_100k \
145 && dsda_any_monsters \
146 && (dsda_any_secrets || dsda_any_counted_monsters)
147 );
148 satisfies_tyson = (
149 dsda_missed_monsters == 0 \
150 && dsda_tyson_weapons \
151 && dsda_any_counted_monsters
152 );
153 satisfies_100s = dsda_any_secrets && dsda_100s;
154
155 if (dsda_ExCmdDemo()) return "Other";
156 if (dsda_turbo) return "Other";
157 if (coop_spawns) return "Other";
158 if (solo_net) return "Other";
159 if (dsda_reborn) return "Other";
160
161 if (gameskill == SKILL4) {
162 if (dsda_nomo && !dsda_respawn && !dsda_fast) {
163 if (satisfies_100s) return "NoMo 100S";
164
165 return "NoMo";
166 }
167
168 if (dsda_respawn && !dsda_nomo && !dsda_fast) {
169 if (satisfies_respawn) return "UV Respawn";
170
171 return "Other";
172 }
173
174 if (dsda_fast && !dsda_nomo && !dsda_respawn) {
175 if (satisfies_max) return "UV Fast";
176
177 return "Other";
178 }
179
180 if (dsda_nomo || dsda_respawn || dsda_fast) return "Other";
181
182 if (satisfies_max) return "UV Max";
183 if (satisfies_tyson) return "UV Tyson";
184 if (dsda_any_monsters && dsda_stroller) return "Stroller";
185 if (dsda_any_monsters && dsda_pacifist) return "Pacifist";
186
187 return "UV Speed";
188 }
189 else if (gameskill == SKILL5) {
190 if (nomonsters) return "Other";
191 if (satisfies_100s) return "NM 100S";
192
193 return "NM Speed";
194 }
195
196 return "Other";
197 }