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

Graffiti. #45

Merged
merged 1 commit into from
Feb 7, 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
2 changes: 2 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5017,6 +5017,8 @@ point game::look_around()
mvwputch(w_terrain, SEEY, SEEX, c_white, 'x');
mvwprintw(w_look, 1, 1, "Unseen.");
}
if (m.graffiti_at(lx, ly).contents)
mvwprintw(w_look, 6, 1, "Graffiti: %s", m.graffiti_at(lx, ly).contents->c_str());
wrefresh(w_look);
wrefresh(w_terrain);
} while (ch != ' ' && ch != KEY_ESCAPE && ch != '\n');
Expand Down
25 changes: 25 additions & 0 deletions graffiti.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "graffiti.h"
#include "output.h"

graffiti::graffiti()
{
this->contents = NULL;
}

graffiti::graffiti(std::string newstr)
{
this->contents = new std::string(newstr);
}

graffiti::~graffiti()
{
// delete contents;
}

graffiti graffiti::operator=(graffiti rhs)
{
if(rhs.contents)
this->contents = new std::string(*rhs.contents);
else
this->contents = 0;
}
18 changes: 18 additions & 0 deletions graffiti.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _GRAFFITI_H_
#define _GRAFFITI_H_

#include <string>
#include "itype.h"
#include "mtype.h"

class graffiti
{
public:
graffiti();
graffiti(std::string contents);
~graffiti();
graffiti operator=(graffiti rhs);
std::string *contents;
};

#endif
6 changes: 3 additions & 3 deletions itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ itm_wrapper, itm_syringe, itm_rag, itm_fur, itm_leather, itm_superglue,
itm_splinter, itm_skewer, itm_crackpipe, itm_torch_done,
itm_spring, itm_lawnmower, itm_lawnmower_blade, itm_lawnmower_machete,
itm_lawnmower_halberd, itm_curtain, itm_broketent, itm_element,
itm_television, itm_pilot_light, itm_toaster, itm_microwave, itm_laptop,
itm_fan, itm_ceramic_plate, itm_ceramic_bowl, itm_ceramic_cup,
itm_television, itm_pilot_light, itm_toaster, itm_microwave, itm_laptop,
itm_fan, itm_ceramic_plate, itm_ceramic_bowl, itm_ceramic_cup,
itm_glass_plate, itm_glass_bowl, itm_glass, itm_tin_plate, itm_fork, itm_spork,

// Vehicle parts
Expand Down Expand Up @@ -203,7 +203,7 @@ itm_lighter, itm_sewing_kit, itm_scissors, itm_hammer, itm_extinguisher,
itm_knife_butcher, itm_knife_combat, itm_saw, itm_ax, itm_hacksaw,
itm_tent_kit, itm_torch, itm_torch_lit, itm_candle, itm_candle_lit,
itm_brazier, itm_puller, itm_press, itm_screwdriver, itm_wrench,
itm_boltcutters, itm_mop, itm_picklocks, itm_pickaxe,
itm_boltcutters, itm_mop, itm_picklocks, itm_pickaxe, itm_spray_can,
// Bionics containers
itm_bionics_battery, itm_bionics_power, itm_bionics_tools,
itm_bionics_neuro, itm_bionics_sensory, itm_bionics_aquatic,
Expand Down
4 changes: 4 additions & 0 deletions itypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3928,6 +3928,10 @@ TOOL("pickaxe", 60, 160,'/', c_ltred, WOOD, MNULL,
12, 11, 12, 0, -1, 0, 0, 0, 0, AT_NULL, itm_null, &iuse::pickaxe, 0, "\
A large steel pickaxe, strike the earth!");

TOOL("spray can", 50, 10, ';', c_ltblue, PLASTIC, MNULL,
1, 1, 0, 0, 0, 10, 10, 1, 0, AT_NULL, itm_null, &iuse::spray_can, 0, "\
A spray can, filled with paint. Use this tool to make graffiti on the floor.");

// BIONICS
// These are the modules used to install new bionics in the player. They're
// very simple and straightforward; a difficulty, followed by a NULL-terminated
Expand Down
9 changes: 9 additions & 0 deletions iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3311,3 +3311,12 @@ void iuse::artifact(game *g, player *p, item *it, bool t)
}
}
}

