Welcome to the Builder Academy

Question medit - code assistance

More
07 Feb 2018 02:24 - 07 Feb 2018 02:30 #7550 by cunning
I have a unique special procedures that mimics zone load. I am trying to add it to medit just as you would in Zedit.
Code:
void medit_setup_existing(struct descriptor_data *d, int rmob_num) { struct char_data *mob; /* Allocate a scratch mobile structure. */ CREATE(mob, struct char_data, 1); copy_mobile(mob, mob_proto + rmob_num); OLC_MOB(d) = mob; OLC_ITEM_TYPE(d) = MOB_TRIGGER; dg_olc_script_copy(d); /* * The edited mob must not have a script. * It will be assigned to the updated mob later, after editing. */ SCRIPT(mob) = NULL; OLC_MOB(d)->proto_script = NULL; OLC_PROC(d) = OLC_MOB(d)->mob_specials.func; }
Code:
case MEDIT_PROC_MENU: switch (tolower(*arg)) { case 'q': medit_disp_menu(d); return; case 'n': /* New entry. */ if (OLC_PROC(d)[0].command == '~') { /* first command */ if (new_mob_proc(OLC_MOB(d), 0) && start_change_procs(d, 0)) { medit_spec_proc_assign(d); OLC_SAVE(d) = 1; return; } } write_to_output(d, "What number in the list should the new command be? : "); OLC_MODE(d) = MEDIT_NEW_ENTRY; return;
Code:
case MEDIT_NEW_ENTRY: /* Get the line number and insert the new line. */ pos = atoi(arg); if (isdigit(*arg) && new_mob_proc(OLC_MOB(d), pos)) { if (start_change_procs(d, pos)) medit_spec_proc_assign(d); OLC_SAVE(d) = 1; } else medit_disp_spec_menu(d); return;

Genmob.c
Code:
/* Error check user input and then add new (blank) command. */ int new_mob_proc(struct char_data *mob, int pos) { int subcmd = 0; struct spec_proc new_com; /* Error check to ensure users hasn't given too large an index. */ while (mob->mob_specials.func[subcmd].command != '~') subcmd++; if (pos < 0 || pos > subcmd) return 0; /* Ok, let's add a new (blank) command. */ new_com.command = 'N'; add_proc_to_list(&mob->mob_specials.func, &new_com, pos); return 1; }


My issue is that the minute i add a new command it crashes the game. I believe the reason to be because i impact the currently loaded mobile with that procedure. I am stuck because i want to load a copy of the procedure list, and edit it, than remove it from the mob_proto than add the updated one than update the in game mobile.

i believe that i corrupt the first memory block, which than crashes the game when the mobile goes through its live procedure calls. The line in red below should have been ch->mob_specials.func[0].func = Mob armies but as you can see it is corrupted.

Program received signal SIGSEGV, Segmentation fault.
0x000055555557ebb9 in special_procs (ch=ch@entry=0x555556f959c0, victim=victim@entry=0x0, obj=obj@entry=0x0, proc_type=proc_type@entry=3, spec_type=spec_type@entry=1,
dam=dam@entry=0x0, attacktype=0, tmp_desc=0x0) at spec_assign.c:323
323 if (spec_list[MCMD(ch, subcmd).procs].proc_type != PROC_MOB)
(gdb) back
#0 0x000055555557ebb9 in special_procs (ch=ch@entry=0x555556f959c0, victim=victim@entry=0x0, obj=obj@entry=0x0, proc_type=proc_type@entry=3, spec_type=spec_type@entry=1,
dam=dam@entry=0x0, attacktype=0, tmp_desc=0x0) at spec_assign.c:323
#1 0x00005555556c21ac in mobile_activity () at mobact.c:96
#2 0x0000555555677e45 in heartbeat (heart_pulse=179800) at comm.c:1043
#3 0x000055555567d682 in game_loop (local_mother_desc=3) at comm.c:978
#4 0x000055555556e821 in init_game (local_port=<optimized out>) at comm.c:565
#5 main (argc=<optimized out>, argv=<optimized out>) at comm.c:381


#0 0x000055555557ebb9 in special_procs (ch=ch@entry=0x555556f959c0, victim=victim@entry=0x0, obj=obj@entry=0x0, proc_type=proc_type@entry=3, spec_type=spec_type@entry=1,
dam=dam@entry=0x0, attacktype=0, tmp_desc=0x0) at spec_assign.c:323
323 if (spec_list[MCMD(ch, subcmd).procs].proc_type != PROC_MOB)
(gdb) print ch->mob_specials.func[0]
$3 = {command = 104 'h', procs = 32767, func = 0x7ffff737c068 <main_arena+1096>, freq = 1447874704, name = 0x5555564cd090 "ll.\r\n", run_type = 1, term = 0, num1 = 0, num2 = 0,
num3 = 0, num4 = 0, num5 = 0, internal = 0, line = 1, next = 0x0}

