Trying to add some fruit trees. facing errors and in need of some help

well, title is the subject.

specifically i am trying to add pear, cherry, peach apricot and plum trees, to have some variety over just apples.
my internet searches convey that just these fruit trees (and apples ofc) exist in new england climate.

soo, i modded the following files:
1.no need to change the comestibles.json, since all those fruits are already in.

2.item_groups.json: to add peaches & apricots to produce (this is irrelevant to the new stuff)

,{ "type" : "item_group", "id" : "produce", "items":[ ["apple", 70], ["orange", 65], ["banana", 40], ["lemon", 50], ["pear", 50], ["cherries", 30], ["plums", 30], ["peach", 30], ["apricot", 30], ["grapes", 50], ["cranberries", 7], ["raspberries", 7], ["blackberries", 7], ["rhubarb", 20], ["mushroom", 4], ["potato_raw", 10], ["blueberries", 3], ["strawberries", 2], ["tomato", 9], ["broccoli", 9], ["cucumber", 10], ["zucchini", 7], ["celery", 5], ["wheat", 3], ["onion", 3], ["carrot", 3] ] }
i assumed that the number after the id is the chance of it appearing

3.terrain.json: to add all these new trees

{ "type" : "terrain", "id" : "t_tree_apple", "name": "apple tree", "symbol": "7", "color": "ltgreen", "move_cost": 0, "flags": ["FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "TREE", "REDUCE_SCENT"], "examine_action": "tree_apple" },{ "type" : "terrain", "id" : "t_tree_pear", "name": "pear tree", "symbol": "7", "color": "ltgreen", "move_cost": 0, "flags": ["FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "TREE", "REDUCE_SCENT"], "examine_action": "tree_pear" },{ "type" : "terrain", "id" : "t_tree_cherry", "name": "cherry tree", "symbol": "7", "color": "red", "move_cost": 0, "flags": ["FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "TREE", "REDUCE_SCENT"], "examine_action": "tree_cherry" },{ "type" : "terrain", "id" : "t_tree_peach", "name": "peach tree", "symbol": "7", "color": "yellow", "move_cost": 0, "flags": ["FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "TREE", "REDUCE_SCENT"], "examine_action": "tree_peach" },{ "type" : "terrain", "id" : "t_tree_apricot", "name": "apricot tree", "symbol": "7", "color": "yellow", "move_cost": 0, "flags": ["FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "TREE", "REDUCE_SCENT"], "examine_action": "tree_apricot" },{ "type" : "terrain", "id" : "t_tree_plum", "name": "plum tree", "symbol": "7", "color": "red", "move_cost": 0, "flags": ["FLAMMABLE_ASH", "NOITEM", "SUPPORTS_ROOF", "TREE", "REDUCE_SCENT"], "examine_action": "tree_plum" }

4.mapdata.h: added as trees

// Tree t_tree, t_tree_young, t_tree_apple, tree_pear, tree_cherry, tree_peach, tree_apricot, tree_plum, t_tree_pine, t_tree_deadpine, t_underbrush, t_shrub, t_shrub_blueberry, t_shrub_strawberry, t_trunk, t_root_wall, t_wax, t_floor_wax, t_fence_v, t_fence_h, t_chainfence_v, t_chainfence_h, t_chainfence_posts, t_fence_post, t_fence_wire, t_fence_barbed, t_fence_rope, t_railing_v, t_railing_h,

5.mapdata.cpp: again added trees

// Tree t_tree, t_tree_young, t_tree_apple, tree_pear, tree_cherry, tree_peach, tree_apricot, tree_plum, t_tree_pine, t_tree_deadpine, t_underbrush, t_shrub, t_shrub_blueberry, t_shrub_strawberry, t_trunk, t_root_wall, t_wax, t_floor_wax, t_fence_v, t_fence_h, t_chainfence_v, t_chainfence_h, t_chainfence_posts, t_fence_post, t_fence_wire, t_fence_barbed, t_fence_rope, t_railing_v, t_railing_h,

6.mapgen_functions.cpp: so that the new trees will spawn

if ((forest_chance > 0 && rn > 13) || one_in(100 - forest_chance)) { if (one_in(250)) { m->ter_set(i, j, t_tree_apple); } else if (one_in(300)){ m->ter_set(i, j, tree_pear); }else if (one_in(300)){ m->ter_set(i, j, tree_cherry); }else if (one_in(350)){ m->ter_set(i, j, tree_peach); }else if (one_in(350)){ m->ter_set(i, j, tree_apricot); }else if (one_in(350)){ m->ter_set(i, j, tree_plum); }else if (one_in(128)){ m->ter_set(i, j, t_tree_deadpine); } else if (one_in(16)){ m->ter_set(i, j, t_tree_pine); } else { m->ter_set(i, j, t_tree); }
here i give 1 in 300 chance for pears and 1 in 350 for all other trees.

7.iexamine.h: to set functions to be able to harvest from the trees

void tree_apple (player *p, map *m, int examx, int examy); void tree_pear (player *p, map *m, int examx, int examy); void tree_cherry (player *p, map *m, int examx, int examy); void tree_peach (player *p, map *m, int examx, int examy); void tree_apricot (player *p, map *m, int examx, int examy); void tree_plum (player *p, map *m, int examx, int examy);

and
8a. iexamine.cpp: to create the new harvest functions

[spoiler][code]void iexamine::tree_pear(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == SUMMER || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != AUTUMN) {
add_msg( m_info, (“The fruits ripen in autumn.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “pear”, t_tree);
}

void iexamine::tree_cherry(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == SUMMER || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “cherries”, t_tree);
}

void iexamine::tree_peach(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == SUMMER || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “peach”, t_tree);
}

void iexamine::tree_apricot(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == SUMMER || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “apricot”, t_tree);
}

void iexamine::tree_plum(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == SUMMER || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “plum”, t_tree);
}[/code][/spoiler]

