Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for wildlife overspawning #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ bool game::do_turn()
int group = valid_group((mon_id)(z[i].type->id), levx, levy);
if (group != -1) {
cur_om.zg[group].population++;
if (cur_om.zg[group].population / pow(cur_om.zg[group].radius, 2.0) > 5)
if (cur_om.zg[group].population / pow(cur_om.zg[group].radius, 2.0) > 5 &&
!cur_om.zg[group].diffuse)
cur_om.zg[group].radius++;
}
}
Expand Down Expand Up @@ -1389,10 +1390,6 @@ input_ret game::get_input(int timeout_ms)
use_item();
break;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These four lines shouldn't be nixed; …

case ACTION_USE_WIELDED:
use_wielded_item();
break;

case ACTION_WEAR:
wear();
break;
Expand Down Expand Up @@ -3344,7 +3341,8 @@ void game::monmove()
int group = valid_group((mon_id)(z[i].type->id), levx, levy);
if (group != -1) {
cur_om.zg[group].population++;
if (cur_om.zg[group].population / pow(cur_om.zg[group].radius, 2.0) > 5)
if (cur_om.zg[group].population / pow(cur_om.zg[group].radius, 2.0) > 5 &&
!cur_om.zg[group].diffuse )
cur_om.zg[group].radius++;
} else if (mt_to_mc((mon_id)(z[i].type->id)) != mcat_null) {
cur_om.zg.push_back(mongroup(mt_to_mc((mon_id)(z[i].type->id)),
Expand Down Expand Up @@ -4117,11 +4115,6 @@ void game::use_item()
u.use(this, ch);
}

void game::use_wielded_item()
{
u.use_wielded(this);
}

bool game::pl_choose_vehicle (int &x, int &y)
{
refresh_all();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And nor should these 5.

Expand Down Expand Up @@ -7139,7 +7132,8 @@ void game::update_map(int &x, int &y)
group = valid_group((mon_id)(z[i].type->id), levx + shiftx, levy + shifty);
if (group != -1) {
cur_om.zg[group].population++;
if (cur_om.zg[group].population / pow(cur_om.zg[group].radius, 2.0) > 5)
if (cur_om.zg[group].population / pow(cur_om.zg[group].radius, 2.0) > 5 &&
!cur_om.zg[group].diffuse)
cur_om.zg[group].radius++;
}
/* Removing adding new groups for now. Haha!
Expand Down Expand Up @@ -7439,14 +7433,18 @@ void game::spawn_mon(int shiftx, int shifty)
if (dist <= rad) {
// (The area of the group's territory) in (population/square at this range)
// chance of adding one monster; cap at the population OR 16
while (long((1.0 - double(dist / rad)) * pop) > rng(0, pow(rad, 2.0)) &&
while ( (cur_om.zg[i].diffuse ?
long( pop) :
long((1.0 - double(dist / rad)) * pop) )
> rng(0, pow(rad, 2.0)) &&
rng(0, MAPSIZE * 4) > group && group < pop && group < MAPSIZE * 3)
group++;

cur_om.zg[i].population -= group;
// Reduce group radius proportionally to remaining
// population to maintain a minimal population density.
if (cur_om.zg[i].population / pow(cur_om.zg[i].radius, 2.0) < 1.0)
if (cur_om.zg[i].population / pow(cur_om.zg[i].radius, 2.0) < 1.0 &&
!cur_om.zg[i].diffuse)
cur_om.zg[i].radius--;

if (group > 0) // If we spawned some zombies, advance the timer
Expand Down Expand Up @@ -7552,7 +7550,8 @@ int game::valid_group(mon_id type, int x, int y)
// If there's a group that's ALMOST big enough, expand that group's radius
// by one and absorb into that group.
int semi = rng(0, semi_valid.size() - 1);
cur_om.zg[semi_valid[semi]].radius++;
if (!cur_om.zg[semi_valid[semi]].diffuse)
cur_om.zg[semi_valid[semi]].radius++;
return semi_valid[semi];
}
}
Expand Down
2 changes: 2 additions & 0 deletions mongroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct mongroup {
unsigned char radius;
unsigned int population;
bool dying;
bool diffuse; // group size ind. of dist. from center and radius invariant
mongroup(moncat_id ptype, int pposx, int pposy, unsigned char prad,
unsigned int ppop) {
type = ptype;
Expand All @@ -42,6 +43,7 @@ struct mongroup {
radius = prad;
population = ppop;
dying = false;
diffuse = false;
}
bool is_safe() { return moncat_is_safe(type); };
};
Expand Down
14 changes: 10 additions & 4 deletions overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2280,15 +2280,19 @@ void overmap::place_mongroups()
zg.push_back(
mongroup(mcat_forest, 0, OMAPY, OMAPY,
rng(2000, 12000)));
zg.back().diffuse = true;
zg.push_back(
mongroup(mcat_forest, 0, OMAPY * 2 - 1, OMAPY,
rng(2000, 12000)));
zg.back().diffuse = true;
zg.push_back(
mongroup(mcat_forest, OMAPX, 0, OMAPX,
rng(2000, 12000)));
zg.back().diffuse = true;
zg.push_back(
mongroup(mcat_forest, OMAPX * 2 - 1, 0, OMAPX,
rng(2000, 12000)));
zg.back().diffuse = true;
}

void overmap::place_radios()
Expand Down Expand Up @@ -2336,7 +2340,8 @@ void overmap::save(std::string name, int x, int y, int z)
fout << std::endl;
for (int i = 0; i < zg.size(); i++)
fout << "Z " << zg[i].type << " " << zg[i].posx << " " << zg[i].posy << " " <<
int(zg[i].radius) << " " << zg[i].population << std::endl;
int(zg[i].radius) << " " << zg[i].population << " " << zg[i].diffuse <<
std::endl;
for (int i = 0; i < cities.size(); i++)
fout << "t " << cities[i].x << " " << cities[i].y << " " << cities[i].s <<
std::endl;
Expand All @@ -2358,7 +2363,7 @@ void overmap::open(game *g, int x, int y, int z)
std::stringstream plrfilename, terfilename;
std::ifstream fin;
char datatype;
int ct, cx, cy, cs, cp;
int ct, cx, cy, cs, cp, cd;
city tmp;
std::vector<item> npc_inventory;

Expand All @@ -2381,9 +2386,10 @@ void overmap::open(game *g, int x, int y, int z)
}
}
while (fin >> datatype) {
if (datatype == 'Z') { // Monster group
fin >> ct >> cx >> cy >> cs >> cp;
if (datatype == 'Z') { // Monster group
fin >> ct >> cx >> cy >> cs >> cp >> cd;
zg.push_back(mongroup(moncat_id(ct), cx, cy, cs, cp));
zg.back().diffuse = cd;
nummg++;
} else if (datatype == 't') { // City
fin >> cx >> cy >> cs;
Expand Down