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

construction bugfixes and more build changes #17

Merged
merged 4 commits into from
Jan 22, 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
60 changes: 42 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,41 @@ DEBUG = -g
#DEFINES += -DDEBUG_ENABLE_MAP_GEN
#DEFINES += -DDEBUG_ENABLE_GAME

ODIR = obj
W32ODIR = objwin
DDIR = .deps
VERSION = 0.1

TARGET = cataclysm
W32TARGET = cataclysm.exe
BINDIST_DIR = Cataclysm

ODIR = obj
W32ODIR = objwin
DDIR = .deps

OS = $(shell uname -o)
CXX = $(CROSS)g++

# enable optimizations. slow to build
ifdef ($(RELEASE))
ifdef RELEASE
OTHERS += -O3
DEBUG =
endif

CXXFLAGS = $(WARNINGS) $(DEBUG) $(PROFILE) $(OTHERS)

# is this mingw check even being used anymore?
ifeq ($(OS), Msys)
LDFLAGS = -static -lpdcurses
else
BINDIST_EXTRAS = README data/
BINDIST = cataclysmdda-$(VERSION).tar.gz
W32BINDIST = cataclysmdda-$(VERSION).zip
BINDIST_CMD = tar -czvf $(BINDIST) $(BINDIST_DIR)
W32BINDIST_CMD = zip -r $(W32BINDIST) $(BINDIST_DIR)

# is this section even being used anymore?
# SOMEBODY PLEASE CHECK
#ifeq ($(OS), Msys)
# LDFLAGS = -static -lpdcurses
#else
LDFLAGS = -lncurses
endif
#endif

# Win32 (mingw32?)
ifeq ($(NATIVE), win32)
TARGET = $(W32TARGET)
W32LDFLAGS = -Wl,-stack,12000000,-subsystem,windows
LDFLAGS = -static -lgdi32
ODIR = $(W32ODIR)
endif
# Linux 64-bit
ifeq ($(NATIVE), linux64)
CXXFLAGS += -m64
Expand All @@ -83,11 +86,22 @@ else
CXXFLAGS += -m32
endif
endif
# Win32 (mingw32?)
ifeq ($(NATIVE), win32)
TARGET = $(W32TARGET)
BINDIST = $(W32BINDIST)
BINDIST_CMD = $(W32BINDIST_CMD)
ODIR = $(W32ODIR)
W32LDFLAGS = -Wl,-stack,12000000,-subsystem,windows
LDFLAGS += -static -lgdi32
endif
# MXE cross-compile to win32
ifeq ($(CROSS), i686-pc-mingw32-)
TARGET = $(W32TARGET)
LDFLAGS = -lgdi32
BINDIST = $(W32BINDIST)
BINDIST_CMD = $(W32BINDIST_CMD)
ODIR = $(W32ODIR)
LDFLAGS += -lgdi32
endif

SOURCES = $(wildcard *.cpp)
Expand All @@ -111,6 +125,16 @@ $(ODIR)/%.o: %.cpp
$(CXX) $(DEFINES) $(CXXFLAGS) -c $< -o $@

