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

misc fixes #26

Merged
merged 5 commits into from
Jan 30, 2013
Merged
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
17 changes: 9 additions & 8 deletions event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ void event::actualize(game *g)

case EVENT_TEMPLE_FLOOD: {
bool flooded = false;
map copy;

ter_id flood_buf[SEEX*MAPSIZE][SEEY*MAPSIZE];
for (int x = 0; x < SEEX * MAPSIZE; x++) {
for (int y = 0; y < SEEY * MAPSIZE; y++)
copy.ter(x, y) = g->m.ter(x, y);
flood_buf[x][y] = g->m.ter(x, y);
}
for (int x = 0; x < SEEX * MAPSIZE; x++) {
for (int y = 0; y < SEEY * MAPSIZE; y++) {
Expand All @@ -151,7 +152,7 @@ void event::actualize(game *g)
}
}
if (deepen) {
copy.ter(x, y) = t_water_dp;
flood_buf[x][y] = t_water_dp;
flooded = true;
}
} else if (g->m.ter(x, y) == t_rock_floor) {
Expand All @@ -163,7 +164,7 @@ void event::actualize(game *g)
}
}
if (flood) {
copy.ter(x, y) = t_water_sh;
flood_buf[x][y] = t_water_sh;
flooded = true;
}
}
Expand All @@ -172,18 +173,18 @@ void event::actualize(game *g)
if (!flooded)
return; // We finished flooding the entire chamber!
// Check if we should print a message
if (copy.ter(g->u.posx, g->u.posy) != g->m.ter(g->u.posx, g->u.posy)) {
if (copy.ter(g->u.posx, g->u.posy) == t_water_sh)
if (flood_buf[g->u.posx][g->u.posy] != g->m.ter(g->u.posx, g->u.posy)) {
if (flood_buf[g->u.posx][g->u.posy] == t_water_sh)
g->add_msg("Water quickly floods up to your knees.");
else { // Must be deep water!
g->add_msg("Water fills nearly to the ceiling!");
g->plswim(g->u.posx, g->u.posy);
}
}
// copy is filled with correct tiles; now copy them back to g->m
// flood_buf is filled with correct tiles; now copy them back to g->m
for (int x = 0; x < SEEX * MAPSIZE; x++) {
for (int y = 0; y < SEEY * MAPSIZE; y++)
g->m.ter(x, y) = copy.ter(x, y);
g->m.ter(x, y) = flood_buf[x][y];
}
g->add_event(EVENT_TEMPLE_FLOOD, int(g->turn) + rng(2, 3));
} break;
Expand Down
2 changes: 1 addition & 1 deletion game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7014,7 +7014,7 @@ void game::vertical_move(int movez, bool force)

levz += movez;
u.moves -= 100;
m.veh_cached_parts.clear();
m.clear_vehicle_cache();
m.vehicle_list.clear();
m.load(this, levx, levy);
u.posx = stairx;
Expand Down
22 changes: 21 additions & 1 deletion map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ map::map(std::vector<itype*> *itptr, std::vector<itype_id> (*miptr)[num_itloc],
grid[n] = NULL;
dbg(D_INFO) << "map::map( itptr["<<itptr<<"], miptr["<<miptr<<"], trptr["<<trptr<<"] ): my_MAPSIZE: " << my_MAPSIZE;
veh_in_active_range = true;
memset(veh_exists_at, 0, sizeof(veh_exists_at));
}

map::~map()
Expand Down Expand Up @@ -90,13 +91,16 @@ vehicle* map::veh_at(const int x, const int y, int &part_num)
// This function is called A LOT. Move as much out of here as possible.
if (!veh_in_active_range || !inbounds(x, y))
return NULL; // Out-of-bounds - null vehicle
if(!veh_exists_at[x][y])
return NULL; // cache cache indicates no vehicle. This should optimize a great deal.
std::pair<int,int> point(x,y);
std::map< std::pair<int,int>, std::pair<vehicle*,int> >::iterator it;
if ((it = veh_cached_parts.find(point)) != veh_cached_parts.end())
{
part_num = it->second.second;
return it->second.first;
}
debugmsg ("vehicle part cache cache indacated vehicle not found :/");
return NULL;
}

