40 static const char*
TYPENAME() {
return "AwardInfo"; }
102 static bool config_exists =
false;
107 : uid(0), name(n), create_date(0), points(0), medals(0), flight_time(0),
108 missions(0), kills(0), losses(0), campaigns(0), trained(0),
109 flight_model(0), flying_start(0), landing_model(0),
110 ai_level(1), hud_mode(0), hud_color(1),
111 ff_level(4), grid(1), gunsight(0), award(0)
122 : uid(0), create_date(0), points(0), medals(0), flight_time(0),
123 missions(0), kills(0), losses(0), campaigns(0), trained(0),
124 flight_model(0), flying_start(0), landing_model(0),
125 ai_level(1), hud_mode(0), hud_color(1),
126 ff_level(4), grid(1), gunsight(0), award(0)
176 if (n >= 0 && n < 10)
185 if (n >= 0 && n < 10 && m && *m)
214 else if (n > 0 && n <= 20)
224 if (n > 0 && n <= 20)
225 return (
trained & (1 << (n-1))) ?
true :
false;
233 if (
id > 0 &&
id < 30)
234 return (
campaigns & (1 <<
id)) ?
true :
false;
242 if (
id > 0 &&
id < 30) {
369 if (n >= 0 && n <= 4) {
378 if (n >= 0 && n <= 1) {
386 if (n >= 0 && n <= 1) {
446 if (award->
id == rank)
459 if (award->
id == rank)
472 if (award->
id == rank) {
490 if (award->
id == rank)
503 if (award->
name == name)
513 for (
int i = rank_table.
size()-1; i >= 0; i--) {
539 for (
int i = 0; i < 16; i++) {
540 int selector = 1 << (15-i);
565 if (award->
id == medal)
578 if (award->
id == medal) {
596 if (award->
id == medal)
611 for (
int i = rank_table.
size()-1; i >= 0; i--) {
624 for (
int i = 0; i < rank_table.
size(); i++) {
631 return rank_table.
size()-1;
649 int minutes = flight_time / 60;
675 int old_rank =
Rank();
690 if (old_rank != rank) {
790 static Player* current_player = 0;
795 return player_roster;
801 return current_player;
809 if (current_player && current_player != p) {
811 for (
int i = 0; i < 3; i++) {
829 for (
int i = 0; i < 3; i++) {
830 if (p->
mfd[i] >= 0) {
844 for (
int i = 0; i < player_roster.
size(); i++) {
864 player_roster.
append(newbie);
878 if (p == current_player) {
881 if (player_roster.
size())
882 current_player = player_roster.
at(0);
898 if (!current_player) {
899 if (!player_roster.
size()) {
910 if (current_player && !player_roster.
contains(current_player))
911 delete current_player;
925 return config_exists;
930 #define GET_DEF_BOOL(x) if(pdef->name()->value()==(#x))GetDefBool(player->x,pdef,filename)
931 #define GET_DEF_TEXT(x) if(pdef->name()->value()==(#x))GetDefText(player->x,pdef,filename)
932 #define GET_DEF_NUM(x) if(pdef->name()->value()==(#x))GetDefNumber(player->x,pdef,filename)
937 config_exists =
false;
944 strcpy_s(filename,
"player.cfg");
947 ::fopen_s(&f, filename,
"rb");
950 config_exists =
true;
952 ::fseek(f, 0, SEEK_END);
954 ::fseek(f, 0, SEEK_SET);
956 block =
new(__FILE__,__LINE__) BYTE[blocklen+1];
959 ::fread(block, blocklen, 1, f);
966 Parser parser(
new(__FILE__,__LINE__)
BlockReader((
const char*) block, blocklen));
970 Print(
"ERROR: could not parse '%s'.\n", filename);
975 if (!file_type || file_type->
value() !=
"PLAYER_CONFIG") {
976 Print(
"WARNING: invalid '%s' file. Using defaults\n", filename);
981 if (current_player && !player_roster.
contains(current_player))
982 delete current_player;
997 Print(
"WARNING: player structure missing in '%s'\n", filename);
1001 bool current =
false;
1022 else if (pdef->
name()->
value() == (
"chat_0"))
1025 else if (pdef->
name()->
value() == (
"chat_1"))
1028 else if (pdef->
name()->
value() == (
"chat_2"))
1031 else if (pdef->
name()->
value() == (
"chat_3"))
1034 else if (pdef->
name()->
value() == (
"chat_4"))
1037 else if (pdef->
name()->
value() == (
"chat_5"))
1040 else if (pdef->
name()->
value() == (
"chat_6"))
1043 else if (pdef->
name()->
value() == (
"chat_7"))
1046 else if (pdef->
name()->
value() == (
"chat_8"))
1049 else if (pdef->
name()->
value() == (
"chat_9"))
1052 else if (pdef->
name()->
value() == (
"mfd0"))
1055 else if (pdef->
name()->
value() == (
"mfd1"))
1058 else if (pdef->
name()->
value() == (
"mfd2"))
1061 else if (pdef->
name()->
value() == (
"current"))
1064 else if (pdef->
name()->
value() == (
"trained"))
1067 else if (pdef->
name()->
value() == (
"stats")) {
1104 player_roster.
append(player);
1113 Print(
"WARNING: unknown label '%s' in '%s'\n",
1118 Print(
"WARNING: term ignored in '%s'\n", filename);
1134 if (hud && current_player) {
1135 for (
int i = 0; i < 3; i++) {
1144 fopen_s(&f,
"player.cfg",
"w");
1146 fprintf(f,
"PLAYER_CONFIG\n\n");
1152 fprintf(f,
"player: {\n");
1153 fprintf(f,
" uid: %d,\n", p->
uid);
1160 if (stat_data.
length() > 32) {
1162 int len = stat_data.
length();
1164 for (
int n = 0; n < len; n += 32) {
1165 ZeroMemory(tmp,
sizeof(tmp));
1166 const char* p = stat_data.
data() + n;
1167 strncpy(tmp, p, 32);
1170 fprintf(f,
" stats: \"%s\"\n", tmp);
1171 else if (n < len-32)
1172 fprintf(f,
" \"%s\"\n", tmp);
1174 fprintf(f,
" \"%s\",\n", tmp);
1178 if (p == current_player)
1179 fprintf(f,
" current: true,\n");
1181 fprintf(f,
" current: false,\n");
1183 fprintf(f,
" trained: %d,\n", p->
trained);
1187 fprintf(f,
" ai_level: %d,\n", p->
ai_level);
1188 fprintf(f,
" hud_mode: %d,\n", p->
hud_mode);
1189 fprintf(f,
" hud_color: %d,\n", p->
hud_color);
1190 fprintf(f,
" ff_level: %d,\n", p->
ff_level);
1191 fprintf(f,
" grid: %d,\n", p->
grid);
1192 fprintf(f,
" gunsight: %d,\n", p->
gunsight);
1194 for (
int i = 0; i < 10; i++) {
1198 for (
int i = 0; i < 3; i++) {
1199 if (p->
mfd[i] >= 0) {
1200 fprintf(f,
" mfd%d: %d,\n", i, p->
mfd[i]);
1204 fprintf(f,
"}\n\n");
1209 config_exists =
true;
1215 static char stat_buf[280];
1216 static char code_buf[280];
1221 ZeroMemory(stat_buf, 280);
1222 ZeroMemory(code_buf, 280);
1224 sprintf_s(stat_buf,
"%-16s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
1234 11, 12, 13, 14, 15, 16,
1235 17, 18, 19, 20, 21, 22, 23, 24,
1236 25, 26, 27, 28, 29, 30, 31, 32);
1238 for (
int i = 0; i < 16; i++)
1239 for (
int j = 0; j < 16; j++)
1240 code_buf[i*16 + j] = stat_buf[j*16 + i];
1248 ZeroMemory(stat_buf, 280);
1249 ZeroMemory(code_buf, 280);
1251 if (!stats || !*stats) {
1252 Print(
"Player::DecodeStats() invalid or missing stats\n");
1259 if (plain.
length() == 64) {
1260 for (
int i = 0; i < 8; i++)
1261 for (
int j = 0; j < 8; j++)
1262 stat_buf[j*8 + i] = plain[i*8 +j];
1265 else if (plain.
length() == 256) {
1266 for (
int i = 0; i < 16; i++)
1267 for (
int j = 0; j < 16; j++)
1268 stat_buf[j*16 + i] = plain[i*16 +j];
1272 Print(
"Player::DecodeStats() invalid plain text length %d\n", plain.
length());
1278 ZeroMemory(work, 32);
1279 CopyMemory(work, stat_buf, 16);
1280 for (
int i = 15; i > 0; i--)
1281 if (work[i] ==
' ') work[i] = 0;
1285 ZeroMemory(work, 16);
1286 CopyMemory(work, stat_buf+16, 8);
1289 ZeroMemory(work, 16);
1290 CopyMemory(work, stat_buf+24, 8);
1291 sscanf_s(work,
"%x", &
points);
1294 ZeroMemory(work, 16);
1295 CopyMemory(work, stat_buf+32, 8);
1299 ZeroMemory(work, 16);
1300 CopyMemory(work, stat_buf+40, 8);
1304 ZeroMemory(work, 16);
1305 CopyMemory(work, stat_buf+48, 8);
1306 sscanf_s(work,
"%x", &
kills);
1309 ZeroMemory(work, 16);
1310 CopyMemory(work, stat_buf+56, 8);
1311 sscanf_s(work,
"%x", &
losses);
1314 if (plain.
length() > 64) {
1315 ZeroMemory(work, 16);
1316 CopyMemory(work, stat_buf+64, 8);
1317 sscanf_s(work,
"%x", &
medals);
1319 ZeroMemory(work, 16);
1320 CopyMemory(work, stat_buf+72, 8);
1325 ::Print(
"WARNING - loaded player with zero stats '%s'\n",
name.
data());
1337 if (!loader)
return;
1340 const char* filename =
"awards.def";
1353 if (!file_type || file_type->
value() !=
"AWARDS") {
1361 ::Print(
"Loading Ranks and Medals\n");
1364 delete term; term = 0;
1373 Print(
"WARNING: award structure missing in '%s'\n", filename);
1382 if (pdef->
name()->
value() == (
"name")) {
1387 else if (pdef->
name()->
value() == (
"abrv")) {
1392 else if (pdef->
name()->
value() == (
"desc")) {
1398 else if (pdef->
name()->
value() == (
"award")) {
1404 else if (pdef->
name()->
value() == (
"desc_sound"))
1407 else if (pdef->
name()->
value() == (
"award_sound"))
1435 else if (pdef->
name()->
value() == (
"type")) {
1443 else if (txt ==
"medal")
1447 else if (pdef->
name()->
value() == (
"id"))
1450 else if (pdef->
name()->
value() == (
"total_points"))
1453 else if (pdef->
name()->
value() == (
"mission_points"))
1456 else if (pdef->
name()->
value() == (
"total_missions"))
1459 else if (pdef->
name()->
value() == (
"kills"))
1462 else if (pdef->
name()->
value() == (
"lost"))
1465 else if (pdef->
name()->
value() == (
"collision"))
1468 else if (pdef->
name()->
value() == (
"campaign_id"))
1471 else if (pdef->
name()->
value() == (
"campaign_complete"))
1474 else if (pdef->
name()->
value() == (
"dynamic_campaign"))
1477 else if (pdef->
name()->
value() == (
"ceremony"))
1480 else if (pdef->
name()->
value() == (
"required_awards"))
1483 else if (pdef->
name()->
value() == (
"lottery"))
1486 else if (pdef->
name()->
value() == (
"min_rank"))
1489 else if (pdef->
name()->
value() == (
"max_rank"))
1492 else if (pdef->
name()->
value() == (
"min_ship_class")) {
1498 else if (pdef->
name()->
value() == (
"max_ship_class")) {
1510 rank_table.
append(award);
1514 medal_table.
append(award);
1523 Print(
"WARNING: unknown label '%s' in '%s'\n",
1528 Print(
"WARNING: term ignored in '%s'\n", filename);
1548 if (p !=
this && p->
uid >=
uid)