void iuse::spray_can(game *g, player *p, item *it, bool t)
{
std::string message = string_input_popup("Spray what?");
if(g->m.add_graffiti(g, p->posx, p->posy, message))
g->add_msg("You spray a message on the ground.");
else
g->add_msg("You fail to spray a message here.");
}
1 change: 1 addition & 0 deletions iuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class iuse
void wrench (game *g, player *p, item *it, bool t);
void boltcutters (game *g, player *p, item *it, bool t);
void mop (game *g, player *p, item *it, bool t);
void spray_can (game *g, player *p, item *it, bool t);
// MACGUFFINS
void mcg_note (game *g, player *p, item *it, bool t);
// ARTIFACTS
Expand Down
35 changes: 34 additions & 1 deletion map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,7 @@ void map::drawsq(WINDOW* w, player &u, const int x, const int y, const bool inve
nc_color tercol;
long sym = terlist[ter(x, y)].sym;
bool hi = false;
bool graf = false;
bool normal_tercol = false, drew_field = false;
if (u.has_disease(DI_BOOMERED))
tercol = c_magenta;
Expand Down Expand Up @@ -2384,11 +2385,16 @@ void map::drawsq(WINDOW* w, player &u, const int x, const int y, const bool inve
if (normal_tercol)
tercol = veh->part_color(veh_part);
}

// If there's graffiti here, change background color
if(graffiti_at(x,y).contents)
graf = true;

if (invert)
mvwputch_inv(w, j, k, tercol, sym);
else if (hi)
mvwputch_hi (w, j, k, tercol, sym);
else if (graf)
mvwputch (w, j, k, red_background(tercol), sym);
else
mvwputch (w, j, k, tercol, sym);
}
Expand Down Expand Up @@ -2943,6 +2949,33 @@ bool map::inbounds(const int x, const int y)
return (x >= 0 && x < SEEX * my_MAPSIZE && y >= 0 && y < SEEY * my_MAPSIZE);
}

bool map::add_graffiti(game *g, int x, int y, std::string contents)
{
int nx = x;
int ny = y;
int nonant = int(nx / SEEX) + int(ny / SEEY) * my_MAPSIZE;
nx %= SEEX;
ny %= SEEY;
grid[nonant]->graf[nx][ny] = graffiti(contents);
return true;
}

graffiti map::graffiti_at(int x, int y)
{
if (!inbounds(x, y))
return graffiti();
/*
int nonant;
cast_to_nonant(x, y, nonant);
*/
int nonant = int(x / SEEX) + int(y / SEEY) * my_MAPSIZE;

x %= SEEX;
y %= SEEY;
return grid[nonant]->graf[x][y];
}


tinymap::tinymap()
{
nulter = t_null;
Expand Down
5 changes: 5 additions & 0 deletions map.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "monster.h"
#include "npc.h"
#include "vehicle.h"
#include "graffiti.h"

#define MAPSIZE 11

Expand Down Expand Up @@ -166,6 +167,10 @@ class map
// Computers
computer* computer_at(const int x, const int y);

// Graffiti
graffiti graffiti_at(int x, int y);
bool add_graffiti(game *g, int x, int y, std::string contents);

// mapgen.cpp functions
void generate(game *g, overmap *om, const int x, const int y, const int turn);
void post_process(game *g, unsigned zones);
Expand Down
17 changes: 17 additions & 0 deletions mapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ void mapbuffer::save()
// Output the computer
if (sm->comp.name != "")
fout << "c " << sm->comp.save_data() << std::endl;

// Output the graffiti
for (int j = 0; j < SEEY; j++) {
for (int i = 0; i < SEEX; i++) {
if (sm->graf[i][j].contents)
fout << "G " << i << " " << j << *sm->graf[i][j].contents << std::endl;
}
}

fout << "----" << std::endl;
num_saved_submaps++;
}
Expand Down Expand Up @@ -205,6 +214,7 @@ void mapbuffer::load()
sm->itm[i][j].clear();
sm->trp[i][j] = tr_null;
sm->fld[i][j] = field();
sm->graf[i][j] = graffiti();
}
}
// Load irradiation
Expand Down Expand Up @@ -265,6 +275,13 @@ void mapbuffer::load()
} else if (string_identifier == "c") {
getline(fin, databuff);
sm->comp.load_data(databuff);
} else if (string_identifier == "G") {
std::string s;
int j;
int i;
fin >> j >> i;
getline(fin,s);
sm->graf[j][i] = graffiti(s);
}
} while (string_identifier != "----" && !fin.eof());

Expand Down
2 changes: 2 additions & 0 deletions mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "enums.h"
#include "computer.h"
#include "vehicle.h"
#include "graffiti.h"
#include <iosfwd>

