Bookless spell systems in C: is this a good approach?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Magnate
    Angband Devteam member
    • May 2007
    • 5110

    #16
    Originally posted by LostTemplar
    Old is good, it is well done and tested (not counting recent changes) code was written much better and accurately 20 years ago.
    Umm ... thanks. Have you looked at the V source recently?
    "Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles

    Comment

    • LostTemplar
      Knight
      • Aug 2009
      • 670

      #17
      I mosltly look into FAangband, and it uses quite old V code, even new versions are based on maybe two yeras old V. Everything seems ok. Some time ago I was trying to tinker with Dungeon Crawl code, and it was much harder to modify then Angband.

      Comment

      • Therem Harth
        Knight
        • Jan 2008
        • 926

        #18
        Originally posted by Magnate
        I still think you're crazy to try this on a gnarly 20-year-old C codebase when there's a brand new clean python codebase just waiting for a spell system. Ho hum.
        I'm starting to think you're right. The V sources are prettier than they used to be, but they're still an absolute mess; the stuff required to add another book-user realm is scattered through about a dozen different files. I think it might actually be easier to add bookless caster classes, than to add new spellbooks.

        BTW, can anyone tell me how to invoke the selection-friendly menu system in V? I could do something like what ToME does, i.e. just put up a block of formatted text and wait for character input; but I wanted to do this the right way, not the easy way... Assuming there is a "right way" with this codebase.

        Comment

        • takkaria
          Veteran
          • Apr 2007
          • 1951

          #19
          Originally posted by Therem Harth
          I'm starting to think you're right. The V sources are prettier than they used to be, but they're still an absolute mess; the stuff required to add another book-user realm is scattered through about a dozen different files. I think it might actually be easier to add bookless caster classes, than to add new spellbooks.

          BTW, can anyone tell me how to invoke the selection-friendly menu system in V? I could do something like what ToME does, i.e. just put up a block of formatted text and wait for character input; but I wanted to do this the right way, not the easy way... Assuming there is a "right way" with this codebase.
          There are a few different ways of invoking it. Check out the code in ui-spell.c for a decent example (and the documentation in ui-menu.h). It's a bit of a clunky API but that's largely because it's in C.
          takkaria whispers something about options. -more-

          Comment

          • Therem Harth
            Knight
            • Jan 2008
            • 926

            #20
            Okay, now that the first bookless class is almost done, two questions:
            1. What's a reasonable way to refresh the whole screen, so that the casting menu disappears properly once the spell is cast? [Sort of solved]
            2. How is command repetition handled?

            Once those are taken care of, and with a little more tweaking, my Vanilla mod will be ready to roll for the first time.

            Oh, also, two notes:
            - I wound up not using the menu system... Sorry, I had a lot of trouble figuring it out.
            - The command for using bookless powers is 'p', not 'm'. Partly because I'm too lazy to make bookless powers work with do_cmd_cast(), and partly because I might want casters with both book and bookless options in the future.

            Edit: Okay, with (1) you refresh the screen py passing stuff to p_ptr->redraw. Unfortunately I'm having trouble getting mana to redraw properly, even though PR_MANA is definitely getting passed to it (as part of PR_BASIC).
            Last edited by Therem Harth; January 11, 2013, 22:03.

            Comment

            • takkaria
              Veteran
              • Apr 2007
              • 1951

              #21
              Originally posted by Therem Harth
              Okay, now that the first bookless class is almost done, two questions:
              1. What's a reasonable way to refresh the whole screen, so that the casting menu disappears properly once the spell is cast? [Sort of solved]
              The correct way to do this is to call screen_save() before writing to the scren and screen_load() afterward. You don't have to do anything else.

              2. How is command repetition handled?
              What version of V are you modifying? It's handled in game-cmd.c in recent versions I think.
              takkaria whispers something about options. -more-

              Comment

              • Therem Harth
                Knight
                • Jan 2008
                • 926

                #22
                Originally posted by takkaria
                The correct way to do this is to call screen_save() before writing to the scren and screen_load() afterward. You don't have to do anything else.
                Tried that. The result was dead monsters showing up as alive on the screen. I think maybe I was doing something in the wrong order; let's try that again...

                What version of V are you modifying? It's handled in game-cmd.c in recent versions I think.
                3.2.0. Yes, I'm probably getting what I deserve :P

                Edit: yeah, the problem with scree_save() and screen_load() was doing things in the wrong order. Unfortunately I also have to refresh the mana display *after* casting the spell...

                Edit 2: The mana display seems to work now for some reason. OTOH, hitting the Escape key while in the casting menu causes the menu to linger on the screen; and following that, refreshing the screen renders it entirely black.

                It looks like the Escape key completely bypasses Angband's key capturing, and allows the user to exit before the saved screen is reloaded. Any way to prevent that?
                Last edited by Therem Harth; January 12, 2013, 01:29.

                Comment

                • Therem Harth
                  Knight
                  • Jan 2008
                  • 926

                  #23
                  Ugh. Okay, what I have now is something like

                  Code:
                  	screen_save();
                          ...
                  	while (get_com("Cast which spell? (Esc to exit)", &choice))
                  	{
                  		if (!choice)
                  		{
                  			screen_load();
                  			return;
                  		}
                          }
                          ...
                  This results in the menu lingering on the screen. So does

                  Code:
                  if (choice == 27)
                  What am I not understanding here?

                  Comment

                  • takkaria
                    Veteran
                    • Apr 2007
                    • 1951

                    #24
                    Originally posted by Therem Harth
                    Ugh. Okay, what I have now is something like

                    Code:
                    	screen_save();
                            ...
                    	while (get_com("Cast which spell? (Esc to exit)", &choice))
                    	{
                    		if (!choice)
                    		{
                    			screen_load();
                    			return;
                    		}
                            }
                            ...
                    This results in the menu lingering on the screen. So does

                    Code:
                    if (choice == 27)
                    What am I not understanding here?
                    There's something else going on than what you pasted because what you pasted looks fine. What's the whole function look like?
                    takkaria whispers something about options. -more-

                    Comment

                    • Therem Harth
                      Knight
                      • Jan 2008
                      • 926

                      #25
                      Trying to upload the source file as an attachment but the board won't let me, so here's the function.

                      Code:
                      void do_cmd_pyro()
                      {
                      	char choice;
                      
                      	screen_save();
                      	print_pyro_menu();
                      	while (get_com("Cast which spell? (Esc to exit)", &choice))
                      	{
                      		if (!choice)
                      		{
                      			screen_load();
                      			return;
                      		}
                      
                      		if (A2I(choice) < 0 || A2I(choice) >= MAX_PYRO_SPELLS)
                      		{
                      			msg_print("Invalid spell choice.");
                      			continue;
                      		}
                      		/* Redraw the main window */
                      		screen_load();
                      		cast_pyro_spell(A2I(choice));
                      		break;
                      	}
                      
                      	return;
                      }

                      Comment

                      • AnonymousHero
                        Veteran
                        • Jun 2007
                        • 1393

                        #26
                        get_com is probably returning false when you press ESC.

                        Comment

                        • Therem Harth
                          Knight
                          • Jan 2008
                          • 926

                          #27
                          Oh, thanks! I hadn't thought of that.

                          Edit: thank you very much, that worked. Now to figure out why the mana display is still not updating.
                          Last edited by Therem Harth; January 13, 2013, 16:05.

                          Comment

                          • Therem Harth
                            Knight
                            • Jan 2008
                            • 926

                            #28
                            Okay, got it working. Version 0.0.1 is now ready.

                            Comment

                            • takkaria
                              Veteran
                              • Apr 2007
                              • 1951

                              #29
                              Yeah, make sure that the screen_load() happens immediately before the final return of the function and you're sorted, really. That's always the best way to do saving/loading - in pairs, not with one _save and multiple _loads. It's too easy to fuck things up otherwise.

                              Originally posted by Therem Harth
                              Trying to upload the source file as an attachment but the board won't let me, so here's the function.

                              Code:
                              void do_cmd_pyro()
                              {
                              	char choice;
                              
                              	screen_save();
                              	print_pyro_menu();
                              	while (get_com("Cast which spell? (Esc to exit)", &choice))
                              	{
                              		if (!choice)
                              		{
                              			screen_load();
                              			return;
                              		}
                              
                              		if (A2I(choice) < 0 || A2I(choice) >= MAX_PYRO_SPELLS)
                              		{
                              			msg_print("Invalid spell choice.");
                              			continue;
                              		}
                              		/* Redraw the main window */
                              		screen_load();
                              		cast_pyro_spell(A2I(choice));
                              		break;
                              	}
                              
                              	return;
                              }
                              takkaria whispers something about options. -more-

                              Comment

                              Working...
                              😀
                              😂
                              🥰
                              😘
                              🤢
                              😎
                              😞
                              😡
                              👍
                              👎