clean:
rm -f $(TARGET) $(W32TARGET) $(ODIR)/*.o $(W32ODIR)/*.o
rm -f $(TARGET) $(W32TARGET) $(ODIR)/*.o $(W32ODIR)/*.o $(W32BINDIST) \
$(BINDIST)
rm -rf $(BINDIST_DIR)

bindist: $(BINDIST)

$(BINDIST): $(TARGET) $(BINDIST_EXTRAS)
rm -rf $(BINDIST_DIR)
mkdir -p $(BINDIST_DIR)
cp -R $(TARGET) $(BINDIST_EXTRAS) $(BINDIST_DIR)
$(BINDIST_CMD)

-include $(SOURCES:%.cpp=$(DEPDIR)/%.P)
52 changes: 33 additions & 19 deletions construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void game::construction_menu()
// Print the constructions between offset and max (or how many will fit)
for (int i = 0; i < 22 && i + offset < constructions.size(); i++) {
int current = i + offset;
nc_color col = (player_can_build(u, total_inv, constructions[current], 0) ?
nc_color col = (player_can_build(u, total_inv, constructions[current], -1) ?
c_white : c_dkgray);
// Map menu items to hotkey letters, skipping j, k, l, and q.
char hotkey = current + ((current < 9) ? 97 : ((current < 13) ? 100 : 101));
Expand All @@ -289,7 +289,8 @@ void game::construction_menu()
// Print stages and their requirements
int posx = 33, posy = 2;
for (int n = 0; n < current_con->stages.size(); n++) {
nc_color color_stage = (player_can_build(u, total_inv, current_con, n) ?
nc_color color_stage = (player_can_build(u, total_inv, current_con, n,
false, true) ?
c_white : c_dkgray);
mvwprintz(w_con, posy, 31, color_stage, "Stage %d: %s", n + 1,
current_con->stages[n].terrain == t_null? "" : terlist[current_con->stages[n].terrain].name.c_str());
Expand Down Expand Up @@ -395,7 +396,7 @@ void game::construction_menu()
break;
case '\n':
case 'l':
if (player_can_build(u, total_inv, constructions[select], 0)) {
if (player_can_build(u, total_inv, constructions[select], -1)) {
place_construction(constructions[select]);
ch = 'q';
} else {
Expand All @@ -412,8 +413,8 @@ void game::construction_menu()
default:
if (ch < 96 || ch > constructions.size() + 101) break;
// Map menu items to hotkey letters, skipping j, k, l, and q.
char hotkey = ch - ((ch < 105) ? 97 : ((ch < 112) ? 100 : 101));
if (player_can_build(u, total_inv, constructions[hotkey], 0)) {
char hotkey = ch - ((ch < 106) ? 97 : ((ch < 112) ? 100 : 101));
if (player_can_build(u, total_inv, constructions[hotkey], -1)) {
place_construction(constructions[hotkey]);
ch = 'q';
} else {
Expand All @@ -429,8 +430,10 @@ void game::construction_menu()
}

bool game::player_can_build(player &p, inventory inv, constructable* con,
int level, bool cont)
int level, bool cont, bool exact_level)
{
// default behavior: return true if any of the stages up to L can be constr'd
// if exact_level, require that this level be constructable
if (p.sklevel[sk_carpentry] < con->difficulty)
return false;

Expand All @@ -440,20 +443,24 @@ bool game::player_can_build(player &p, inventory inv, constructable* con,
int start = 0;
if (cont)
start = level;

bool can_build_any = false;
for (int i = start; i < con->stages.size() && i <= level; i++) {
construction_stage stage = con->stages[i];
bool has_tool = false;
bool has_component = false;
for (int j = 0; j < 3; j++) {
if (stage.tools[j].size() > 0) {
bool has_tool = false;

for (int k = 0; k < stage.tools[j].size() && !has_tool; k++) {
if (inv.has_amount(stage.tools[j][k], 1))
has_tool = true;
}
if (!has_tool)
return false;
if (!has_tool) // missing one of the tools for this stage
break;
}
if (stage.components[j].size() > 0) {
bool has_component = false;

for (int k = 0; k < stage.components[j].size() && !has_component; k++) {
if (( itypes[stage.components[j][k].type]->is_ammo() &&
inv.has_charges(stage.components[j][k].type,
Expand All @@ -463,12 +470,16 @@ bool game::player_can_build(player &p, inventory inv, constructable* con,
stage.components[j][k].count) ))
has_component = true;
}
if (!has_component)
return false;
if (!has_component) // missing one of the comps for this stage
break;
}
}
}
return true;

} // j in [0,2]
can_build_any = has_component && has_tool;
if (exact_level && (i == level) && (!has_component || !has_tool))
return false;
} // stage[i]
return can_build_any;
}

void game::place_construction(constructable *con)
Expand All @@ -492,14 +503,17 @@ void game::place_construction(constructable *con)

if (place_okay) {
// Make sure we're not trying to continue a construction that we can't finish
int starting_stage = 0, max_stage = 0;
int starting_stage = 0, max_stage = -1;
for (int i = 0; i < con->stages.size(); i++) {
if (m.ter(x, y) == con->stages[i].terrain)
starting_stage = i + 1;
if (player_can_build(u, total_inv, con, i, true))
max_stage = i;
}

for(int i = starting_stage; i < con->stages.size(); i++) {
if (player_can_build(u, total_inv, con, i, true, true))
max_stage = i;
else
break;
}
if (max_stage >= starting_stage) {
valid.push_back(point(x, y));
m.drawsq(w_terrain, u, x, y, true, false);
Expand Down
3 changes: 2 additions & 1 deletion game.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ class game
void complete_disassemble(); // See crafting.cpp
void construction_menu(); // See construction.cpp
bool player_can_build(player &p, inventory inv, constructable* con,
int level = -1, bool cont = false);
int level = -1, bool cont = false,
bool exact_level=false);
void place_construction(constructable *con); // See construction.cpp
void complete_construction(); // See construction.cpp
bool pl_choose_vehicle (int &x, int &y);
Expand Down