Expand All @@ -109,8 +113,8 @@ vehicle* map::veh_at(const int x, const int y)

void map::reset_vehicle_cache()
{
clear_vehicle_cache();
// Cache all vehicles
veh_cached_parts.clear();
veh_in_active_range = false;
for( std::set<vehicle*>::iterator veh = vehicle_list.begin(),
it_end = vehicle_list.end(); veh != it_end; ++veh ) {
Expand All @@ -127,6 +131,9 @@ void map::update_vehicle_cache(vehicle * veh, const bool brand_new)
veh_cached_parts.begin(), end = veh_cached_parts.end(), tmp;
while( it != end ) {
if( it->second.first == veh ) {
int x = it->first.first;
int y = it->first.second;
veh_exists_at[x][y] = false;
tmp = it;
++it;
veh_cached_parts.erase( tmp );
Expand All @@ -145,9 +152,22 @@ void map::update_vehicle_cache(vehicle * veh, const bool brand_new)
const int py = gy + it->precalc_dy[0];
veh_cached_parts.insert( std::make_pair( std::make_pair(px,py),
std::make_pair(veh,partid) ));
veh_exists_at[px][py] = true;
}
}

void map::clear_vehicle_cache()
{
std::map< std::pair<int,int>, std::pair<vehicle*,int> >::iterator part;
while( veh_cached_parts.size() ) {
part = veh_cached_parts.begin();
int x = part->first.first;
int y = part->first.second;
veh_exists_at[x][y] = false;
veh_cached_parts.erase(part);
}
}

void map::board_vehicle(game *g, int x, int y, player *p)
{
if (!p) {
Expand Down
2 changes: 2 additions & 0 deletions map.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class map
void unboard_vehicle(game *g, const int x, const int y);//remove player from vehicle at x,y
void update_vehicle_cache(vehicle *, const bool brand_new = false);
void reset_vehicle_cache();
void clear_vehicle_cache();

void destroy_vehicle (vehicle *veh);
// Change vehicle coords and move vehicle's driver along.
Expand Down Expand Up @@ -182,6 +183,7 @@ class map
std::vector <itype*> *itypes;
std::set<vehicle*> vehicle_list;
std::map< std::pair<int,int>, std::pair<vehicle*,int> > veh_cached_parts;
bool veh_exists_at [SEEX * MAPSIZE][SEEY * MAPSIZE];

protected:
void saven(overmap *om, unsigned const int turn, const int x, const int y,
Expand Down
5 changes: 5 additions & 0 deletions mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6689,6 +6689,11 @@ void map::add_spawn(mon_id type, int count, int x, int y, bool friendly,
return;
}
int nonant = int(x / SEEX) + int(y / SEEY) * my_MAPSIZE;
if(!grid[nonant]){
debugmsg("centadodecamonant doesn't exist in grid; within add_spawn(%d, %d, %d, %d)",
type, count, x, y);
return;
}
x %= SEEX;
y %= SEEY;
spawn_point tmp(type, count, x, y, faction_id, mission_id, friendly, name);
Expand Down
3 changes: 2 additions & 1 deletion player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2891,7 +2891,8 @@ void player::suffer(game *g)
}

if (has_trait(PF_WEB_WEAVER) && one_in(3)) {
if (g->m.field_at(posx, posy).type == fd_null)
if (g->m.field_at(posx, posy).type == fd_null ||
g->m.field_at(posx, posy).type == fd_slime)
g->m.add_field(g, posx, posy, fd_web, 1);
else if (g->m.field_at(posx, posy).type == fd_web &&
g->m.field_at(posx, posy).density < 3)
Expand Down
1 change: 1 addition & 0 deletions skill.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <iostream>
#include <stdint.h>


enum skill {
Expand Down