Skip to content

Commit 8a9cfd7

Browse files
authored
Merge pull request #82272 from PatrikLundell/personal_mission
2 parents 54d9859 + 76f31b0 commit 8a9cfd7

File tree

7 files changed

+325
-23
lines changed

7 files changed

+325
-23
lines changed

data/raw/keybindings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,13 @@
12841284
"id": "MISSIONS",
12851285
"bindings": [ { "input_method": "keyboard_char", "key": "M" }, { "input_method": "keyboard_code", "key": "m", "mod": [ "shift" ] } ]
12861286
},
1287+
{
1288+
"type": "keybinding",
1289+
"name": "Define Point of Interest",
1290+
"category": "OVERMAP",
1291+
"id": "CREATE_POINT_OF_INTEREST",
1292+
"bindings": [ { "input_method": "keyboard_char", "key": "P" }, { "input_method": "keyboard_code", "key": "p", "mod": [ "shift" ] } ]
1293+
},
12871294
{
12881295
"type": "keybinding",
12891296
"id": "ROTATE",

src/avatar.cpp

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,21 @@ std::vector<mission *> avatar::get_failed_missions() const
300300
return failed_missions;
301301
}
302302

303+
std::vector<point_of_interest> avatar::get_points_of_interest() const
304+
{
305+
return points_of_interest;
306+
}
307+
303308
mission *avatar::get_active_mission() const
304309
{
305310
return active_mission;
306311
}
307312

313+
point_of_interest avatar::get_active_point_of_interest() const
314+
{
315+
return active_point_of_interest;
316+
}
317+
308318
void avatar::reset_all_missions()
309319
{
310320
active_mission = nullptr;
@@ -315,10 +325,12 @@ void avatar::reset_all_missions()
315325

316326
tripoint_abs_omt avatar::get_active_mission_target() const
317327
{
318-
if( active_mission == nullptr ) {
319-
return tripoint_abs_omt::invalid;
328+
if( active_mission != nullptr ) {
329+
return active_mission->get_target();
330+
} else {
331+
// It's tripoint_abs_invalid if not active.
332+
return active_point_of_interest.pos;
320333
}
321-
return active_mission->get_target();
322334
}
323335

324336
void avatar::set_active_mission( mission &cur_mission )
@@ -329,7 +341,25 @@ void avatar::set_active_mission( mission &cur_mission )
329341
cur_mission.mission_id().c_str() );
330342
} else {
331343
active_mission = &cur_mission;
344+
active_point_of_interest.pos = tripoint_abs_omt::invalid;
345+
}
346+
}
347+
348+
void avatar::set_active_point_of_interest( const point_of_interest &active_point_of_interest )
349+
{
350+
for( const point_of_interest &iter : points_of_interest ) {
351+
// It's really sufficient to only check the position as used...
352+
if( iter.pos == active_point_of_interest.pos &&
353+
iter.text == active_point_of_interest.text ) {
354+
this->active_point_of_interest = active_point_of_interest;
355+
active_mission = nullptr;
356+
return;
357+
}
358+
332359
}
360+
361+
debugmsg( "active point of interest %s is not in the points_of_interest list",
362+
active_point_of_interest.text.c_str() );
333363
}
334364

335365
void avatar::update_active_mission()
@@ -399,6 +429,44 @@ void avatar::remove_active_mission( mission &cur_mission )
399429
}
400430
}
401431

