Permalink
Browse files

Multiple fixes. New debug functions. Fungal spires work.

  • Loading branch information...
1 parent ef8e986 commit 401a2c823a5d7fb858a516794e293d0b8bd43f45 @Whales committed Oct 21, 2011
Showing with 385 additions and 119 deletions.
  1. +1 −1 computer.cpp
  2. +28 −28 crafting.cpp
  3. +36 −10 game.cpp
  4. +5 −4 game.h
  5. +22 −2 inventory.cpp
  6. +2 −1 inventory.h
  7. +10 −0 item.cpp
  8. +1 −0 item.h
  9. +0 −4 iuse.cpp
  10. +9 −3 map.cpp
  11. +2 −1 map.h
  12. +2 −2 mapdata.h
  13. +4 −10 melee.cpp
  14. +1 −17 monster.cpp
  15. +1 −2 mtype.h
  16. +4 −4 mtypedef.cpp
  17. +8 −0 npcmove.cpp
  18. +2 −2 output.cpp
  19. +1 −1 overmap.cpp
  20. +7 −2 player.cpp
  21. +1 −1 player.h
  22. +238 −24 wish.cpp
View
@@ -159,7 +159,7 @@ bool computer::hack_attempt(player *p, int Security)
if (Security == -1)
Security = security; // Set to main system security if no value passed
- p->practice(sk_computer, Security * 2);
+ p->practice(sk_computer, 5 + Security * 2);
int player_roll = p->sklevel[sk_computer];
if (p->int_cur < 8 && one_in(2))
player_roll -= rng(0, 8 - p->int_cur);
View
@@ -60,8 +60,8 @@ void game::init_recipes()
RECIPE(itm_molotov, CC_WEAPON, sk_null, sk_null, 0, 500);
COMP(itm_rag, 1, NULL);
- COMP(itm_whiskey, 1, itm_vodka, 1, itm_rum, 1, itm_tequila, 1,
- itm_gasoline, 1, NULL);
+ COMP(itm_whiskey, -1, itm_vodka, -1, itm_rum, -1, itm_tequila, -1,
+ itm_gasoline, -1, NULL);
RECIPE(itm_pipebomb, CC_WEAPON, sk_mechanics, sk_null, 1, 750);
TOOL(itm_hacksaw, -1, NULL);
@@ -626,7 +626,7 @@ void game::craft()
inventory crafting_inv;
crafting_inv.form_from_map(this, point(u.posx, u.posy), PICKUP_RANGE);
- crafting_inv.add_stack(u.inv_dump());
+ crafting_inv += u.inv;
do {
if (redraw) { // When we switch tabs, redraw the header
@@ -731,13 +731,13 @@ Press ? to describe object. Press <ENTER> to attempt to craft object.");
int count = current[line]->components[i][j].count;
itype_id type = current[line]->components[i][j].type;
nc_color compcol = c_red;
- if (itypes[type]->count_by_charges()) {
+ if (itypes[type]->count_by_charges() && count > 0) {
if (crafting_inv.has_charges(type, count))
compcol = c_green;
- } else if (crafting_inv.has_amount(type, count))
+ } else if (crafting_inv.has_amount(type, abs(count)))
compcol = c_green;
std::stringstream dump;
- dump << count << "x " << itypes[type]->name << " ";
+ dump << abs(count) << "x " << itypes[type]->name << " ";
std::string compname = dump.str();
if (xpos + compname.length() >= 80) {
ypos++;
@@ -908,7 +908,7 @@ void game::pick_recipes(std::vector<recipe*> &current,
{
inventory crafting_inv;
crafting_inv.form_from_map(this, point(u.posx, u.posy), PICKUP_RANGE);
- crafting_inv.add_stack(u.inv_dump());
+ crafting_inv += u.inv;
bool have_tool[5], have_comp[5];
@@ -946,15 +946,15 @@ void game::pick_recipes(std::vector<recipe*> &current,
if (current[i]->components[j].size() == 0)
have_comp[j] = true;
else {
- for (int k = 0; k < current[i]->components[j].size(); k++) {
+ for (int k = 0; k < current[i]->components[j].size() && !have_comp[j]; k++){
itype_id type = current[i]->components[j][k].type;
int count = current[i]->components[j][k].count;
- if (itypes[type]->count_by_charges()) {
+ if (itypes[type]->count_by_charges() && count > 0) {
if (crafting_inv.has_charges(type, count)) {
have_comp[j] = true;
k = current[i]->components[j].size();
}
- } else if (crafting_inv.has_amount(type, count)) {
+ } else if (crafting_inv.has_amount(type, abs(count))) {
have_comp[j] = true;
k = current[i]->components[j].size();
}
@@ -990,19 +990,17 @@ void game::complete_craft()
std::vector<component> player_has;
std::vector<component> map_has;
for (int j = 0; j < making.components[i].size(); j++) {
- if (itypes[making.components[i][j].type]->count_by_charges()) {
- if (u.has_charges(making.components[i][j].type,
- making.components[i][j].count))
+ itype_id type = making.components[i][j].type;
+ int count = making.components[i][j].count;
+ if (itypes[type]->count_by_charges() && count > 0) {
+ if (u.has_charges(type, count))
player_has.push_back(making.components[i][j]);
- if (map_inv.has_charges(making.components[i][j].type,
- making.components[i][j].count))
+ if (map_inv.has_charges(type, count))
map_has.push_back(making.components[i][j]);
} else {
- if (u.has_amount(making.components[i][j].type,
- making.components[i][j].count))
+ if (u.has_amount(type, abs(count)))
player_has.push_back(making.components[i][j]);
- if (map_inv.has_amount(making.components[i][j].type,
- making.components[i][j].count))
+ if (map_inv.has_amount(type, abs(count)))
map_has.push_back(making.components[i][j]);
}
}
@@ -1080,21 +1078,22 @@ void game::complete_craft()
for (int i = 0; i < num_lost_player; i++) {
int n = rng(0, player_use.size() - 1);
if (itypes[player_use[n].type]->count_by_charges() &&
- player_use[i].type != itm_gasoline)
+ player_use[n].count > 0)
u.use_charges(player_use[n].type, player_use[n].count);
else
- u.use_amount(player_use[n].type, player_use[n].count);
+ u.use_amount(player_use[n].type, abs(player_use[n].count),
+ (player_use[n].count < 0)); // If true, use container
player_use.erase(player_use.begin() + n);
}
for (int i = 0; i < num_lost_map; i++) {
int n = rng(0, map_use.size() - 1);
if (itypes[map_use[n].type]->count_by_charges() &&
- map_use[i].type != itm_gasoline)
+ map_use[n].count > 0)
m.use_charges(point(u.posx, u.posy), PICKUP_RANGE,
map_use[n].type, map_use[n].count);
else
m.use_amount(point(u.posx, u.posy), PICKUP_RANGE,
- map_use[n].type, map_use[n].count);
+ map_use[n].type, abs(map_use[n].count),(map_use[n].count < 0));
map_use.erase(map_use.begin() + n);
}
@@ -1111,25 +1110,26 @@ void game::complete_craft()
// Use up the items in will_use
for (int i = 0; i < player_use.size(); i++) {
if (itypes[player_use[i].type]->count_by_charges() &&
- player_use[i].type != itm_gasoline)
+ player_use[i].count > 0)
u.use_charges(player_use[i].type, player_use[i].count);
else
- u.use_amount(player_use[i].type, player_use[i].count);
+ u.use_amount(player_use[i].type, abs(player_use[i].count),
+ (player_use[i].count < 0));
}
for (int i = 0; i < map_use.size(); i++) {
if (itypes[map_use[i].type]->count_by_charges() &&
- map_use[i].type != itm_gasoline)
+ map_use[i].count > 0)
m.use_charges(point(u.posx, u.posy), PICKUP_RANGE,
map_use[i].type, map_use[i].count);
else
m.use_amount(point(u.posx, u.posy), PICKUP_RANGE,
- map_use[i].type, map_use[i].count);
+ map_use[i].type, abs(map_use[i].count), (map_use[i].count < 0));
}
// Set up the new item, and pick an inventory letter
int iter = 0;
item newit(itypes[making.result], turn, nextinv);
- if (!newit.count_by_charges())
+ if (!newit.craft_has_charges())
newit.charges = 0;
do {
newit.invlet = nextinv;
View
@@ -1334,16 +1334,19 @@ void game::debug()
"Teleport - Long Range", // 3
"Reveal map", // 4
"Spawn NPC", // 5
- "Check game state...", // 6
- "Cancel", // 7
+ "Spawn Monster", // 6
+ "Check game state...", // 7
+ "Cancel", // 8
NULL);
switch (action) {
case 1:
wish();
break;
+
case 2:
teleport();
break;
+
case 3: {
point tmp = cur_om.choose_point(this);
if (tmp.x != -1) {
@@ -1354,13 +1357,15 @@ void game::debug()
m.load(this, levx, levy);
}
} break;
+
case 4:
debugmsg("%d radio towers", cur_om.radios.size());
for (int i = 0; i < OMAPX; i++) {
for (int j = 0; j < OMAPY; j++)
cur_om.seen(i, j) = true;
}
break;
+
case 5: {
npc temp;
temp.randomize(this);
@@ -1370,7 +1375,12 @@ void game::debug()
temp.posy = u.posy - 4;
active_npc.push_back(temp);
} break;
+
case 6:
+ monster_wish();
+ break;
+
+ case 7:
popup_top("\
Current turn: %d; Next spawn %d.\n\
%d monsters exist.\n\
@@ -3339,7 +3349,7 @@ shape, but with long, twisted, distended limbs.");
m.disarm_trap(this, examx, examy);
}
-void game::look_around()
+point game::look_around()
{
int lx = u.posx, ly = u.posy;
int mx, my, junk;
@@ -3421,7 +3431,10 @@ void game::look_around()
}
wrefresh(w_look);
wrefresh(w_terrain);
- } while (ch != ' ' && ch != KEY_ESCAPE && ch != ';' && ch != '\n');
+ } while (ch != ' ' && ch != KEY_ESCAPE && ch != '\n');
+ if (ch == '\n')
+ return point(lx, ly);
+ return point(-1, -1);
}
// Pick up items at (posx, posy).
@@ -3837,14 +3850,27 @@ bool game::handle_liquid(item &liquid, bool from_ground, bool infinite)
return false;
item *cont = &(u.i_at(ch));
ammotype type = cont->ammo_type();
- if (cont->type->id == itm_null) {
+ if (cont == NULL || cont->is_null()) {
add_msg("Never mind.");
return false;
- } else if (cont->is_tool() &&
- (dynamic_cast<it_tool*>(cont->type))->max_charges > 0 &&
- (dynamic_cast<it_tool*>(cont->type))->ammo == type &&
- (cont->charges == 0 || cont->curammo->id == liquid.type->id)) {
- add_msg("You pour %s into your %s.", ammo_name(type).c_str(),
+ } else if (liquid.is_ammo() && cont->is_tool()) {
+ it_tool* tool = dynamic_cast<it_tool*>(cont->type);
+ ammotype liquid_type = liquid.ammo_type();
+ if (tool->ammo != liquid_type) {
+ add_msg("Your %s won't hold %s.", cont->tname(this).c_str(),
+ liquid.tname(this).c_str());
+ return false;
+ }
+ if (tool->max_charges <= 0 || cont->charges >= tool->max_charges) {
+ add_msg("Your %s can't hold any more %s.", cont->tname(this).c_str(),
+ liquid.tname(this).c_str());
+ return false;
+ }
+ if (cont->charges > 0 && cont->curammo->id != liquid.type->id) {
+ add_msg("You can't mix loads in your %s.", cont->tname(this).c_str());
+ return false;
+ }
+ add_msg("You pour %s into your %s.", liquid.tname(this).c_str(),
cont->tname(this).c_str());
cont->curammo = dynamic_cast<it_ammo*>(liquid.type);
int max_charges = (dynamic_cast<it_tool*>(cont->type))->max_charges;
View
9 game.h
@@ -174,13 +174,14 @@ class game
void init_construction(); // Initializes construction "recipes"
void init_missions(); // Initializes mission templates
- void create_factions(); // Creates new factions (for a new game world)
+ void create_factions(); // Creates new factions (for a new game world)
// Player actions
void wish(); // Cheat by wishing for an item 'Z'
- void plmove(int x, int y); // Standard movement; handles attacks, traps, &c
- void plswim(int x, int y); // Called by plmove. Handles swimming
+ void monster_wish(); // Create a monster
+ void plmove(int x, int y); // Standard movement; handles attacks, traps, &c
+ void plswim(int x, int y); // Called by plmove. Handles swimming
void wait(); // Long wait (player action) '^'
void open(); // Open a door 'o'
void close(); // Close a door 'c'
@@ -196,7 +197,7 @@ class game
void place_construction(constructable con); // See construction.cpp
void complete_construction(); // See construction.cpp
void examine();// Examine nearby terrain 'e'
- void look_around();// Look at nearby terrain ';'
+ point look_around();// Look at nearby terrain ';'
void pickup(int posx, int posy, int min);// Pickup items; ',' or via examine()
// Pick where to put liquid; false if it's left where it was
bool handle_liquid(item &liquid, bool from_ground, bool infinite);
View
@@ -24,6 +24,16 @@ std::vector<item>& inventory::stack_at(int i)
return items[i];
}
+std::vector<item> inventory::as_vector()
+{
+ std::vector<item> ret;
+ for (int i = 0; i < size(); i++) {
+ for (int j = 0; j < stack_at(i).size(); j++)
+ ret.push_back(items[i][j]);
+ }
+ return ret;
+}
+
int inventory::size() const
{
return items.size();
@@ -310,20 +320,30 @@ int inventory::charges_of(itype_id it)
return count;
}
-void inventory::use_amount(itype_id it, int quantity)
+void inventory::use_amount(itype_id it, int quantity, bool use_container)
{
for (int i = 0; i < items.size() && quantity > 0; i++) {
for (int j = 0; j < items[i].size() && quantity > 0; j++) {
// First, check contents
+ bool used_item_contents = false;
for (int k = 0; k < items[i][j].contents.size() && quantity > 0; k++) {
if (items[i][j].contents[k].type->id == it) {
quantity--;
items[i][j].contents.erase(items[i][j].contents.begin() + k);
k--;
+ used_item_contents = true;
}
}
// Now check the item itself
- if (items[i][j].type->id == it) {
+ if (use_container && used_item_contents) {
+ items[i].erase(items[i].begin() + j);
+ j--;
+ if (items[i].empty()) {
+ items.erase(items.begin() + i);
+ i--;
+ j = 0;
+ }
+ } else if (items[i][j].type->id == it) {
quantity--;
items[i].erase(items[i].begin() + j);
j--;
View
@@ -13,6 +13,7 @@ class inventory
public:
item& operator[] (int i);
std::vector<item>& stack_at(int i);
+ std::vector<item> as_vector();
item& front();
item& back();
int size() const;
@@ -51,7 +52,7 @@ class inventory
int amount_of (itype_id it);
int charges_of(itype_id it);
- void use_amount (itype_id it, int quantity);
+ void use_amount (itype_id it, int quantity, bool use_container = false);
void use_charges(itype_id it, int quantity);
bool has_amount (itype_id it, int quantity);
View
@@ -655,6 +655,16 @@ bool item::count_by_charges()
return false;
}
+bool item::craft_has_charges()
+{
+ if (count_by_charges())
+ return true;
+ else if (ammo_type() == AT_NULL)
+ return true;
+
+ return false;
+}
+
int item::weapon_value(int skills[num_skill_types])
{
int my_value = 0;
View
1 item.h
@@ -60,6 +60,7 @@ class item
bool has_flag(item_flag f);
bool goes_bad();
bool count_by_charges();
+ bool craft_has_charges();
bool rotten(game *g);
// Our value as a weapon, given particular skills
View
@@ -1808,10 +1808,6 @@ void iuse::tazer(game *g, player *p, item *it, bool t)
g->add_msg("You attempt to shock the %s, but miss.", z->name().c_str());
return;
}
- if (z->has_flag(MF_SHOCK)) {
- g->add_msg("You shock the %s, but it seems immune!", z->name().c_str());
- return;
- }
g->add_msg("You shock the %s!", z->name().c_str());
int shock = rng(5, 25);
z->moves -= shock * 100;
Oops, something went wrong.

0 comments on commit 401a2c8

Please sign in to comment.