Archived
1
0

+ added properties instead of class variables

x removed Typliste (integrated in Einwohner)
This commit is contained in:
2009-01-30 21:57:37 +01:00
parent 422210793e
commit 497fd500d9
9 changed files with 153 additions and 72 deletions
+35 -23
View File
@@ -3,40 +3,49 @@ using System;
namespace vampi
{
class Einwohner : Spielfigur {
public const int F_SEX = 10;
public const int SEX_MALE = 1;
public const int SEX_FEMALE = 2;
public const int F_INFECTED = 11;
private static int count = 0;
public static int Count {
get { return Einwohner.count; }
}
private bool infected = false;
public bool Infected {
get { return this.infected; }
get { return (this.props[F_INFECTED] != 0); }
}
public static int legalSexAge = Settings.humanLegalSexAge;
public static int vampireConversionRate = Settings.humanVampireConversionPercent;
public bool ismale;
public string name;
public Einwohner(Spielfeld sfeld)
: base(sfeld) {
this.typ = Typliste.EINWOHNER;
this.maxAge = Settings.humanMaxAge;
this.age = Program.random.Next(0, Settings.humanMaxInitAge);
this.props[F_TYPE] = TYPE_HUMAN;
this.props[F_MAXAGE] = Settings.humanMaxAge;
this.props[F_AGE] = Program.random.Next(0, Settings.humanMaxInitAge);
Einwohner.count++;
if (Program.random.Next(0, 100) < 85) this.ismale = true; else this.ismale = false;
this.props[F_SEX] = (Program.random.Next(0, 100) < 85)?SEX_MALE:SEX_FEMALE;
if (this.props[F_SEX] == SEX_MALE) {
this.name = Settings.namesMale[Program.random.Next(0, Settings.namesMale.GetLength(0))];
} else {
this.name = Settings.namesFemale[Program.random.Next(0, Settings.namesFemale.GetLength(0))];
}
// Console.WriteLine(this.name+" is born! (" + ((this.ismale)?"m":"f") + ")");
}
public void infect() {
if (this.infected)
return;
this.infected = true;
if (this.age < this.maxAge - Settings.humanInfectedMaxAge) this.age = this.maxAge - Settings.humanInfectedMaxAge;
if (this.Infected)
return;
// Console.WriteLine(this.name+" got infected!");
this.props[F_INFECTED] = 1;
if (this.props[F_AGE] < this.props[F_MAXAGE] - Settings.humanInfectedMaxAge) this.props[F_AGE] = this.props[F_MAXAGE] - Settings.humanInfectedMaxAge;
}
public override void die() {
Einwohner.count--;
if (this.infected) {
if (this.Infected) {
int rvalue = Program.random.Next(0, 100);
if (rvalue <= Einwohner.vampireConversionRate) {
if (rvalue <= Settings.humanVampireConversionPercent) {
new Vampir(this.sfeld);
return;
}
@@ -46,8 +55,11 @@ namespace vampi
public override void runStep() {
base.runStep();
if (this.infected && !Settings.humanInfectedCanReproduceWithNormal) return;
this.tryMate();
}
protected void tryMate() {
if (this.Infected && !Settings.humanInfectedCanReproduceWithNormal) return;
// search for constraints (empty field, partner to mate > 10 yrs)
Spielfeld birthplace = null;
@@ -55,10 +67,11 @@ namespace vampi
for (int i = 1; i <= 8; i++) {
Spielfeld neighbor = this.sfeld.getNachbarfeld(i);
if (neighbor != null && neighbor.Sfigur != null) {
if (neighbor.Sfigur.Typ == Typliste.EINWOHNER) {
if (neighbor.Sfigur.Age >= Einwohner.legalSexAge && (Settings.humanNormalCanReproduceWithInfected || !((Einwohner)neighbor.Sfigur).Infected)) {
if (((Einwohner)neighbor.Sfigur).ismale != this.ismale)
mateFound = true;
if (neighbor.Sfigur.props[F_TYPE] == TYPE_HUMAN) {
if (neighbor.Sfigur.Age >= Settings.humanLegalSexAge && (Settings.humanNormalCanReproduceWithInfected || !((Einwohner)neighbor.Sfigur).Infected)) {
if (neighbor.Sfigur.props[F_SEX] != this.props[F_SEX]) {
mateFound = true;
}
}
}
} else if (neighbor != null && neighbor.Sfigur == null) {
@@ -69,7 +82,6 @@ namespace vampi
if (mateFound && birthplace != null) {
new Einwohner(birthplace);
}
}
}
}//namespace