(svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.

pull/155/head
belugas 18 years ago
parent d99a269493
commit 8952924c64

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file namegen.cpp */
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "debug.h" #include "debug.h"
@ -41,21 +43,21 @@ static byte MakeEnglishOriginalTownName(char *buf, uint32 seed, const char *last
{ {
int i; int i;
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
// optional first segment /* optional first segment */
i = SeedChanceBias(0, lengthof(name_original_english_1), seed, 50); i = SeedChanceBias(0, lengthof(name_original_english_1), seed, 50);
if (i >= 0) if (i >= 0)
strecat(buf, name_original_english_1[i], last); strecat(buf, name_original_english_1[i], last);
//mandatory middle segments /* mandatory middle segments */
strecat(buf, name_original_english_2[SeedChance(4, lengthof(name_original_english_2), seed)], last); strecat(buf, name_original_english_2[SeedChance(4, lengthof(name_original_english_2), seed)], last);
strecat(buf, name_original_english_3[SeedChance(7, lengthof(name_original_english_3), seed)], last); strecat(buf, name_original_english_3[SeedChance(7, lengthof(name_original_english_3), seed)], last);
strecat(buf, name_original_english_4[SeedChance(10, lengthof(name_original_english_4), seed)], last); strecat(buf, name_original_english_4[SeedChance(10, lengthof(name_original_english_4), seed)], last);
strecat(buf, name_original_english_5[SeedChance(13, lengthof(name_original_english_5), seed)], last); strecat(buf, name_original_english_5[SeedChance(13, lengthof(name_original_english_5), seed)], last);
//optional last segment /* optional last segment */
i = SeedChanceBias(15, lengthof(name_original_english_6), seed, 60); i = SeedChanceBias(15, lengthof(name_original_english_6), seed, 60);
if (i >= 0) if (i >= 0)
strecat(buf, name_original_english_6[i], last); strecat(buf, name_original_english_6[i], last);
@ -82,10 +84,10 @@ static byte MakeEnglishAdditionalTownName(char *buf, uint32 seed, const char *la
{ {
int i; int i;
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
// optional first segment /* optional first segment */
i = SeedChanceBias(0, lengthof(name_additional_english_prefix), seed, 50); i = SeedChanceBias(0, lengthof(name_additional_english_prefix), seed, 50);
if (i >= 0) if (i >= 0)
strecat(buf,name_additional_english_prefix[i], last); strecat(buf,name_additional_english_prefix[i], last);
@ -104,7 +106,7 @@ static byte MakeEnglishAdditionalTownName(char *buf, uint32 seed, const char *la
strecat(buf, name_additional_english_2[SeedChance(14, lengthof(name_additional_english_2), seed)], last); strecat(buf, name_additional_english_2[SeedChance(14, lengthof(name_additional_english_2), seed)], last);
//optional last segment /* optional last segment */
i = SeedChanceBias(15, lengthof(name_additional_english_3), seed, 60); i = SeedChanceBias(15, lengthof(name_additional_english_3), seed, 60);
if (i >= 0) if (i >= 0)
strecat(buf, name_additional_english_3[i], last); strecat(buf, name_additional_english_3[i], last);
@ -128,32 +130,32 @@ static byte MakeAustrianTownName(char *buf, uint32 seed, const char *last)
int i, j = 0; int i, j = 0;
strecpy(buf, "", last); strecpy(buf, "", last);
// Bad, Maria, Gross, ... /* Bad, Maria, Gross, ... */
i = SeedChanceBias(0, lengthof(name_austrian_a1), seed, 15); i = SeedChanceBias(0, lengthof(name_austrian_a1), seed, 15);
if (i >= 0) strecat(buf, name_austrian_a1[i], last); if (i >= 0) strecat(buf, name_austrian_a1[i], last);
i = SeedChance(4, 6, seed); i = SeedChance(4, 6, seed);
if (i >= 4) { if (i >= 4) {
// Kaisers-kirchen /* Kaisers-kirchen */
strecat(buf, name_austrian_a2[SeedChance( 7, lengthof(name_austrian_a2), seed)], last); strecat(buf, name_austrian_a2[SeedChance( 7, lengthof(name_austrian_a2), seed)], last);
strecat(buf, name_austrian_a3[SeedChance(13, lengthof(name_austrian_a3), seed)], last); strecat(buf, name_austrian_a3[SeedChance(13, lengthof(name_austrian_a3), seed)], last);
} else if (i >= 2) { } else if (i >= 2) {
// St. Johann /* St. Johann */
strecat(buf, name_austrian_a5[SeedChance( 7, lengthof(name_austrian_a5), seed)], last); strecat(buf, name_austrian_a5[SeedChance( 7, lengthof(name_austrian_a5), seed)], last);
strecat(buf, name_austrian_a6[SeedChance( 9, lengthof(name_austrian_a6), seed)], last); strecat(buf, name_austrian_a6[SeedChance( 9, lengthof(name_austrian_a6), seed)], last);
j = 1; // More likely to have a " an der " or " am " j = 1; // More likely to have a " an der " or " am "
} else { } else {
// Zell /* Zell */
strecat(buf, name_austrian_a4[SeedChance( 7, lengthof(name_austrian_a4), seed)], last); strecat(buf, name_austrian_a4[SeedChance( 7, lengthof(name_austrian_a4), seed)], last);
} }
i = SeedChance(1, 6, seed); i = SeedChance(1, 6, seed);
if (i >= 4 - j) { if (i >= 4 - j) {
// an der Donau (rivers) /* an der Donau (rivers) */
strecat(buf, name_austrian_f1[SeedChance(4, lengthof(name_austrian_f1), seed)], last); strecat(buf, name_austrian_f1[SeedChance(4, lengthof(name_austrian_f1), seed)], last);
strecat(buf, name_austrian_f2[SeedChance(5, lengthof(name_austrian_f2), seed)], last); strecat(buf, name_austrian_f2[SeedChance(5, lengthof(name_austrian_f2), seed)], last);
} else if (i >= 2 - j) { } else if (i >= 2 - j) {
// am Dachstein (mountains) /* am Dachstein (mountains) */
strecat(buf, name_austrian_b1[SeedChance(4, lengthof(name_austrian_b1), seed)], last); strecat(buf, name_austrian_b1[SeedChance(4, lengthof(name_austrian_b1), seed)], last);
strecat(buf, name_austrian_b2[SeedChance(5, lengthof(name_austrian_b2), seed)], last); strecat(buf, name_austrian_b2[SeedChance(5, lengthof(name_austrian_b2), seed)], last);
} }
@ -166,18 +168,18 @@ static byte MakeGermanTownName(char *buf, uint32 seed, const char *last)
uint i; uint i;
uint seed_derivative; uint seed_derivative;
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
seed_derivative = SeedChance(7, 28, seed); seed_derivative = SeedChance(7, 28, seed);
//optional prefix /* optional prefix */
if (seed_derivative == 12 || seed_derivative == 19) { if (seed_derivative == 12 || seed_derivative == 19) {
i = SeedChance(2, lengthof(name_german_pre), seed); i = SeedChance(2, lengthof(name_german_pre), seed);
strecat(buf,name_german_pre[i], last); strecat(buf,name_german_pre[i], last);
} }
// mandatory middle segments including option of hardcoded name /* mandatory middle segments including option of hardcoded name */
i = SeedChance(3, lengthof(name_german_real) + lengthof(name_german_1), seed); i = SeedChance(3, lengthof(name_german_real) + lengthof(name_german_1), seed);
if (i < lengthof(name_german_real)) { if (i < lengthof(name_german_real)) {
strecat(buf,name_german_real[i], last); strecat(buf,name_german_real[i], last);
@ -188,7 +190,7 @@ static byte MakeGermanTownName(char *buf, uint32 seed, const char *last)
strecat(buf, name_german_2[i], last); strecat(buf, name_german_2[i], last);
} }
// optional suffix /* optional suffix */
if (seed_derivative == 24) { if (seed_derivative == 24) {
i = SeedChance(9, i = SeedChance(9,
lengthof(name_german_4_an_der) + lengthof(name_german_4_am), seed); lengthof(name_german_4_an_der) + lengthof(name_german_4_am), seed);
@ -226,15 +228,15 @@ static byte MakeSwedishTownName(char *buf, uint32 seed, const char *last)
{ {
int i; int i;
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
// optional first segment /* optional first segment */
i = SeedChanceBias(0, lengthof(name_swedish_1), seed, 50); i = SeedChanceBias(0, lengthof(name_swedish_1), seed, 50);
if (i >= 0) if (i >= 0)
strecat(buf, name_swedish_1[i], last); strecat(buf, name_swedish_1[i], last);
// mandatory middle segments including option of hardcoded name /* mandatory middle segments including option of hardcoded name */
if (SeedChance(4, 5, seed) >= 3) { if (SeedChance(4, 5, seed) >= 3) {
strecat(buf, name_swedish_2[SeedChance( 7, lengthof(name_swedish_2), seed)], last); strecat(buf, name_swedish_2[SeedChance( 7, lengthof(name_swedish_2), seed)], last);
} else { } else {
@ -252,15 +254,15 @@ static byte MakeDutchTownName(char *buf, uint32 seed, const char *last)
{ {
int i; int i;
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
// optional first segment /* optional first segment */
i = SeedChanceBias(0, lengthof(name_dutch_1), seed, 50); i = SeedChanceBias(0, lengthof(name_dutch_1), seed, 50);
if (i >= 0) if (i >= 0)
strecat(buf, name_dutch_1[i], last); strecat(buf, name_dutch_1[i], last);
// mandatory middle segments including option of hardcoded name /* mandatory middle segments including option of hardcoded name */
if (SeedChance(6, 9, seed) > 4) { if (SeedChance(6, 9, seed) > 4) {
strecat(buf, name_dutch_2[SeedChance( 9, lengthof(name_dutch_2), seed)], last); strecat(buf, name_dutch_2[SeedChance( 9, lengthof(name_dutch_2), seed)], last);
} else { } else {
@ -274,16 +276,16 @@ static byte MakeDutchTownName(char *buf, uint32 seed, const char *last)
static byte MakeFinnishTownName(char *buf, uint32 seed, const char *last) static byte MakeFinnishTownName(char *buf, uint32 seed, const char *last)
{ {
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
// Select randomly if town name should consists of one or two parts. /* Select randomly if town name should consists of one or two parts. */
if (SeedChance(0, 15, seed) >= 10) { if (SeedChance(0, 15, seed) >= 10) {
strecat(buf, name_finnish_real[SeedChance(2, lengthof(name_finnish_real), seed)], last); strecat(buf, name_finnish_real[SeedChance(2, lengthof(name_finnish_real), seed)], last);
} else if (SeedChance(0, 15, seed) >= 5) { } else if (SeedChance(0, 15, seed) >= 5) {
// A two-part name by combining one of name_finnish_1 + "la"/"lä" /* A two-part name by combining one of name_finnish_1 + "la"/"lä"
// The reason for not having the contents of name_finnish_{1,2} in the same table is * The reason for not having the contents of name_finnish_{1,2} in the same table is
// that the ones in name_finnish_2 are not good for this purpose. * that the ones in name_finnish_2 are not good for this purpose. */
uint sel = SeedChance( 0, lengthof(name_finnish_1), seed); uint sel = SeedChance( 0, lengthof(name_finnish_1), seed);
char *end; char *end;
strecat(buf, name_finnish_1[sel], last); strecat(buf, name_finnish_1[sel], last);
@ -298,8 +300,8 @@ static byte MakeFinnishTownName(char *buf, uint32 seed, const char *last)
strecat(buf, "", last); strecat(buf, "", last);
} }
} else { } else {
// A two-part name by combining one of name_finnish_{1,2} + name_finnish_3. /* A two-part name by combining one of name_finnish_{1,2} + name_finnish_3.
// Why aren't name_finnish_{1,2} just one table? See above. * Why aren't name_finnish_{1,2} just one table? See above. */
uint sel = SeedChance(2, uint sel = SeedChance(2,
lengthof(name_finnish_1) + lengthof(name_finnish_2), seed); lengthof(name_finnish_1) + lengthof(name_finnish_2), seed);
if (sel >= lengthof(name_finnish_1)) { if (sel >= lengthof(name_finnish_1)) {
@ -318,10 +320,10 @@ static byte MakePolishTownName(char *buf, uint32 seed, const char *last)
uint i; uint i;
uint j; uint j;
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
// optional first segment /* optional first segment */
i = SeedChance(0, i = SeedChance(0,
lengthof(name_polish_2_o) + lengthof(name_polish_2_m) + lengthof(name_polish_2_o) + lengthof(name_polish_2_m) +
lengthof(name_polish_2_f) + lengthof(name_polish_2_n), lengthof(name_polish_2_f) + lengthof(name_polish_2_n),
@ -374,13 +376,13 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
CzechChoose choose; CzechChoose choose;
CzechAllow allow; CzechAllow allow;
// 1:3 chance to use a real name. /* 1:3 chance to use a real name. */
if (SeedModChance(0, 4, seed) == 0) { if (SeedModChance(0, 4, seed) == 0) {
strecpy(buf, name_czech_real[SeedModChance(4, lengthof(name_czech_real), seed)], last); strecpy(buf, name_czech_real[SeedModChance(4, lengthof(name_czech_real), seed)], last);
return 0; return 0;
} }
// NUL terminates the string for strcat() /* NUL terminates the string for strcat() */
strecpy(buf, "", last); strecpy(buf, "", last);
prob_tails = SeedModChance(2, 32, seed); prob_tails = SeedModChance(2, 32, seed);
@ -389,12 +391,12 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
if (do_prefix) prefix = SeedModChance(5, lengthof(name_czech_adj) * 12, seed) / 12; if (do_prefix) prefix = SeedModChance(5, lengthof(name_czech_adj) * 12, seed) / 12;
if (do_suffix) suffix = SeedModChance(7, lengthof(name_czech_suffix), seed); if (do_suffix) suffix = SeedModChance(7, lengthof(name_czech_suffix), seed);
// 3:1 chance 3:1 to use dynamic substantive /* 3:1 chance 3:1 to use dynamic substantive */
stem = SeedModChance(9, stem = SeedModChance(9,
lengthof(name_czech_subst_full) + 3 * lengthof(name_czech_subst_stem), lengthof(name_czech_subst_full) + 3 * lengthof(name_czech_subst_stem),
seed); seed);
if (stem < lengthof(name_czech_subst_full)) { if (stem < lengthof(name_czech_subst_full)) {
// That was easy! /* That was easy! */
dynamic_subst = false; dynamic_subst = false;
gender = name_czech_subst_full[stem].gender; gender = name_czech_subst_full[stem].gender;
choose = name_czech_subst_full[stem].choose; choose = name_czech_subst_full[stem].choose;
@ -404,7 +406,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
int ending_start = -1, ending_stop = -1; int ending_start = -1, ending_stop = -1;
int i; int i;
// Load the substantive /* Load the substantive */
dynamic_subst = true; dynamic_subst = true;
stem -= lengthof(name_czech_subst_full); stem -= lengthof(name_czech_subst_full);
stem %= lengthof(name_czech_subst_stem); stem %= lengthof(name_czech_subst_stem);
@ -412,15 +414,15 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
choose = name_czech_subst_stem[stem].choose; choose = name_czech_subst_stem[stem].choose;
allow = name_czech_subst_stem[stem].allow; allow = name_czech_subst_stem[stem].allow;
// Load the postfix (1:1 chance that a postfix will be inserted) /* Load the postfix (1:1 chance that a postfix will be inserted) */
postfix = SeedModChance(14, lengthof(name_czech_subst_postfix) * 2, seed); postfix = SeedModChance(14, lengthof(name_czech_subst_postfix) * 2, seed);
if (choose & CZC_POSTFIX) { if (choose & CZC_POSTFIX) {
// Always get a real postfix. /* Always get a real postfix. */
postfix %= lengthof(name_czech_subst_postfix); postfix %= lengthof(name_czech_subst_postfix);
} }
if (choose & CZC_NOPOSTFIX) { if (choose & CZC_NOPOSTFIX) {
// Always drop a postfix. /* Always drop a postfix. */
postfix += lengthof(name_czech_subst_postfix); postfix += lengthof(name_czech_subst_postfix);
} }
if (postfix < lengthof(name_czech_subst_postfix)) { if (postfix < lengthof(name_czech_subst_postfix)) {
@ -429,7 +431,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
choose |= CZC_NOPOSTFIX; choose |= CZC_NOPOSTFIX;
} }
// Localize the array segment containing a good gender /* Localize the array segment containing a good gender */
for (ending = 0; ending < (int) lengthof(name_czech_subst_ending); ending++) { for (ending = 0; ending < (int) lengthof(name_czech_subst_ending); ending++) {
const CzechNameSubst *e = &name_czech_subst_ending[ending]; const CzechNameSubst *e = &name_czech_subst_ending[ending];
@ -445,11 +447,11 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
} }
} }
if (ending_stop < 0) { if (ending_stop < 0) {
// Whoa. All the endings matched. /* Whoa. All the endings matched. */
ending_stop = ending - 1; ending_stop = ending - 1;
} }
// Make a sequential map of the items with good mask /* Make a sequential map of the items with good mask */
i = 0; i = 0;
for (ending = ending_start; ending <= ending_stop; ending++) { for (ending = ending_start; ending <= ending_stop; ending++) {
const CzechNameSubst *e = &name_czech_subst_ending[ending]; const CzechNameSubst *e = &name_czech_subst_ending[ending];
@ -459,20 +461,20 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
} }
assert(i > 0); assert(i > 0);
// Load the ending /* Load the ending */
ending = map[SeedModChance(16, i, seed)]; ending = map[SeedModChance(16, i, seed)];
// Override possible CZG_*FREE; this must be a real gender, /* Override possible CZG_*FREE; this must be a real gender,
// otherwise we get overflow when modifying the adjectivum. * otherwise we get overflow when modifying the adjectivum. */
gender = name_czech_subst_ending[ending].gender; gender = name_czech_subst_ending[ending].gender;
assert(gender != CZG_FREE && gender != CZG_NFREE); assert(gender != CZG_FREE && gender != CZG_NFREE);
} }
if (do_prefix && (name_czech_adj[prefix].choose & choose) != choose) { if (do_prefix && (name_czech_adj[prefix].choose & choose) != choose) {
// Throw away non-matching prefix. /* Throw away non-matching prefix. */
do_prefix = false; do_prefix = false;
} }
// Now finally construct the name /* Now finally construct the name */
if (do_prefix) { if (do_prefix) {
CzechPattern pattern = name_czech_adj[prefix].pattern; CzechPattern pattern = name_czech_adj[prefix].pattern;
@ -505,7 +507,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
endlen = strlen(endstr); endlen = strlen(endstr);
assert(postlen > 0 && endlen > 0); assert(postlen > 0 && endlen > 0);
// Kill the "avava" and "Jananna"-like cases /* Kill the "avava" and "Jananna"-like cases */
if (postlen < 2 || postlen > endlen || ( if (postlen < 2 || postlen > endlen || (
(poststr[1] != 'v' || poststr[1] != endstr[1]) && (poststr[1] != 'v' || poststr[1] != endstr[1]) &&
poststr[2] != endstr[1]) poststr[2] != endstr[1])
@ -514,7 +516,7 @@ static byte MakeCzechTownName(char *buf, uint32 seed, const char *last)
strecat(buf, poststr, last); strecat(buf, poststr, last);
buflen = strlen(buf); buflen = strlen(buf);
// k-i -> c-i, h-i -> z-i /* k-i -> c-i, h-i -> z-i */
if (endstr[0] == 'i') { if (endstr[0] == 'i') {
switch (buf[buflen - 1]) { switch (buf[buflen - 1]) {
case 'k': buf[buflen - 1] = 'c'; break; case 'k': buf[buflen - 1] = 'c'; break;
@ -553,15 +555,15 @@ static byte MakeNorwegianTownName(char *buf, uint32 seed, const char *last)
{ {
strecpy(buf, "", last); strecpy(buf, "", last);
// Use first 4 bit from seed to decide whether or not this town should /* Use first 4 bit from seed to decide whether or not this town should
// have a real name 3/16 chance. Bit 0-3 * have a real name 3/16 chance. Bit 0-3 */
if (SeedChance(0, 15, seed) < 3) { if (SeedChance(0, 15, seed) < 3) {
// Use 7bit for the realname table index. Bit 4-10 /* Use 7bit for the realname table index. Bit 4-10 */
strecat(buf, name_norwegian_real[SeedChance(4, lengthof(name_norwegian_real), seed)], last); strecat(buf, name_norwegian_real[SeedChance(4, lengthof(name_norwegian_real), seed)], last);
} else { } else {
// Use 7bit for the first fake part. Bit 4-10 /* Use 7bit for the first fake part. Bit 4-10 */
strecat(buf, name_norwegian_1[SeedChance(4, lengthof(name_norwegian_1), seed)], last); strecat(buf, name_norwegian_1[SeedChance(4, lengthof(name_norwegian_1), seed)], last);
// Use 7bit for the last fake part. Bit 11-17 /* Use 7bit for the last fake part. Bit 11-17 */
strecat(buf, name_norwegian_2[SeedChance(11, lengthof(name_norwegian_2), seed)], last); strecat(buf, name_norwegian_2[SeedChance(11, lengthof(name_norwegian_2), seed)], last);
} }
@ -572,22 +574,22 @@ static byte MakeHungarianTownName(char *buf, uint32 seed, const char *last)
{ {
uint i; uint i;
//null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
if (SeedChance(12, 15, seed) < 3) { if (SeedChance(12, 15, seed) < 3) {
strecat(buf, name_hungarian_real[SeedChance(0, lengthof(name_hungarian_real), seed)], last); strecat(buf, name_hungarian_real[SeedChance(0, lengthof(name_hungarian_real), seed)], last);
} else { } else {
// optional first segment /* optional first segment */
i = SeedChance(3, lengthof(name_hungarian_1) * 3, seed); i = SeedChance(3, lengthof(name_hungarian_1) * 3, seed);
if (i < lengthof(name_hungarian_1)) if (i < lengthof(name_hungarian_1))
strecat(buf, name_hungarian_1[i], last); strecat(buf, name_hungarian_1[i], last);
// mandatory middle segments /* mandatory middle segments */
strecat(buf, name_hungarian_2[SeedChance(3, lengthof(name_hungarian_2), seed)], last); strecat(buf, name_hungarian_2[SeedChance(3, lengthof(name_hungarian_2), seed)], last);
strecat(buf, name_hungarian_3[SeedChance(6, lengthof(name_hungarian_3), seed)], last); strecat(buf, name_hungarian_3[SeedChance(6, lengthof(name_hungarian_3), seed)], last);
// optional last segment /* optional last segment */
i = SeedChance(10, lengthof(name_hungarian_4) * 3, seed); i = SeedChance(10, lengthof(name_hungarian_4) * 3, seed);
if (i < lengthof(name_hungarian_4)) { if (i < lengthof(name_hungarian_4)) {
strecat(buf, name_hungarian_4[i], last); strecat(buf, name_hungarian_4[i], last);
@ -607,15 +609,15 @@ static byte MakeDanishTownName(char *buf, uint32 seed, const char *last)
{ {
int i; int i;
// null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
// optional first segment /* optional first segment */
i = SeedChanceBias(0, lengthof(name_danish_1), seed, 50); i = SeedChanceBias(0, lengthof(name_danish_1), seed, 50);
if (i >= 0) if (i >= 0)
strecat(buf, name_danish_1[i], last); strecat(buf, name_danish_1[i], last);
// middle segments removed as this algorithm seems to create much more realistic names /* middle segments removed as this algorithm seems to create much more realistic names */
strecat(buf, name_danish_2[SeedChance( 7, lengthof(name_danish_2), seed)], last); strecat(buf, name_danish_2[SeedChance( 7, lengthof(name_danish_2), seed)], last);
strecat(buf, name_danish_3[SeedChance(16, lengthof(name_danish_3), seed)], last); strecat(buf, name_danish_3[SeedChance(16, lengthof(name_danish_3), seed)], last);
@ -626,16 +628,16 @@ static byte MakeTurkishTownName(char *buf, uint32 seed, const char *last)
{ {
uint i; uint i;
// null terminates the string for strcat /* null terminates the string for strcat */
strecpy(buf, "", last); strecpy(buf, "", last);
if ((i = SeedModChance(0, 5, seed)) == 0) { if ((i = SeedModChance(0, 5, seed)) == 0) {
strecat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)], last); strecat(buf, name_turkish_prefix[SeedModChance( 2, lengthof(name_turkish_prefix), seed)], last);
// middle segment /* middle segment */
strecat(buf, name_turkish_middle[SeedModChance( 4, lengthof(name_turkish_middle), seed)], last); strecat(buf, name_turkish_middle[SeedModChance( 4, lengthof(name_turkish_middle), seed)], last);
// optional suffix /* optional suffix */
if (SeedModChance(0, 7, seed) == 0) { if (SeedModChance(0, 7, seed) == 0) {
strecat(buf, name_turkish_suffix[SeedModChance( 10, lengthof(name_turkish_suffix), seed)], last); strecat(buf, name_turkish_suffix[SeedModChance( 10, lengthof(name_turkish_suffix), seed)], last);
} }
@ -757,30 +759,30 @@ TownNameGenerator * const _town_name_generators[] =
MakeCatalanTownName, MakeCatalanTownName,
}; };
// DO WE NEED THIS ANY MORE? /* DO WE NEED THIS ANY MORE? */
#define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z) #define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z)
uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type) uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type)
{ {
switch (old_town_name_type) { switch (old_town_name_type) {
case 0: case 3: /* English, American */ case 0: case 3: // English, American
/* Already OK */ /* Already OK */
return townnameparts; return townnameparts;
case 1: /* French */ case 1: // French
/* For some reason 86 needs to be subtracted from townnameparts /* For some reason 86 needs to be subtracted from townnameparts
* 0000 0000 0000 0000 0000 0000 1111 1111 */ * 0000 0000 0000 0000 0000 0000 1111 1111 */
return FIXNUM(townnameparts - 86, lengthof(name_french_real), 0); return FIXNUM(townnameparts - 86, lengthof(name_french_real), 0);
case 2: /* German */ case 2: // German
DEBUG(misc, 0, "German Townnames are buggy (%d)", townnameparts); DEBUG(misc, 0, "German Townnames are buggy (%d)", townnameparts);
return townnameparts; return townnameparts;
case 4: /* Latin-American */ case 4: // Latin-American
/* 0000 0000 0000 0000 0000 0000 1111 1111 */ /* 0000 0000 0000 0000 0000 0000 1111 1111 */
return FIXNUM(townnameparts, lengthof(name_spanish_real), 0); return FIXNUM(townnameparts, lengthof(name_spanish_real), 0);
case 5: /* Silly */ case 5: // Silly
/* NUM_SILLY_1 - lower 16 bits /* NUM_SILLY_1 - lower 16 bits
* NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes) * NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes)
* 1000 0000 2222 2222 0000 0000 1111 1111 */ * 1000 0000 2222 2222 0000 0000 1111 1111 */

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file namegen.h */
#ifndef NAMEGEN_H #ifndef NAMEGEN_H
#define NAMEGEN_H #define NAMEGEN_H

File diff suppressed because it is too large Load Diff

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf.h */
#ifndef NEWGRF_H #ifndef NEWGRF_H
#define NEWGRF_H #define NEWGRF_H
@ -60,7 +62,7 @@ struct GRFFile {
HouseSpec **housespec; HouseSpec **housespec;
uint32 param[0x80]; uint32 param[0x80];
uint param_end; /// one more than the highest set parameter uint param_end; ///< one more than the highest set parameter
GRFLabel *label; ///< Pointer to the first label. This is a linked list, not an array. GRFLabel *label; ///< Pointer to the first label. This is a linked list, not an array.
@ -78,7 +80,7 @@ extern bool _have_newhouses;
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage); void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage);
void LoadNewGRF(uint load_index, uint file_index); void LoadNewGRF(uint load_index, uint file_index);
void ReloadNewGRFData(); // in openttd.c void ReloadNewGRFData(); // in openttd.cpp
void CDECL grfmsg(int severity, const char *str, ...); void CDECL grfmsg(int severity, const char *str, ...);

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_cargo.h */
#ifndef NEWGRF_CARGO_H #ifndef NEWGRF_CARGO_H
#define NEWGRF_CARGO_H #define NEWGRF_CARGO_H

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgfr_config.cpp */
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "functions.h" #include "functions.h"
@ -481,3 +483,4 @@ extern const ChunkHandler _newgrf_chunk_handlers[] = {
}; };

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_config.h */
#ifndef NEWGRF_CONFIG_H #ifndef NEWGRF_CONFIG_H
#define NEWGRF_CONFIG_H #define NEWGRF_CONFIG_H
@ -80,7 +82,7 @@ GRFListCompatibility IsGoodGRFConfigList();
bool FillGRFDetails(GRFConfig *config, bool is_static); bool FillGRFDetails(GRFConfig *config, bool is_static);
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last); char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
/* In newgrf_gui.c */ /* In newgrf_gui.cpp */
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config); void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_engine.cpp */
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "variables.h" #include "variables.h"
@ -66,10 +68,10 @@ static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID car
const WagonOverrides *wos = &_engine_wagon_overrides[engine]; const WagonOverrides *wos = &_engine_wagon_overrides[engine];
int i; int i;
// XXX: This could turn out to be a timesink on profiles. We could /* XXX: This could turn out to be a timesink on profiles. We could
// always just dedicate 65535 bytes for an [engine][train] trampoline * always just dedicate 65535 bytes for an [engine][train] trampoline
// for O(1). Or O(logMlogN) and searching binary tree or smt. like * for O(1). Or O(logMlogN) and searching binary tree or smt. like
// that. --pasky * that. --pasky */
for (i = 0; i < wos->overrides_count; i++) { for (i = 0; i < wos->overrides_count; i++) {
const WagonOverride *wo = &wos->overrides[i]; const WagonOverride *wo = &wos->overrides[i];
@ -260,11 +262,11 @@ static byte MapAircraftMovementState(const Vehicle *v)
* to a landing by the hanger of an international airport. */ * to a landing by the hanger of an international airport. */
if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER; if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER;
// The final two conditions apply to helicopters or aircraft. /* The final two conditions apply to helicopters or aircraft.
/* Has reached hanger? */ * Has reached hanger? */
if (amdflag & AMED_EXACTPOS) return AMS_TTDP_HANGAR; if (amdflag & AMED_EXACTPOS) return AMS_TTDP_HANGAR;
// Still moving towards hanger. /* Still moving towards hanger. */
return AMS_TTDP_TO_HANGAR; return AMS_TTDP_TO_HANGAR;
case TERM1: case TERM1:
@ -318,7 +320,7 @@ static byte MapAircraftMovementState(const Vehicle *v)
case ENDLANDING: // On the runway braking case ENDLANDING: // On the runway braking
if (amdflag & AMED_BRAKE) return AMS_TTDP_BRAKING; if (amdflag & AMED_BRAKE) return AMS_TTDP_BRAKING;
// Landed - moving off runway /* Landed - moving off runway */
return AMS_TTDP_TO_INWAY; return AMS_TTDP_TO_INWAY;
case HELILANDING: case HELILANDING:
@ -393,7 +395,7 @@ static byte MapAircraftMovementAction(const Vehicle *v)
case STARTTAKEOFF: // Accelerating down runway case STARTTAKEOFF: // Accelerating down runway
case ENDTAKEOFF: // Ascent case ENDTAKEOFF: // Ascent
case HELITAKEOFF: case HELITAKEOFF:
// TODO Need to find which terminal (or hanger) we've come from. How? /* @todo Need to find which terminal (or hanger) we've come from. How? */
return AMA_TTDP_PAD1_TO_TAKEOFF; return AMA_TTDP_PAD1_TO_TAKEOFF;
case FLYING: case FLYING:
@ -403,7 +405,7 @@ static byte MapAircraftMovementAction(const Vehicle *v)
case ENDLANDING: // On the runway braking case ENDLANDING: // On the runway braking
case HELILANDING: case HELILANDING:
case HELIENDLANDING: case HELIENDLANDING:
// TODO Need to check terminal we're landing to. Is it known yet? /* @todo Need to check terminal we're landing to. Is it known yet? */
return (v->current_order.type == OT_GOTO_DEPOT) ? return (v->current_order.type == OT_GOTO_DEPOT) ?
AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1; AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
@ -473,12 +475,12 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
if (v == NULL) { if (v == NULL) {
/* Vehicle does not exist, so we're in a purchase list */ /* Vehicle does not exist, so we're in a purchase list */
switch (variable) { switch (variable) {
case 0x43: return _current_player; /* Owner information */ case 0x43: return _current_player; // Owner information
case 0x46: return 0; /* Motion counter */ case 0x46: return 0; // Motion counter
case 0x48: return GetEngine(object->u.vehicle.self_type)->flags; /* Vehicle Type Info */ case 0x48: return GetEngine(object->u.vehicle.self_type)->flags; // Vehicle Type Info
case 0xC4: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; /* Build year */ case 0xC4: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
case 0xDA: return INVALID_VEHICLE; /* Next vehicle */ case 0xDA: return INVALID_VEHICLE; // Next vehicle
case 0x7F: return GetGRFParameter(object->u.vehicle.self_type, parameter); /* Read GRF parameter */ case 0x7F: return GetGRFParameter(object->u.vehicle.self_type, parameter); // Read GRF parameter
} }
*available = false; *available = false;
@ -487,8 +489,8 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
/* Calculated vehicle parameters */ /* Calculated vehicle parameters */
switch (variable) { switch (variable) {
case 0x40: /* Get length of consist */ case 0x40: // Get length of consist
case 0x41: /* Get length of same consecutive wagons */ case 0x41: // Get length of same consecutive wagons
if (v->type != VEH_TRAIN) return 1; if (v->type != VEH_TRAIN) return 1;
{ {
@ -509,7 +511,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
return chain_before | chain_after << 8 | (chain_before + chain_after + (variable == 0x41)) << 16; return chain_before | chain_after << 8 | (chain_before + chain_after + (variable == 0x41)) << 16;
} }
case 0x42: { /* Consist cargo information */ case 0x42: { // Consist cargo information
/* XXX Missing support for common refit cycle and property 25 */ /* XXX Missing support for common refit cycle and property 25 */
const Vehicle *u; const Vehicle *u;
byte cargo_classes = 0; byte cargo_classes = 0;
@ -541,15 +543,15 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
return cargo_classes | (common_cargo_type << 8) | (user_def_data << 24); return cargo_classes | (common_cargo_type << 8) | (user_def_data << 24);
} }
case 0x43: /* Player information */ case 0x43: // Player information
return v->owner; return v->owner;
case 0x44: /* Aircraft information */ case 0x44: // Aircraft information
if (v->type != VEH_AIRCRAFT) return UINT_MAX; if (v->type != VEH_AIRCRAFT) return UINT_MAX;
{ {
const Vehicle *w = v->next; const Vehicle *w = v->next;
uint16 altitude = v->z_pos - w->z_pos; /* Aircraft height - shadow height */ uint16 altitude = v->z_pos - w->z_pos; // Aircraft height - shadow height
byte airporttype; byte airporttype;
switch (GetStation(v->u.air.targetairport)->airport_type) { switch (GetStation(v->u.air.targetairport)->airport_type) {
@ -571,10 +573,10 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
return (altitude << 8) | airporttype; return (altitude << 8) | airporttype;
} }
case 0x46: /* Motion counter */ case 0x46: // Motion counter
return v->motion_counter; return v->motion_counter;
case 0x47: { /* Vehicle cargo info */ case 0x47: { // Vehicle cargo info
/* Format: ccccwwtt /* Format: ccccwwtt
* tt - the cargo type transported by the vehicle, * tt - the cargo type transported by the vehicle,
* translated if a translation table has been installed. * translated if a translation table has been installed.
@ -586,10 +588,10 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type]; return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type];
} }
case 0x48: return GetEngine(v->engine_type)->flags; /* Vehicle Type Info */ case 0x48: return GetEngine(v->engine_type)->flags; // Vehicle Type Info
/* Variables which use the parameter */ /* Variables which use the parameter */
case 0x60: /* Count consist's engine ID occurance */ case 0x60: // Count consist's engine ID occurance
if (v->type != VEH_TRAIN) return v->engine_type == parameter; if (v->type != VEH_TRAIN) return v->engine_type == parameter;
{ {
@ -600,13 +602,13 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
return count; return count;
} }
case 0x7F: return GetGRFParameter(v->engine_type, parameter); /* Read GRF parameter */ case 0x7F: return GetGRFParameter(v->engine_type, parameter); // Read GRF parameter
case 0xFE: case 0xFE:
case 0xFF: { case 0xFF: {
uint16 modflags = 0; uint16 modflags = 0;
/* TODO: There are some other bits that should be implemented: /* @todo: There are some other bits that should be implemented:
* bit 5: Whether the rail vehicle is powered or not (mostly useful for wagons). * bit 5: Whether the rail vehicle is powered or not (mostly useful for wagons).
* bit 6: This is an electrically powered rail vehicle which is running on normal rail. * bit 6: This is an electrically powered rail vehicle which is running on normal rail.
* bit 8: (Maybe?) Toggled whenever the train reverses. * bit 8: (Maybe?) Toggled whenever the train reverses.
@ -992,7 +994,7 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando
void TriggerVehicle(Vehicle *v, VehicleTrigger trigger) void TriggerVehicle(Vehicle *v, VehicleTrigger trigger)
{ {
if (trigger == VEHICLE_TRIGGER_DEPOT) { if (trigger == VEHICLE_TRIGGER_DEPOT) {
// store that the vehicle entered a depot this tick /* store that the vehicle entered a depot this tick */
VehicleEnteredDepotThisTick(v); VehicleEnteredDepotThisTick(v);
} }
@ -1020,8 +1022,8 @@ StringID GetCustomEngineName(EngineID engine)
return _engine_custom_names[engine] == 0 ? _engine_name_strings[engine] : _engine_custom_names[engine]; return _engine_custom_names[engine] == 0 ? _engine_name_strings[engine] : _engine_custom_names[engine];
} }
// Functions for changing the order of vehicle purchase lists /* Functions for changing the order of vehicle purchase lists
// This is currently only implemented for rail vehicles. * This is currently only implemented for rail vehicles. */
static EngineID _engine_list_order[NUM_TRAIN_ENGINES]; static EngineID _engine_list_order[NUM_TRAIN_ENGINES];
static byte _engine_list_position[NUM_TRAIN_ENGINES]; static byte _engine_list_position[NUM_TRAIN_ENGINES];
@ -1066,13 +1068,13 @@ void AlterRailVehListOrder(EngineID engine, EngineID target)
if (engine == target) return; if (engine == target) return;
// First, remove our ID from the list. /* First, remove our ID from the list. */
for (i = 0; i < NUM_TRAIN_ENGINES - 1; i++) { for (i = 0; i < NUM_TRAIN_ENGINES - 1; i++) {
if (_engine_list_order[i] == engine) moving = true; if (_engine_list_order[i] == engine) moving = true;
if (moving) _engine_list_order[i] = _engine_list_order[i + 1]; if (moving) _engine_list_order[i] = _engine_list_order[i + 1];
} }
// Now, insert it again, before the target engine. /* Now, insert it again, before the target engine. */
for (i = NUM_TRAIN_ENGINES - 1; i > 0; i--) { for (i = NUM_TRAIN_ENGINES - 1; i > 0; i--) {
_engine_list_order[i] = _engine_list_order[i - 1]; _engine_list_order[i] = _engine_list_order[i - 1];
if (_engine_list_order[i] == target) { if (_engine_list_order[i] == target) {
@ -1081,7 +1083,7 @@ void AlterRailVehListOrder(EngineID engine, EngineID target)
} }
} }
// Update the engine list position (a reverse of engine list order) /* Update the engine list position (a reverse of engine list order) */
for (i = 0; i < NUM_TRAIN_ENGINES; i++) { for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
_engine_list_position[_engine_list_order[i]] = i; _engine_list_position[_engine_list_order[i]] = i;
} }

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_engine.h */
#ifndef NEWGRF_ENGINE_H #ifndef NEWGRF_ENGINE_H
#define NEWGRF_ENGINE_H #define NEWGRF_ENGINE_H
@ -7,9 +9,6 @@
#include "direction.h" #include "direction.h"
#include "newgrf_cargo.h" #include "newgrf_cargo.h"
/** @file newgrf_engine.h
*/
extern int _traininfo_vehicle_pitch; extern int _traininfo_vehicle_pitch;
extern int _traininfo_vehicle_width; extern int _traininfo_vehicle_width;
@ -38,11 +37,11 @@ bool UsesWagonOverride(const Vehicle *v);
enum VehicleTrigger { enum VehicleTrigger {
VEHICLE_TRIGGER_NEW_CARGO = 1, VEHICLE_TRIGGER_NEW_CARGO = 1,
// Externally triggered only for the first vehicle in chain /* Externally triggered only for the first vehicle in chain */
VEHICLE_TRIGGER_DEPOT = 2, VEHICLE_TRIGGER_DEPOT = 2,
// Externally triggered only for the first vehicle in chain, only if whole chain is empty /* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
VEHICLE_TRIGGER_EMPTY = 4, VEHICLE_TRIGGER_EMPTY = 4,
// Not triggered externally (called for the whole chain if we got NEW_CARGO) /* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
VEHICLE_TRIGGER_ANY_NEW_CARGO = 8, VEHICLE_TRIGGER_ANY_NEW_CARGO = 8,
}; };
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger); void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_gui.cpp */
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "functions.h" #include "functions.h"
@ -157,7 +159,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
case WE_CLICK: case WE_CLICK:
switch (e->we.click.widget) { switch (e->we.click.widget) {
case 3: { case 3: {
// Get row... /* Get row... */
const GRFConfig *c; const GRFConfig *c;
uint i = (e->we.click.pt.y - w->widget[3].top) / 10 + w->vscroll.pos; uint i = (e->we.click.pt.y - w->widget[3].top) / 10 + w->vscroll.pos;
@ -167,7 +169,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
break; break;
} }
case 6: /* Add selection to list */ case 6: // Add selection to list
if (WP(w, newgrf_add_d).sel != NULL) { if (WP(w, newgrf_add_d).sel != NULL) {
const GRFConfig *src = WP(w, newgrf_add_d).sel; const GRFConfig *src = WP(w, newgrf_add_d).sel;
GRFConfig **list; GRFConfig **list;
@ -196,7 +198,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
} }
break; break;
case 7: /* Rescan list */ case 7: // Rescan list
WP(w, newgrf_add_d).sel = NULL; WP(w, newgrf_add_d).sel = NULL;
ScanNewGRFFiles(); ScanNewGRFFiles();
SetWindowDirty(w); SetWindowDirty(w);
@ -376,7 +378,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
case WE_CLICK: case WE_CLICK:
switch (e->we.click.widget) { switch (e->we.click.widget) {
case SNGRFS_ADD: { /* Add GRF */ case SNGRFS_ADD: { // Add GRF
GRFConfig **list = WP(w, newgrf_d).list; GRFConfig **list = WP(w, newgrf_d).list;
Window *w; Window *w;
@ -388,7 +390,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
break; break;
} }
case SNGRFS_REMOVE: { /* Remove GRF */ case SNGRFS_REMOVE: { // Remove GRF
GRFConfig **pc, *c, *newsel; GRFConfig **pc, *c, *newsel;
/* Choose the next GRF file to be the selected file */ /* Choose the next GRF file to be the selected file */
@ -412,7 +414,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
break; break;
} }
case SNGRFS_MOVE_UP: { /* Move GRF up */ case SNGRFS_MOVE_UP: { // Move GRF up
GRFConfig **pc, *c; GRFConfig **pc, *c;
if (WP(w, newgrf_d).sel == NULL) break; if (WP(w, newgrf_d).sel == NULL) break;
@ -428,7 +430,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
break; break;
} }
case SNGRFS_MOVE_DOWN: { /* Move GRF down */ case SNGRFS_MOVE_DOWN: { // Move GRF down
GRFConfig **pc, *c; GRFConfig **pc, *c;
if (WP(w, newgrf_d).sel == NULL) break; if (WP(w, newgrf_d).sel == NULL) break;
@ -444,7 +446,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
break; break;
} }
case SNGRFS_FILE_LIST: { /* Select a GRF */ case SNGRFS_FILE_LIST: { // Select a GRF
GRFConfig *c; GRFConfig *c;
uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos; uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos;
@ -455,7 +457,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
break; break;
} }
case SNGRFS_APPLY_CHANGES: /* Apply changes made to GRF list */ case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
if (WP(w, newgrf_d).execute) { if (WP(w, newgrf_d).execute) {
ShowQuery( ShowQuery(
STR_POPUP_CAUTION_CAPTION, STR_POPUP_CAUTION_CAPTION,
@ -468,7 +470,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
} }
break; break;
case SNGRFS_SET_PARAMETERS: { /* Edit parameters */ case SNGRFS_SET_PARAMETERS: { // Edit parameters
char buff[512]; char buff[512];
if (WP(w, newgrf_d).sel == NULL) break; if (WP(w, newgrf_d).sel == NULL) break;

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_sound.cpp */
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "oldpool.h" #include "oldpool.h"

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_sound.h */
#ifndef NEWGRF_SOUND_H #ifndef NEWGRF_SOUND_H
#define NEWGRF_SOUND_H #define NEWGRF_SOUND_H

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_spritegroup.cpp */
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "variables.h" #include "variables.h"

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file newgrf_spritegroup.h */
#ifndef NEWGRF_SPRITEGROUP_H #ifndef NEWGRF_SPRITEGROUP_H
#define NEWGRF_SPRITEGROUP_H #define NEWGRF_SPRITEGROUP_H
@ -11,12 +13,12 @@ struct SpriteGroup;
/* 'Real' sprite groups contain a list of other result or callback sprite /* 'Real' sprite groups contain a list of other result or callback sprite
* groups. */ * groups. */
struct RealSpriteGroup { struct RealSpriteGroup {
// Loaded = in motion, loading = not moving /* Loaded = in motion, loading = not moving
// Each group contains several spritesets, for various loading stages * Each group contains several spritesets, for various loading stages */
// XXX: For stations the meaning is different - loaded is for stations /* XXX: For stations the meaning is different - loaded is for stations
// with small amount of cargo whilst loading is for stations with a lot * with small amount of cargo whilst loading is for stations with a lot
// of da stuff. * of da stuff. */
byte num_loaded; ///< Number of loaded groups byte num_loaded; ///< Number of loaded groups
byte num_loading; ///< Number of loading groups byte num_loading; ///< Number of loading groups
@ -27,7 +29,7 @@ struct RealSpriteGroup {
/* Shared by deterministic and random groups. */ /* Shared by deterministic and random groups. */
enum VarSpriteGroupScope { enum VarSpriteGroupScope {
VSG_SCOPE_SELF, VSG_SCOPE_SELF,
// Engine of consists for vehicles, city for stations. /* Engine of consists for vehicles, city for stations. */
VSG_SCOPE_PARENT, VSG_SCOPE_PARENT,
}; };
@ -44,20 +46,20 @@ enum DeterministicSpriteGroupAdjustType {
}; };
enum DeterministicSpriteGroupAdjustOperation { enum DeterministicSpriteGroupAdjustOperation {
DSGA_OP_ADD, // a + b DSGA_OP_ADD, ///< a + b
DSGA_OP_SUB, // a - b DSGA_OP_SUB, ///< a - b
DSGA_OP_SMIN, // (signed) min(a, b) DSGA_OP_SMIN, ///< (signed) min(a, b)
DSGA_OP_SMAX, // (signed) max(a, b) DSGA_OP_SMAX, ///< (signed) max(a, b)
DSGA_OP_UMIN, // (unsigned) min(a, b) DSGA_OP_UMIN, ///< (unsigned) min(a, b)
DSGA_OP_UMAX, // (unsigned) max(a, b) DSGA_OP_UMAX, ///< (unsigned) max(a, b)
DSGA_OP_SDIV, // (signed) a / b DSGA_OP_SDIV, ///< (signed) a / b
DSGA_OP_SMOD, // (signed) a % b DSGA_OP_SMOD, ///< (signed) a % b
DSGA_OP_UDIV, // (unsigned) a / b DSGA_OP_UDIV, ///< (unsigned) a / b
DSGA_OP_UMOD, // (unsigned) a & b DSGA_OP_UMOD, ///< (unsigned) a & b
DSGA_OP_MUL, // a * b DSGA_OP_MUL, ///< a * b
DSGA_OP_AND, // a & b DSGA_OP_AND, ///< a & b
DSGA_OP_OR, // a | b DSGA_OP_OR, ///< a | b
DSGA_OP_XOR, // a ^ b DSGA_OP_XOR, ///< a ^ b
}; };
@ -89,7 +91,7 @@ struct DeterministicSpriteGroup {
DeterministicSpriteGroupAdjust *adjusts; DeterministicSpriteGroupAdjust *adjusts;
DeterministicSpriteGroupRange *ranges; // Dynamically allocated DeterministicSpriteGroupRange *ranges; // Dynamically allocated
// Dynamically allocated, this is the sole owner /* Dynamically allocated, this is the sole owner */
const SpriteGroup *default_group; const SpriteGroup *default_group;
}; };
@ -99,19 +101,15 @@ enum RandomizedSpriteGroupCompareMode {
}; };
struct RandomizedSpriteGroup { struct RandomizedSpriteGroup {
// Take this object: VarSpriteGroupScope var_scope; ///< Take this object:
VarSpriteGroupScope var_scope;
// Check for these triggers: RandomizedSpriteGroupCompareMode cmp_mode; ///< Check for these triggers:
RandomizedSpriteGroupCompareMode cmp_mode;
byte triggers; byte triggers;
// Look for this in the per-object randomized bitmask: byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
byte lowest_randbit; byte num_groups; ///< must be power of 2
byte num_groups; // must be power of 2
// Take the group with appropriate index: const SpriteGroup **groups; ///< Take the group with appropriate index:
const SpriteGroup **groups;
}; };
@ -130,7 +128,7 @@ struct ResultSpriteGroup {
}; };
struct TileLayoutSpriteGroup { struct TileLayoutSpriteGroup {
byte num_sprites; /* Number of sprites in the spriteset, used for loading stages */ byte num_sprites; ///< Number of sprites in the spriteset, used for loading stages
struct DrawTileSprites *dts; struct DrawTileSprites *dts;
}; };

@ -43,7 +43,7 @@ void ResetStationClasses()
station_classes[i].spec = NULL; station_classes[i].spec = NULL;
} }
// Set up initial data /* Set up initial data */
station_classes[0].id = 'DFLT'; station_classes[0].id = 'DFLT';
station_classes[0].name = STR_STAT_CLASS_DFLT; station_classes[0].name = STR_STAT_CLASS_DFLT;
station_classes[0].stations = 1; station_classes[0].stations = 1;
@ -66,10 +66,10 @@ StationClassID AllocateStationClass(uint32 cls)
{ {
for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) { for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
if (station_classes[i].id == cls) { if (station_classes[i].id == cls) {
// ClassID is already allocated, so reuse it. /* ClassID is already allocated, so reuse it. */
return i; return i;
} else if (station_classes[i].id == 0) { } else if (station_classes[i].id == 0) {
// This class is empty, so allocate it to the ClassID. /* This class is empty, so allocate it to the ClassID. */
station_classes[i].id = cls; station_classes[i].id = cls;
return i; return i;
} }
@ -168,8 +168,8 @@ const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station)
if (station < station_classes[sclass].stations) if (station < station_classes[sclass].stations)
return station_classes[sclass].spec[station]; return station_classes[sclass].spec[station];
// If the custom station isn't defined any more, then the GRF file /* If the custom station isn't defined any more, then the GRF file
// probably was not loaded. * probably was not loaded. */
return NULL; return NULL;
} }
@ -355,11 +355,11 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by
case 0x41: case 0x41:
case 0x46: case 0x46:
case 0x47: case 0x47:
case 0x49: return 0x2110000; /* Platforms, tracks & position */ case 0x49: return 0x2110000; // Platforms, tracks & position
case 0x42: return 0; /* Rail type (XXX Get current type from GUI?) */ case 0x42: return 0; // Rail type (XXX Get current type from GUI?)
case 0x43: return _current_player; /* Station owner */ case 0x43: return _current_player; // Station owner
case 0x44: return 2; /* PBS status */ case 0x44: return 2; // PBS status
case 0xFA: return max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0); /* Build date */ case 0xFA: return max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0); // Build date
} }
*available = false; *available = false;
@ -370,16 +370,16 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by
/* Calculated station variables */ /* Calculated station variables */
case 0x40: return GetPlatformInfoHelper(tile, false, false, false); case 0x40: return GetPlatformInfoHelper(tile, false, false, false);
case 0x41: return GetPlatformInfoHelper(tile, true, false, false); case 0x41: return GetPlatformInfoHelper(tile, true, false, false);
case 0x42: /* Terrain and rail type */ case 0x42: // Terrain and rail type
return ((_opt.landscape == LT_HILLY && GetTileZ(tile) > GetSnowLine()) ? 4 : 0) | return ((_opt.landscape == LT_HILLY && GetTileZ(tile) > GetSnowLine()) ? 4 : 0) |
(_opt.landscape == LT_DESERT ? GetTropicZone(tile) : 0) | (_opt.landscape == LT_DESERT ? GetTropicZone(tile) : 0) |
(GetRailType(tile) << 8); (GetRailType(tile) << 8);
case 0x43: return st->owner; /* Station owner */ case 0x43: return st->owner; // Station owner
case 0x44: return 2; /* PBS status */ case 0x44: return 2; // PBS status
case 0x45: return GetRailContinuationInfo(tile); case 0x45: return GetRailContinuationInfo(tile);
case 0x46: return GetPlatformInfoHelper(tile, false, false, true); case 0x46: return GetPlatformInfoHelper(tile, false, false, true);
case 0x47: return GetPlatformInfoHelper(tile, true, false, true); case 0x47: return GetPlatformInfoHelper(tile, true, false, true);
case 0x48: { /* Accepted cargo types */ case 0x48: { // Accepted cargo types
CargoID cargo_type; CargoID cargo_type;
uint32 value = 0; uint32 value = 0;
@ -557,7 +557,7 @@ SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Sta
ResolverObject object; ResolverObject object;
NewStationResolver(&object, statspec, st, tile); NewStationResolver(&object, statspec, st, tile);
object.callback_param1 = 1; /* Indicate we are resolving the ground sprite */ object.callback_param1 = 1; // Indicate we are resolving the ground sprite
group = ResolveStation(&object); group = ResolveStation(&object);
if (group == NULL || group->type != SGT_RESULT) return 0; if (group == NULL || group->type != SGT_RESULT) return 0;

@ -1,6 +1,6 @@
/* $Id$ */ /* $Id$ */
/** @file /** @file newgrf_text.cpp
* Implementation of Action 04 "universal holder" structure and functions. * Implementation of Action 04 "universal holder" structure and functions.
* This file implements a linked-lists of strings, * This file implements a linked-lists of strings,
* holding everything that the newgrf action 04 will send over to OpenTTD. * holding everything that the newgrf action 04 will send over to OpenTTD.
@ -122,7 +122,7 @@ const iso_grf iso_codes[] = {
{"sv_SE", GRFLX_SWEDISH}, {"sv_SE", GRFLX_SWEDISH},
{"tr_TR", GRFLX_TURKISH}, {"tr_TR", GRFLX_TURKISH},
{"uk_UA", GRFLX_UKRAINIAN}, {"uk_UA", GRFLX_UKRAINIAN},
{"gen", GRFLB_GENERIC} //this is not iso code, but there has to be something... {"gen", GRFLB_GENERIC} ///< this is not iso code, but there has to be something...
}; };
@ -180,12 +180,12 @@ struct GRFTextEntry {
static uint _num_grf_texts = 0; static uint _num_grf_texts = 0;
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3]; static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
static byte _currentLangID = GRFLX_ENGLISH; //by default, english is used. static byte _currentLangID = GRFLX_ENGLISH; ///< by default, english is used.
char *TranslateTTDPatchCodes(const char *str) char *TranslateTTDPatchCodes(const char *str)
{ {
char *tmp = MallocT<char>(strlen(str) * 10 + 1); /* Allocate space to allow for expansion */ char *tmp = MallocT<char>(strlen(str) * 10 + 1); // Allocate space to allow for expansion
char *d = tmp; char *d = tmp;
bool unicode = false; bool unicode = false;
WChar c; WChar c;
@ -198,7 +198,7 @@ char *TranslateTTDPatchCodes(const char *str)
} }
for (;;) { for (;;) {
const char *tmp = str; /* Used for UTF-8 decoding */ const char *tmp = str; // Used for UTF-8 decoding
c = (byte)*str++; c = (byte)*str++;
if (c == 0) break; if (c == 0) break;

@ -2,7 +2,7 @@
#ifndef NEWGRF_TEXT_H #ifndef NEWGRF_TEXT_H
#define NEWGRF_TEXT_H #define NEWGRF_TEXT_H
/** @file /** @file newgrf_text.h
* Header of Action 04 "universal holder" structure and functions * Header of Action 04 "universal holder" structure and functions
*/ */

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file news.h */
#ifndef NEWS_H #ifndef NEWS_H
#define NEWS_H #define NEWS_H

@ -64,14 +64,14 @@ StringID GetNewsStringNewVehicleAvail(const NewsItem *ni);
StringID GetNewsStringBankrupcy(const NewsItem *ni); StringID GetNewsStringBankrupcy(const NewsItem *ni);
static DrawNewsCallbackProc * const _draw_news_callback[] = { static DrawNewsCallbackProc * const _draw_news_callback[] = {
DrawNewsNewVehicleAvail, /* DNC_VEHICLEAVAIL */ DrawNewsNewVehicleAvail, //< DNC_VEHICLEAVAIL
DrawNewsBankrupcy, /* DNC_BANKRUPCY */ DrawNewsBankrupcy, //< DNC_BANKRUPCY
}; };
extern GetNewsStringCallbackProc * const _get_news_string_callback[]; extern GetNewsStringCallbackProc * const _get_news_string_callback[];
GetNewsStringCallbackProc * const _get_news_string_callback[] = { GetNewsStringCallbackProc * const _get_news_string_callback[] = {
GetNewsStringNewVehicleAvail, /* DNC_VEHICLEAVAIL */ GetNewsStringNewVehicleAvail, ///< DNC_VEHICLEAVAIL
GetNewsStringBankrupcy, /* DNC_BANKRUPCY */ GetNewsStringBankrupcy, ///< DNC_BANKRUPCY
}; };
void InitNewsItemStructs() void InitNewsItemStructs()
@ -104,7 +104,7 @@ void DrawNewsBorder(const Window *w)
static void NewsWindowProc(Window *w, WindowEvent *e) static void NewsWindowProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
case WE_CREATE: { /* If chatbar is open at creation time, we need to go above it */ case WE_CREATE: { // If chatbar is open at creation time, we need to go above it
const Window *w1 = FindWindowById(WC_SEND_NETWORK_MSG, 0); const Window *w1 = FindWindowById(WC_SEND_NETWORK_MSG, 0);
w->message.msg = (w1 != NULL) ? w1->height : 0; w->message.msg = (w1 != NULL) ? w1->height : 0;
} break; } break;
@ -189,20 +189,20 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
case WE_KEYPRESS: case WE_KEYPRESS:
if (e->we.keypress.keycode == WKC_SPACE) { if (e->we.keypress.keycode == WKC_SPACE) {
// Don't continue. /* Don't continue. */
e->we.keypress.cont = false; e->we.keypress.cont = false;
DeleteWindow(w); DeleteWindow(w);
} }
break; break;
case WE_MESSAGE: /* The chatbar has notified us that is was either created or closed */ case WE_MESSAGE: // The chatbar has notified us that is was either created or closed
switch (e->we.message.msg) { switch (e->we.message.msg) {
case WE_CREATE: w->message.msg = e->we.message.wparam; break; case WE_CREATE: w->message.msg = e->we.message.wparam; break;
case WE_DESTROY: w->message.msg = 0; break; case WE_DESTROY: w->message.msg = 0; break;
} }
break; break;
case WE_TICK: { /* Scroll up newsmessages from the bottom in steps of 4 pixels */ case WE_TICK: { // Scroll up newsmessages from the bottom in steps of 4 pixels
int diff; int diff;
int y = max(w->top - 4, _screen.height - w->height - 12 - w->message.msg); int y = max(w->top - 4, _screen.height - w->height - 12 - w->message.msg);
if (y == w->top) return; if (y == w->top) return;
@ -260,7 +260,7 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
if (_game_mode == GM_MENU) return; if (_game_mode == GM_MENU) return;
// check the rare case that the oldest (to be overwritten) news item is open /* check the rare case that the oldest (to be overwritten) news item is open */
if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news))
MoveToNextItem(); MoveToNextItem();
@ -281,7 +281,8 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
/*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d", /*DEBUG(misc, 0, "+cur %3d, old %2d, lat %3d, for %3d, tot %2d",
_current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/ _current_news, _oldest_news, _latest_news, _forced_news, _total_news);*/
{ /* Add news to _latest_news */ /* Add news to _latest_news */
{
Window *w; Window *w;
NewsItem *ni = &_news_items[_latest_news]; NewsItem *ni = &_news_items[_latest_news];
memset(ni, 0, sizeof(*ni)); memset(ni, 0, sizeof(*ni));
@ -290,7 +291,7 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
ni->display_mode = (byte)flags; ni->display_mode = (byte)flags;
ni->flags = (byte)(flags >> 8); ni->flags = (byte)(flags >> 8);
// show this news message in color? /* show this news message in color? */
if (_cur_year >= _patches.colored_news_year) ni->flags |= NF_INCOLOR; if (_cur_year >= _patches.colored_news_year) ni->flags |= NF_INCOLOR;
ni->type = (byte)(flags >> 16); ni->type = (byte)(flags >> 16);
@ -405,7 +406,7 @@ static inline void SetNewsDisplayValue(byte item, byte val)
SB(_news_display_opt, item * 2, 2, val); SB(_news_display_opt, item * 2, 2, val);
} }
// open up an own newspaper window for the news item /* open up an own newspaper window for the news item */
static void ShowNewspaper(NewsItem *ni) static void ShowNewspaper(NewsItem *ni)
{ {
Window *w; Window *w;
@ -455,7 +456,7 @@ static void ShowNewspaper(NewsItem *ni)
w->flags4 |= WF_DISABLE_VP_SCROLL; w->flags4 |= WF_DISABLE_VP_SCROLL;
} }
// show news item in the ticker /* show news item in the ticker */
static void ShowTicker(const NewsItem *ni) static void ShowTicker(const NewsItem *ni)
{ {
Window *w; Window *w;
@ -468,8 +469,8 @@ static void ShowTicker(const NewsItem *ni)
} }
// Are we ready to show another news item? /** Are we ready to show another news item?
// Only if nothing is in the newsticker and no newspaper is displayed * Only if nothing is in the newsticker and no newspaper is displayed */
static bool ReadyForNextItem() static bool ReadyForNextItem()
{ {
const Window *w; const Window *w;
@ -479,15 +480,15 @@ static bool ReadyForNextItem()
if (item >= MAX_NEWS) return true; if (item >= MAX_NEWS) return true;
ni = &_news_items[item]; ni = &_news_items[item];
// Ticker message /* Ticker message
// Check if the status bar message is still being displayed? * Check if the status bar message is still being displayed? */
w = FindWindowById(WC_STATUS_BAR, 0); w = FindWindowById(WC_STATUS_BAR, 0);
if (w != NULL && WP(w, const def_d).data_1 > -1280) return false; if (w != NULL && WP(w, const def_d).data_1 > -1280) return false;
// Newspaper message, decrement duration counter /* Newspaper message, decrement duration counter */
if (ni->duration != 0) ni->duration--; if (ni->duration != 0) ni->duration--;
// neither newsticker nor newspaper are running /* neither newsticker nor newspaper are running */
return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL); return (ni->duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
} }
@ -496,18 +497,18 @@ static void MoveToNextItem()
DeleteWindowById(WC_NEWS_WINDOW, 0); DeleteWindowById(WC_NEWS_WINDOW, 0);
_forced_news = INVALID_NEWS; _forced_news = INVALID_NEWS;
// if we're not at the last item, then move on /* if we're not at the last item, then move on */
if (_current_news != _latest_news) { if (_current_news != _latest_news) {
NewsItem *ni; NewsItem *ni;
_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_current_news); _current_news = (_current_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_current_news);
ni = &_news_items[_current_news]; ni = &_news_items[_current_news];
// check the date, don't show too old items /* check the date, don't show too old items */
if (_date - _news_items_age[ni->type] > ni->date) return; if (_date - _news_items_age[ni->type] > ni->date) return;
switch (GetNewsDisplayValue(ni->type)) { switch (GetNewsDisplayValue(ni->type)) {
case 0: { /* Off - show nothing only a small reminder in the status bar */ case 0: { // Off - show nothing only a small reminder in the status bar
Window *w = FindWindowById(WC_STATUS_BAR, 0); Window *w = FindWindowById(WC_STATUS_BAR, 0);
if (w != NULL) { if (w != NULL) {
@ -517,14 +518,14 @@ static void MoveToNextItem()
break; break;
} }
case 1: /* Summary - show ticker, but if forced big, cascade to full */ case 1: // Summary - show ticker, but if forced big, cascade to full
if (!(ni->flags & NF_FORCE_BIG)) { if (!(ni->flags & NF_FORCE_BIG)) {
ShowTicker(ni); ShowTicker(ni);
break; break;
} }
/* Fallthrough */ /* Fallthrough */
case 2: /* Full - show newspaper*/ case 2: // Full - show newspaper
ShowNewspaper(ni); ShowNewspaper(ni);
break; break;
} }
@ -533,7 +534,7 @@ static void MoveToNextItem()
void NewsLoop() void NewsLoop()
{ {
// no news item yet /* no news item yet */
if (_total_news == 0) return; if (_total_news == 0) return;
if (ReadyForNextItem()) MoveToNextItem(); if (ReadyForNextItem()) MoveToNextItem();
@ -544,10 +545,10 @@ static void ShowNewsMessage(NewsID i)
{ {
if (_total_news == 0) return; if (_total_news == 0) return;
// Delete the news window /* Delete the news window */
DeleteWindowById(WC_NEWS_WINDOW, 0); DeleteWindowById(WC_NEWS_WINDOW, 0);
// setup forced news item /* setup forced news item */
_forced_news = i; _forced_news = i;
if (_forced_news != INVALID_NEWS) { if (_forced_news != INVALID_NEWS) {
@ -649,7 +650,7 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
show = min(_total_news, w->vscroll.cap); show = min(_total_news, w->vscroll.cap);
for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) { for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
// get news in correct order /* get news in correct order */
const NewsItem *ni = &_news_items[getNews(p)]; const NewsItem *ni = &_news_items[getNews(p)];
SetDParam(0, ni->date); SetDParam(0, ni->date);

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file npf.cpp */
#include "stdafx.h" #include "stdafx.h"
#include "openttd.h" #include "openttd.h"
#include "bridge_map.h" #include "bridge_map.h"
@ -99,14 +101,14 @@ static TileIndex CalcClosestStationTile(StationID station, TileIndex tile)
uint x; uint x;
uint y; uint y;
// we are going the aim for the x coordinate of the closest corner /* we are going the aim for the x coordinate of the closest corner
// but if we are between those coordinates, we will aim for our own x coordinate * but if we are between those coordinates, we will aim for our own x coordinate */
x = clamp(TileX(tile), minx, maxx); x = clamp(TileX(tile), minx, maxx);
// same for y coordinate, see above comment /* same for y coordinate, see above comment */
y = clamp(TileY(tile), miny, maxy); y = clamp(TileY(tile), miny, maxy);
// return the tile of our target coordinates /* return the tile of our target coordinates */
return TileXY(x, y); return TileXY(x, y);
} }
@ -121,7 +123,7 @@ static int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, Open
TileIndex to = fstd->dest_coords; TileIndex to = fstd->dest_coords;
uint dist; uint dist;
// for train-stations, we are going to aim for the closest station tile /* for train-stations, we are going to aim for the closest station tile */
if (as->user_data[NPF_TYPE] == TRANSPORT_RAIL && fstd->station_index != INVALID_STATION) if (as->user_data[NPF_TYPE] == TRANSPORT_RAIL && fstd->station_index != INVALID_STATION)
to = CalcClosestStationTile(fstd->station_index, from); to = CalcClosestStationTile(fstd->station_index, from);
@ -173,7 +175,7 @@ static uint NPFTunnelCost(AyStarNode* current)
FindLengthOfTunnelResult flotr; FindLengthOfTunnelResult flotr;
flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir)); flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir));
return flotr.length * NPF_TILE_LENGTH; return flotr.length * NPF_TILE_LENGTH;
//TODO: Penalty for tunnels? /* @todo: Penalty for tunnels? */
} else { } else {
/* We are entering the tunnel, the enter tile is just a /* We are entering the tunnel, the enter tile is just a
* straight track */ * straight track */
@ -244,19 +246,19 @@ static void NPFMarkTile(TileIndex tile)
static int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) static int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent)
{ {
//TileIndex tile = current->tile; /* TileIndex tile = current->tile; */
int32 cost = 0; int32 cost = 0;
Trackdir trackdir = (Trackdir)current->direction; Trackdir trackdir = (Trackdir)current->direction;
cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */ cost = _trackdir_length[trackdir]; // Should be different for diagonal tracks
if (IsBuoyTile(current->tile) && IsDiagonalTrackdir(trackdir)) if (IsBuoyTile(current->tile) && IsDiagonalTrackdir(trackdir))
cost += _patches.npf_buoy_penalty; /* A small penalty for going over buoys */ cost += _patches.npf_buoy_penalty; // A small penalty for going over buoys
if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction))
cost += _patches.npf_water_curve_penalty; cost += _patches.npf_water_curve_penalty;
/* TODO More penalties? */ /* @todo More penalties? */
return cost; return cost;
} }
@ -385,8 +387,8 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Check for turns */ /* Check for turns */
if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction))
cost += _patches.npf_rail_curve_penalty; cost += _patches.npf_rail_curve_penalty;
//TODO, with realistic acceleration, also the amount of straight track between /*TODO, with realistic acceleration, also the amount of straight track between
// curves should be taken into account, as this affects the speed limit. * curves should be taken into account, as this affects the speed limit. */
/* Check for reverse in depot */ /* Check for reverse in depot */
if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) { if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) {
@ -484,7 +486,7 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
break; break;
} }
return true; /* no need to check */ return true; // no need to check
} }
@ -544,7 +546,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
/* Find out the exit direction first */ /* Find out the exit direction first */
if (IsRoadStopTile(src_tile)) { if (IsRoadStopTile(src_tile)) {
exitdir = GetRoadStopDir(src_tile); exitdir = GetRoadStopDir(src_tile);
} else { /* Train or road depot */ } else { // Train or road depot
exitdir = GetDepotDirection(src_tile, type); exitdir = GetDepotDirection(src_tile, type);
} }
@ -610,7 +612,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
DiagDirection exitdir; DiagDirection exitdir;
if (IsRoadStopTile(dst_tile)) { if (IsRoadStopTile(dst_tile)) {
exitdir = GetRoadStopDir(dst_tile); exitdir = GetRoadStopDir(dst_tile);
} else { /* Road or train depot */ } else { // Road or train depot
exitdir = GetDepotDirection(dst_tile, type); exitdir = GetDepotDirection(dst_tile, type);
} }
/* Find the trackdirs that are available for a depot or station with this /* Find the trackdirs that are available for a depot or station with this
@ -640,7 +642,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
/* Check for oneway signal against us */ /* Check for oneway signal against us */
if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TILE_SIGNALS) { if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TILE_SIGNALS) {
if (HasSignalOnTrackdir(dst_tile, ReverseTrackdir(dst_trackdir)) && !HasSignalOnTrackdir(dst_tile, dst_trackdir)) if (HasSignalOnTrackdir(dst_tile, ReverseTrackdir(dst_trackdir)) && !HasSignalOnTrackdir(dst_tile, dst_trackdir))
// if one way signal not pointing towards us, stop going in this direction. /* if one way signal not pointing towards us, stop going in this direction. */
break; break;
} }
{ {

@ -1,5 +1,7 @@
/* $Id$ */ /* $Id$ */
/** @file npf.h */
#ifndef NPF_H #ifndef NPF_H
#define NPF_H #define NPF_H
@ -9,9 +11,9 @@
#include "vehicle.h" #include "vehicle.h"
#include "tile.h" #include "tile.h"
//mowing grass /* mowing grass */
enum { enum {
NPF_HASH_BITS = 12, /* The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value. */ NPF_HASH_BITS = 12, ///< The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value.
/* Do no change below values */ /* Do no change below values */
NPF_HASH_SIZE = 1 << NPF_HASH_BITS, NPF_HASH_SIZE = 1 << NPF_HASH_BITS,
NPF_HASH_HALFBITS = NPF_HASH_BITS / 2, NPF_HASH_HALFBITS = NPF_HASH_BITS / 2,
@ -35,33 +37,38 @@ enum {
NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH
}; };
struct NPFFindStationOrTileData { /* Meant to be stored in AyStar.targetdata */ /* Meant to be stored in AyStar.targetdata */
TileIndex dest_coords; /* An indication of where the station is, for heuristic purposes, or the target tile */ struct NPFFindStationOrTileData {
StationID station_index; /* station index we're heading for, or INVALID_STATION when we're heading for a tile */ TileIndex dest_coords; ///< An indication of where the station is, for heuristic purposes, or the target tile
StationID station_index; ///< station index we're heading for, or INVALID_STATION when we're heading for a tile
}; };
enum { /* Indices into AyStar.userdata[] */ /* Indices into AyStar.userdata[] */
NPF_TYPE = 0, /* Contains a TransportTypes value */ enum {
NPF_OWNER, /* Contains an Owner value */ NPF_TYPE = 0, ///< Contains a TransportTypes value
NPF_RAILTYPES, /* Contains a bitmask the compatible RailTypes of the engine when NPF_TYPE == TRANSPORT_RAIL. Unused otherwise. */ NPF_OWNER, ///< Contains an Owner value
NPF_RAILTYPES, ///< Contains a bitmask the compatible RailTypes of the engine when NPF_TYPE == TRANSPORT_RAIL. Unused otherwise.
}; };
enum { /* Indices into AyStarNode.userdata[] */ /* Indices into AyStarNode.userdata[] */
NPF_TRACKDIR_CHOICE = 0, /* The trackdir chosen to get here */ enum {
NPF_TRACKDIR_CHOICE = 0, ///< The trackdir chosen to get here
NPF_NODE_FLAGS, NPF_NODE_FLAGS,
}; };
enum NPFNodeFlag { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */ /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */
NPF_FLAG_SEEN_SIGNAL, /* Used to mark that a signal was seen on the way, for rail only */ enum NPFNodeFlag {
NPF_FLAG_REVERSE, /* Used to mark that this node was reached from the second start node, if applicable */ NPF_FLAG_SEEN_SIGNAL, ///< Used to mark that a signal was seen on the way, for rail only
NPF_FLAG_LAST_SIGNAL_RED, /* Used to mark that the last signal on this path was red */ NPF_FLAG_REVERSE, ///< Used to mark that this node was reached from the second start node, if applicable
NPF_FLAG_LAST_SIGNAL_RED, ///< Used to mark that the last signal on this path was red
}; };
struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */ /* Meant to be stored in AyStar.userpath */
uint best_bird_dist; /* The best heuristic found. Is 0 if the target was found */ struct NPFFoundTargetData {
uint best_path_dist; /* The shortest path. Is (uint)-1 if no path is found */ uint best_bird_dist; ///< The best heuristic found. Is 0 if the target was found
Trackdir best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */ uint best_path_dist; ///< The shortest path. Is (uint)-1 if no path is found
AyStarNode node; /* The node within the target the search led us to */ Trackdir best_trackdir; ///< The trackdir that leads to the shortest path/closest birds dist
AyStarNode node; ///< The node within the target the search led us to
}; };
/* These functions below are _not_ re-entrant, in favor of speed! */ /* These functions below are _not_ re-entrant, in favor of speed! */

Loading…
Cancel
Save