(gdb) print ch->mob_specials.func[1]
$4 = {command = 80 'P', procs = 111, func = 0x55555557b5e0 <mob_purge_pets>, freq = 100, name = 0x0, run_type = 1, term = 0, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 0, line = 2, next = 0x0}
(gdb) print ch->mob_specials.func[2]
$5 = {command = 80 'P', procs = 98, func = 0x55555557b740 <mob_unaffects_self>, freq = 100, name = 0x0, run_type = 1, term = 0, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 0, line = 3, next = 0x0}
(gdb) print ch->mob_specials.func[3]
$6 = {command = 80 'P', procs = 133, func = 0x55555557c790 <mob_heal_from_damage>, freq = 100, name = 0x0, run_type = 2, term = 1, num1 = 100, num2 = 0, num3 = 0, num4 = 0,
num5 = 0, internal = 8, line = 4, next = 0x0}
(gdb) print ch->mob_specials.func[4]
$7 = {command = 80 'P', procs = 134, func = 0x55555557c930 <mob_cap_damage>, freq = 100, name = 0x0, run_type = 2, term = 1, num1 = 100, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 6, line = 5, next = 0x0}
(gdb) print ch->mob_specials.func[5]
$8 = {command = 80 'P', procs = 106, func = 0x5555555b7050 <proc_entropy_tank>, freq = 33, name = 0x0, run_type = 1, term = 1, num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0,
internal = 0, line = 6, next = 0x0}
Last edit: 07 Feb 2018 02:30 by cunning. Reason: forgot a bit of code.

Please Log in or Create an account to join the conversation.

More
07 Feb 2018 05:51 #7551 by WhiskyTest
Replied by WhiskyTest on topic medit - code assistance
Please excuse me if I've misunderstood, but is your end result:
To be able to add a spec_proc to a mob via medit during runtime?
(If yes then yay, I've made a patch for that!)

Or to do something tricky with multiple commands - zone reset style?

Do you mind describing the scenario in game as the player might experience it, or how you envision it working?

Please Log in or Create an account to join the conversation.

More
07 Feb 2018 11:10 - 07 Feb 2018 11:20 #7552 by cunning
Replied by cunning on topic medit - code assistance
I do both. I load and execute multiple special procs just as in Zedit. Here is a snippet of one of the mobiles.

Code:
Mob Spec-Proc: Exists, NPC Bare Hand Dam: 9d10 Spec-Proc: proc1 Prob: 100 Term: 0 SpecNum: 9/0/0/0/0 Spec-Proc: proc2 Prob: 100 Term: 0 SpecNum: 0/0/0/0/0 Spec-Proc: proc3 Prob: 70 Term: 0 SpecNum: 0/0/0/0/0 Spec-Proc: Proc4 Prob: 33 Term: 1 SpecNum: 0/0/0/0/0 Spec-Proc: proc5 Prob: 33 Term: 1 SpecNum: 0/0/0/0/0 Spec-Proc: proc6 Prob: 33 Term: 1 SpecNum: 0/0/0/0/0 Spec-Proc: proc7 Prob: 100 Term: 1 SpecNum: 60/0/0/0/0

I have NO issue loading it into Medit and displaying:

Special Procedure menu:
Procedure Freq Type Term Num1 Num2 Num3 Num4 Num4 Resist


---- ---- ---- ---- ---- ---- ---- ----
0) Proc1 100 Normal No 9 0 0 0 0 None
1) Proc2 100 Normal No 0 0 0 0 0 None
2) Proc3 70 Normal No 0 0 0 0 0 None
3) Proc4 33 Normal No 0 0 0 0 0 None
4) Proc5 33 Normal No 0 0 0 0 0 None
5) Proc6 50 Normal No 0 0 0 0 0 None
6) Proc7 100 Combat Yes 60 0 0 0 0 Magic
7 - <END OF LIST>
N) Insert new command.
E) Edit a command.
D) Delete a command.
Q) Quit


I can choose option "N" and once I choose what line to insert, the live mobile crashes the game because we have now corrupted the first spec_proc OLC_MOB(d)->mob_specials.func[0]
Last edit: 07 Feb 2018 11:20 by cunning.

Please Log in or Create an account to join the conversation.

More
08 Feb 2018 02:19 #7560 by WhiskyTest
Replied by WhiskyTest on topic medit - code assistance
OK
Not too sure about this..
Would clearing and reassigning spec_procs after your edit help?

Does it crash if the mob is not actually loaded into the game?

Please Log in or Create an account to join the conversation.

More
08 Feb 2018 12:22 #7561 by cunning
Replied by cunning on topic medit - code assistance
IF the mobile is not in the game, no it does not crash. I have even tried to copy the procs into a temp value in OLC I call OLC_PROC(d) leaving the mob_proto alone.

Please Log in or Create an account to join the conversation.

More
08 Feb 2018 12:28 #7562 by cunning
Replied by cunning on topic medit - code assistance
I was wrong, it does crash with the mob out of the game. I now get this "Error in `/development/running_game/bin/circle': corrupted size vs. prev_size: 0x00005555564cd090 ***" I think it means my array's do not match up now.

Please Log in or Create an account to join the conversation.

Time to create page: 0.201 seconds