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

Radio tuning #731

Merged
merged 4 commits into from
Apr 29, 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
1 change: 1 addition & 0 deletions data/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Added fur scarf, fur gloves, fur trenchcoat, fur pants, fur boots (all craft onl
All tailoring items that use fur require survival as secondary skill.
Added crafting recipes for bandana, blanket, house coat, cloak.
Weather radio
Radios are tuneable, so you can receive from more than one station without moving.
New item that doubles battery capacity of tools, recipe learn from certain electronics books.
Bugfix: reduced chance of "Tried to kill monster" debug spam.
Bugfix: reduced chance of "Stopping out-of-map vehicle" spam.
Expand Down
161 changes: 115 additions & 46 deletions iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,55 +1430,124 @@ void iuse::radio_off(game *g, player *p, item *it, bool t)
}
}

void iuse::radio_on(game *g, player *p, item *it, bool t)
static radio_tower *find_radio_station( game *g, int frequency )
{
if (t) { // Normal use
int best_signal = 0;
std::string message = "Radio: Kssssssssssssh.";
for (int k = 0; k < g->cur_om.radios.size(); k++) {
int signal = g->cur_om.radios[k].strength -
rl_dist(g->cur_om.radios[k].x, g->cur_om.radios[k].y,
g->levx, g->levy);
if (signal > best_signal) {
best_signal = signal;
if( g->cur_om.radios[k].type == MESSAGE_BROADCAST ) {
message = g->cur_om.radios[k].message;
} else if (g->cur_om.radios[k].type == WEATHER_RADIO) {
message = weather_forecast(g, g->cur_om.radios[k]);
}
}
}
if (best_signal > 0) {
for (int j = 0; j < message.length(); j++) {
if (dice(10, 100) > dice(10, best_signal * 3)) {
if (!one_in(10))
message[j] = '#';
else
message[j] = char(rng('a', 'z'));
radio_tower *tower = NULL;
for (int k = 0; k < g->cur_om.radios.size(); k++)
{
tower = &g->cur_om.radios[k];
if( 0 < tower->strength - rl_dist(tower->x, tower->y, g->levx, g->levy) &&
tower->frequency == frequency )
{
return tower;
}
}
}
return NULL;
}

std::vector<std::string> segments;
while (message.length() > RADIO_PER_TURN) {
int spot = message.find_last_of(' ', RADIO_PER_TURN);
if (spot == std::string::npos)
spot = RADIO_PER_TURN;
segments.push_back( message.substr(0, spot) );
message = message.substr(spot + 1);
}
segments.push_back(message);
int index = g->turn % (segments.size());
std::stringstream messtream;
messtream << "radio: " << segments[index];
message = messtream.str();
}
point p = g->find_item(it);
g->sound(p.x, p.y, 6, message.c_str());
} else { // Turning it off
g->add_msg_if_player(p,"The radio dies.");
it->make(g->itypes["radio"]);
it->active = false;
}
void iuse::radio_on(game *g, player *p, item *it, bool t)
{
if (t)
{ // Normal use
std::string message = "Radio: Kssssssssssssh.";
radio_tower *selected_tower = find_radio_station( g, it->mode );
if( selected_tower != NULL )
{
if( selected_tower->type == MESSAGE_BROADCAST )
{
message = selected_tower->message;
}
else if (selected_tower->type == WEATHER_RADIO)
{
message = weather_forecast(g, *selected_tower);
}

int signal_strength = selected_tower->strength -
rl_dist(selected_tower->x, selected_tower->y, g->levx, g->levy);

for (int j = 0; j < message.length(); j++)
{
if (dice(10, 100) > dice(10, signal_strength * 3))
{
if (!one_in(10))
{
message[j] = '#';
}
else
{
message[j] = char(rng('a', 'z'));
}
}
}

std::vector<std::string> segments;
while (message.length() > RADIO_PER_TURN)
{
int spot = message.find_last_of(' ', RADIO_PER_TURN);
if (spot == std::string::npos)
{
spot = RADIO_PER_TURN;
}
segments.push_back( message.substr(0, spot) );
message = message.substr(spot + 1);
}
segments.push_back(message);
int index = g->turn % (segments.size());
std::stringstream messtream;
messtream << "radio: " << segments[index];
message = messtream.str();
}
point p = g->find_item(it);
g->sound(p.x, p.y, 6, message.c_str());
} else { // Activated
int ch = menu( true, "Radio:", "Scan", "Turn off", NULL );
switch (ch)
{
case 1:
{
int old_frequency = it->mode;
radio_tower *tower = NULL;
radio_tower *lowest_tower = NULL;
radio_tower *lowest_larger_tower = NULL;

for (int k = 0; k < g->cur_om.radios.size(); k++)
{
tower = &g->cur_om.radios[k];

if( 0 < tower->strength - rl_dist(tower->x, tower->y, g->levx, g->levy) &&
tower->frequency != old_frequency )
{
if( tower->frequency > old_frequency &&
(lowest_larger_tower == NULL ||
tower->frequency < lowest_larger_tower->frequency) )
{
lowest_larger_tower = tower;
}
else if( lowest_tower == NULL ||
tower->frequency < lowest_tower->frequency )
{
lowest_tower = tower;
}
}
}
if( lowest_larger_tower != NULL )
{
it->mode = lowest_larger_tower->frequency;
}
else if( lowest_tower != NULL )
{
it->mode = lowest_tower->frequency;
}
}
break;
case 2:
g->add_msg_if_player(p,"The radio dies.");
it->make(g->itypes["radio"]);
it->active = false;
break;
case 3: break;
}
}
}

void iuse::noise_emitter_off(game *g, player *p, item *it, bool t)
Expand Down
10 changes: 5 additions & 5 deletions overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2602,28 +2602,28 @@ void overmap::place_radios()
case 0:
snprintf( message, sizeof(message), "This is emergency broadcast station %d%d.\
Please proceed quickly and calmly to your designated evacuation point.", i, j);
radios.push_back(radio_tower(i*2, j*2, rng(80, 200), message));
radios.push_back(radio_tower(i*2, j*2, rng(RADIO_MIN_STRENGTH, RADIO_MAX_STRENGTH), message));
break;
case 1:
radios.push_back(radio_tower(i*2, j*2, rng(80, 200),
radios.push_back(radio_tower(i*2, j*2, rng(RADIO_MIN_STRENGTH, RADIO_MAX_STRENGTH),
"Head West. All survivors, head West. Help is waiting."));
break;
case 2:
radios.push_back(radio_tower(i*2, j*2, rng(80, 200), "", WEATHER_RADIO));
radios.push_back(radio_tower(i*2, j*2, rng(RADIO_MIN_STRENGTH, RADIO_MAX_STRENGTH), "", WEATHER_RADIO));
break;
}
}
break;
case ot_lmoe:
snprintf( message, sizeof(message), "This is automated emergency shelter beacon %d%d.\
Supplies, amenities and shelter are stocked.", i, j);
radios.push_back(radio_tower(i*2, j*2, rng(40, 100), message));
radios.push_back(radio_tower(i*2, j*2, rng(RADIO_MIN_STRENGTH, RADIO_MAX_STRENGTH) / 2, message));
break;
case ot_fema_entrance:
snprintf( message, sizeof(message), "This is FEMA camp %d%d.\
Supplies are limited, please bring supplemental food, water, and bedding.\
This is FEMA camp %d%d. A designated long-term emergency shelter.", i, j, i, j);
radios.push_back(radio_tower(i*2, j*2, rng(80, 200), message));
radios.push_back(radio_tower(i*2, j*2, rng(RADIO_MIN_STRENGTH, RADIO_MAX_STRENGTH), message));
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion overmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ enum radio_type {
WEATHER_RADIO
};

#define RADIO_MIN_STRENGTH 80
#define RADIO_MAX_STRENGTH 200

struct radio_tower {
int x;
int y;
int strength;
radio_type type;
std::string message;
int frequency;
radio_tower(int X = -1, int Y = -1, int S = -1, std::string M = "",
radio_type T = MESSAGE_BROADCAST) :
x (X), y (Y), strength (S), type (T), message (M) {}
x (X), y (Y), strength (S), type (T), message (M) {frequency = rand();}
};

struct map_layer {
Expand Down