432+
void avatar::add_point_of_interest( const point_of_interest &new_point_of_interest )
433+
{
434+
for( point_of_interest &existing_point_of_interest : points_of_interest ) {
435+
if( new_point_of_interest.pos == existing_point_of_interest.pos ) {
436+
existing_point_of_interest.text = new_point_of_interest.text;
437+
active_mission = nullptr;
438+
active_point_of_interest = new_point_of_interest;
439+
return;
440+
}
441+
}
442+
443+
points_of_interest.push_back( new_point_of_interest );
444+
active_mission = nullptr;
445+
active_point_of_interest = new_point_of_interest;
446+
}
447+
448+
void avatar::delete_point_of_interest( tripoint_abs_omt pos )
449+
{
450+
for( auto iter = points_of_interest.begin(); iter != points_of_interest.end(); iter++ ) {
451+
if( iter->pos == pos ) {
452+
points_of_interest.erase( iter );
453+
454+
if( active_point_of_interest.pos == pos ) {
455+
active_point_of_interest.pos = tripoint_abs_omt::invalid;
456+
457+
if( !active_missions.empty() ) {
458+
active_mission = active_missions.front();
459+
}
460+
}
461+
462+
return;
463+
}
464+
}
465+
466+
debugmsg( "removed point of interest at %s was not in the points_of_interest list",
467+
pos.to_string().c_str() );
468+
}
469+
402470
diary *avatar::get_avatar_diary()
403471
{
404472
if( a_diary == nullptr ) {

src/avatar.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "magic_teleporter_list.h"
2626
#include "mdarray.h"
2727
#include "memory_fast.h"
28+
#include "point.h"
2829
#include "type_id.h"
2930
#include "units.h"
3031

@@ -74,6 +75,11 @@ struct monster_visible_info {
7475
void remove_npc( npc *n );
7576
};
7677

78+
struct point_of_interest {
79+
tripoint_abs_omt pos = tripoint_abs_omt::invalid;
80+
std::string text;
81+
};
82+
7783
class avatar : public Character
7884
{
7985
public:
@@ -159,19 +165,28 @@ class avatar : public Character
159165
std::vector<mission *> get_active_missions() const;
160166
std::vector<mission *> get_completed_missions() const;
161167
std::vector<mission *> get_failed_missions() const;
168+
std::vector<point_of_interest> get_points_of_interest() const;
162169
/**
163-
* Returns the mission that is currently active. Returns null if mission is active.
170+
* Returns the mission that is currently active. Returns null if no mission is active.
164171
*/
165172
mission *get_active_mission() const;
166173
/**
167-
* Returns the target of the active mission or @ref tripoint_abs_omt::invalid if there is
168-
* no active mission.
174+
* Returns the point of interest that is currently active. Returns null if no mission is active.
175+
*/
176+
point_of_interest get_active_point_of_interest() const;
177+
/**
178+
* Returns the target of the active mission/point of interest or @ref tripoint_abs_omt::invalid if there is
179+
* no active mission or point of interest.
169180
*/
170181
tripoint_abs_omt get_active_mission_target() const;
171182
/**
172183
* Set which mission is active. The mission must be listed in @ref active_missions.
173184
*/
174185
void set_active_mission( mission &cur_mission );
186+
/**
187+
* Set which point of interest is active. The point of interest must be listed in @ref points_of_interest.
188+
*/
189+
void set_active_point_of_interest( const point_of_interest &active_point_of_interest );
175190
/**
176191
* Called when a mission has been assigned to the player.
177192
*/
@@ -188,6 +203,12 @@ class avatar : public Character
188203

189204
void remove_active_mission( mission &cur_mission );
190205

206+
/**
207+
* Despite the name, this operation also makes an existing point of interest active.
208+
*/
209+
void add_point_of_interest( const point_of_interest &new_point_of_interest );
210+
void delete_point_of_interest( tripoint_abs_omt pos );
211+
191212
//return avatar diary
192213
diary *get_avatar_diary();
193214

@@ -404,10 +425,18 @@ class avatar : public Character
404425
/**
405426
* The currently active mission, or null if no mission is currently in progress.
406427
*/
428+
/**
429+
* Points of interest added by the player.
430+
*/
431+
std::vector<point_of_interest> points_of_interest;
432+
407433
mission *active_mission;
434+
435+
point_of_interest active_point_of_interest;
436+
408437
void update_active_mission();
409438
/**
410-
* diary to track player progression and to write the players stroy
439+
* diary to track player progression and to write the players story
411440
*/
412441
std::unique_ptr <diary> a_diary;
413442
/**

0 commit comments

Comments
 (0)