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

Added function for recrafting the last crafted recipe. #182

Merged
merged 2 commits into from
Mar 11, 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
4 changes: 4 additions & 0 deletions action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ std::string action_ident(action_id act)
return "debug_mode";
case ACTION_NULL:
return "null";
case ACTION_RECRAFT:
return "recraft";
}
return "unknown";
}
Expand Down Expand Up @@ -389,6 +391,8 @@ std::string action_name(action_id act)
return "Toggle Debug Messages";
case ACTION_NULL:
return "No Action";
case ACTION_RECRAFT:
return "Recraft last recipe";
}
return "Someone forgot to name an action.";
}
1 change: 1 addition & 0 deletions action.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ACTION_BIONICS,
// Long-term / special actions
ACTION_WAIT,
ACTION_CRAFT,
ACTION_RECRAFT,
ACTION_CONSTRUCT,
ACTION_DISASSEMBLE,
ACTION_SLEEP,
Expand Down
98 changes: 98 additions & 0 deletions crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,103 @@ RECIPE(itm_boobytrap, CC_MISC, "mechanics", "traps",3,5000, false);
// COMP(itm_battery, 500, itm_plut_cell, 1, NULL);
// COMP(itm_scrap, 30, NULL);
}
void game::recraft()
{
if(u.lastrecipe == NULL)
{
popup("Craft something first");
}
else
{
try_and_make(u.lastrecipe);
}
}
void game::try_and_make(recipe *making)
{
if(can_make(making))
{
if (itypes[(making->result)]->m1 == LIQUID)
{
if (u.has_watertight_container() || u.has_matching_liquid(itypes[making->result]->id)) {
make_craft(making);
} else {
popup("You don't have anything to store that liquid in!");
}
}
else {
make_craft(making);
}
}
else
{
popup("You can't do that!");
}
}
bool game::can_make(recipe *r)
{
inventory crafting_inv = crafting_inventory();
if((r->sk_primary != NULL && u.skillLevel(r->sk_primary) < r->difficulty) || (r->sk_secondary != NULL && u.skillLevel(r->sk_secondary) <= 0))
{
}
// under the assumption that all comp and tool's array contains all the required stuffs at the start of the array

// check all tools
for(int i = 0 ; i < 20 ; i++)
{
// if current tool is null(size 0), assume that there is no more after it.
if(r->tools[i].size()==0)
{
break;
}
bool has_tool = false;
for(int j = 0 ; j < r->tools[i].size() ; j++)
{
itype_id type = r->tools[i][j].type;
int req = r->tools[i][j].count;
if((req<= 0 && crafting_inv.has_amount(type,1)) || (req > 0 && crafting_inv.has_charges(type,req)))
{
has_tool = true;
break;
}
}
if(!has_tool)
{
return false;
}
}
// check all components
for(int i = 0 ; i < 20 ; i++)
{
if(r->components[i].size() == 0)
{
break;
}
bool has_comp = false;
for(int j = 0 ; j < r->components[i].size() ; j++)
{
itype_id type = r->components[i][j].type;
int req = r->components[i][j].count;
if (itypes[type]->count_by_charges() && req > 0)
{
if (crafting_inv.has_charges(type, req))
{
has_comp = true;
break;
}
}
else if (crafting_inv.has_amount(type, abs(req)))
{
has_comp = true;
break;
}
}
if(!has_comp)
{
return false;
}
}
return true;
}

void game::craft()
{
Expand Down Expand Up @@ -1487,6 +1584,7 @@ void game::make_craft(recipe *making)
{
u.assign_activity(ACT_CRAFT, making->time, making->id);
u.moves = 0;
u.lastrecipe = making;
}

void game::complete_craft()
Expand Down
4 changes: 4 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,10 @@ bool game::handle_action()
case ACTION_CRAFT:
craft();
break;

case ACTION_RECRAFT:
recraft();
break;

case ACTION_DISASSEMBLE:
if (u.in_vehicle)
Expand Down
3 changes: 3 additions & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ class game
void close(); // Close a door 'c'
void smash(); // Smash terrain
void craft(); // See crafting.cpp
void recraft(); // See crafting.cpp
void try_and_make(recipe *r);
bool can_make(recipe *r);
void make_craft(recipe *making); // See crafting.cpp
void complete_craft(); // See crafting.cpp
void pick_recipes(std::vector<recipe*> &current,
Expand Down
3 changes: 3 additions & 0 deletions player.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "inventory.h"
#include "artifact.h"
#include "mutation.h"
#include "crafting.h"
#include <vector>
#include <string>
#include <map>
Expand Down Expand Up @@ -318,6 +319,8 @@ class player {

std::vector <disease> illness;
std::vector <addiction> addictions;

recipe* lastrecipe;
};

#endif