class game;
Expand Down Expand Up @@ -729,6 +730,7 @@ struct submap {
trap_id trp[SEEX][SEEY]; // Trap on each square
field fld[SEEX][SEEY]; // Field on each square
int rad[SEEX][SEEY]; // Irradiation of each square
graffiti graf[SEEX][SEEY]; // Graffiti on each square
int active_item_count;
int field_count;
int turn_last_touched;
Expand Down
1 change: 1 addition & 0 deletions mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void map::generate(game *g, overmap *om, int x, int y, int turn)
grid[i]->trp[x][y] = tr_null;
grid[i]->fld[x][y] = field();
grid[i]->rad[x][y] = 0;
grid[i]->graf[x][y] = graffiti();
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions mapitemsdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void game::init_mapitems()
itm_glasses_safety, itm_battery, itm_nail, itm_nailgun,
itm_manual_mechanics, itm_hammer, itm_flashlight, itm_soldering_iron,
itm_bubblewrap, itm_binoculars, itm_duct_tape, itm_lawnmower, itm_foot_crank,
itm_boltcutters, NULL);
itm_boltcutters, itm_spray_can, NULL);

setvector(
mapitems[mi_bedroom],
Expand Down Expand Up @@ -174,7 +174,7 @@ void game::init_mapitems()
mapitems[mi_hardware],
itm_superglue, itm_chain, itm_rope_6, itm_rope_30, itm_glass_sheet,
itm_pipe, itm_nail, itm_hose, itm_string_36, itm_frame, itm_metal_tank,
itm_wire, itm_wire_barbed, itm_duct_tape, itm_jerrycan, itm_lawnmower, itm_foot_crank,
itm_wire, itm_wire_barbed, itm_duct_tape, itm_jerrycan, itm_lawnmower, itm_foot_crank, itm_spray_can,
NULL);

setvector(
Expand Down Expand Up @@ -252,7 +252,7 @@ void game::init_mapitems()
itm_glass_sheet, itm_stick, itm_muffler, itm_pipe, itm_bag_plastic,
itm_bottle_plastic, itm_bottle_glass, itm_can_drink, itm_can_food,
itm_box_small, itm_bubblewrap, itm_lighter, itm_syringe, itm_rag,
itm_software_hacking, itm_carboy_plastic, NULL);
itm_software_hacking, itm_carboy_plastic, itm_spray_can, NULL);

setvector(
mapitems[mi_ammo],
Expand Down Expand Up @@ -395,7 +395,7 @@ void game::init_mapitems()
setvector(
mapitems[mi_cop_evidence],
itm_weed, itm_coke, itm_meth, itm_heroin, itm_syringe, itm_electrohack,
itm_knife_combat, itm_crowbar, itm_tazer, itm_software_hacking, NULL);
itm_knife_combat, itm_crowbar, itm_tazer, itm_software_hacking, itm_spray_can, NULL);

setvector(
mapitems[mi_hospital_lab],
Expand Down Expand Up @@ -474,7 +474,7 @@ void game::init_mapitems()
itm_manual_first_aid, itm_manual_tailor, itm_manual_carpentry,
itm_lighter, itm_sewing_kit, itm_thread, itm_hammer, itm_extinguisher,
itm_flashlight, itm_hotplate, itm_water_purifier, itm_radio, itm_rollmat, itm_tent_kit,
itm_canteen, NULL);
itm_canteen, itm_spray_can, NULL);

setvector(
mapitems[mi_mechanics],
Expand Down Expand Up @@ -612,7 +612,7 @@ void game::init_mapitems()
itm_string_36, itm_rope_30, itm_chain, itm_binoculars,
itm_bottle_plastic, itm_lighter, itm_sewing_kit, itm_thread, itm_extinguisher,
itm_flashlight, itm_crowbar, itm_chainsaw_off, itm_beartrap,
itm_grenade, itm_EMPbomb, itm_hotplate, itm_UPS_off, itm_canteen, NULL);
itm_grenade, itm_EMPbomb, itm_hotplate, itm_UPS_off, itm_canteen, itm_spray_can, NULL);

setvector(
mapitems[mi_sewage_plant],
Expand Down Expand Up @@ -659,7 +659,7 @@ void game::init_mapitems()
mapitems[mi_subway],
itm_wrapper, itm_string_6, itm_chain, itm_rock, itm_pipe,
itm_mag_porn, itm_bottle_plastic, itm_bottle_glass, itm_can_drink,
itm_can_food, itm_lighter, itm_flashlight, itm_rag, itm_crowbar, NULL);
itm_can_food, itm_lighter, itm_flashlight, itm_rag, itm_crowbar, itm_spray_can, NULL);

setvector(
mapitems[mi_sewer],
Expand All @@ -683,7 +683,7 @@ void game::init_mapitems()
itm_nx17, itm_flamethrower, itm_flashlight, itm_radio, itm_geiger_off,
itm_teleporter, itm_canister_goo, itm_dynamite, itm_mininuke,
itm_bot_manhack, itm_UPS_off, itm_bionics_battery, itm_bionics_tools,
itm_arrow_cf, NULL);
itm_arrow_cf, itm_spray_can, NULL);

setvector(
mapitems[mi_ant_food],
Expand Down