8b.and in the same file, these functions are called when:

if (“tree_apple” == function_name) {
return &iexamine::tree_apple;
}
if (“tree_pear” == function_name) {
return &iexamine::tree_pear;
}
if (“tree_cherry” == function_name) {
return &iexamine::tree_cherry;
}
if (“tree_peach” == function_name) {
return &iexamine::tree_peach;
}
if (“tree_apricot” == function_name) {
return &iexamine::tree_apricot;
}
if (“tree_plum” == function_name) {
return &iexamine::tree_plum;
}

thing is, i have segfaults, and i don’t understand my debug.log
have i missed some file i should also modify? i cannot find any syntax errors, so maybe i have a logic error?
for your consideration, also the latest entries in my debug.log:

23:13:35.269 GAME :
(./cataclysm() [0x98a86b]),
(./cataclysm() [0x898698]),
(./cataclysm() [0x895dcb]),
(./cataclysm() [0x881f00]),
(./cataclysm() [0x896b2c]),
(./cataclysm() [0x87de48]),
(./cataclysm() [0xacc28e]),
(./cataclysm() [0xaccd8e]),
(./cataclysm() [0xacdc7e]),
(./cataclysm() [0xacddf4]),
(./cataclysm() [0x4fd3c1]),
(./cataclysm() [0x84db9e]),
(./cataclysm() [0x973553]),
(/usr/lib/libc.so.6(__libc_start_main+0xf0) [0x7f641872d000]),
(./cataclysm() [0x408a19]),
GROUP_RIVER: 533 => 211
23:13:35.270 GAME :
(./cataclysm() [0x98a86b]),
(./cataclysm() [0x898698]),
(./cataclysm() [0x895f6b]),
(./cataclysm() [0x881f00]),
(./cataclysm() [0x896b2c]),
(./cataclysm() [0x87de48]),
(./cataclysm() [0xacc28e]),
(./cataclysm() [0xaccd8e]),
(./cataclysm() [0xacdc7e]),
(./cataclysm() [0xacddf4]),
(./cataclysm() [0x4fd3c1]),
(./cataclysm() [0x84db9e]),
(./cataclysm() [0x973553]),
(/usr/lib/libc.so.6(__libc_start_main+0xf0) [0x7f641872d000]),
(./cataclysm() [0x408a19]),
GROUP_WORM: 45 => 18

PS. It is my first try at modding cata. Moreover i have very little experience with c++ and not a great programming experience either, so i might be missing something easy or doing something stupid.
PPS. Would it be better to have a generic ‘fruit bearing tree’ that, when harvested, gives one of those fruits, rather than apples? or separate trees as i did is better?

found and fixed an error in iexamine.cpp: Some of these trees would ripen in summer, but i hadn’t changed the proboscis related code to target AUTUMN and SPRING only.
i will try again, but it does not seem related to the segfault. it would just make both actions happen together…

[spoiler][code]void iexamine::tree_apple(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == SUMMER || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != AUTUMN) {
add_msg( m_info, (“The fruits ripen in autumn.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “apple”, t_tree);
}

void iexamine::tree_pear(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == SUMMER || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != AUTUMN) {
add_msg( m_info, (“The fruits ripen in autumn.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “pear”, t_tree);
}

void iexamine::tree_cherry(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == AUTUMN || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “cherries”, t_tree);
}

void iexamine::tree_peach(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == AUTUMN || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “peach”, t_tree);
}

void iexamine::tree_apricot(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == AUTUMN || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “apricot”, t_tree);
}

void iexamine::tree_plum(player *p, map *m, int examx, int examy)
{
if (calendar::turn.get_season() == WINTER) {
add_msg( m_info, (“The tree is dormant and uninteresting.”));
return;
}
if ( ((p->has_trait(“PROBOSCIS”)) || (p->has_trait(“BEAK_HUM”))) &&
((p->hunger) > 0) && (!(p->wearing_something_on(bp_mouth))) &&
(calendar::turn.get_season() == AUTUMN || calendar::turn.get_season() == SPRING) ) {
p->moves -= 100; // Need to find a blossom (assume there’s one somewhere)
add_msg(
(“You find a flower and drink some nectar.”));
p->hunger -= 15;
}
if (calendar::turn.get_season() != SUMMER) {
add_msg( m_info, (“The fruits ripen in summer.”));
return;
}
if(!query_yn(
(“Harvest from the %s?”), m->tername(examx, examy).c_str())) {
none(p, m, examx, examy);
return;
}
pick_plant(p, m, examx, examy, “plum”, t_tree);
}
[/code][/spoiler]

now looking at mapgen code…

EDIT

found it… in both the mapdata files i was using id’s like tree_plum instead of t_tree_plum that was needed… this should fix it and then i got to learn how to use git… assuming that you’d want to merge it when done…

Great idea, kind of an expansion to what Rivet did right? Really neat.

fixed the final errors… seems fine now… time to learn how to use git to contribute. :confused:

@12doze12: It was in my head for a couple of days as a small scope project that i could do to start learning how to contribute, rather than asking others to add stuff.

Actually i did not know that Rivet has done it when i started. i became aware of it when i pulled the new experimental to mod…
it is pure luck that she hasn’t already added this :slight_smile:

Great, I recently suggested the adiction of craftable wooden/leather shoulder pads and I’m thinking of doing them on my own aswell with the little coding capacity I have in C#.

Yeah, nice work done here!

Did you already try to make a pul request on github?

I am not entirely sure on the colour of the trees; red for cherry and yellow or the others might look a little unusual.

yes, its already merged so try it out and report back on your opinions about the colors.
personally i find it… colorful, especially with all these colored flowers.