It is currently 18 Apr 2024, 04:11
   
Text Size

Updating card rules text in Mananlink source files possible?

Discuss Upcoming Releases, Coding New Cards, Etc.
PLEASE DO NOT REPORT BUGS HERE!

Moderators: BAgate, drool66, Aswan jaguar, gmzombie, stassy, CCGHQ Admins

Updating card rules text in Mananlink source files possible?

Postby Aswan jaguar » 09 Sep 2020, 14:28

Korath is it possible and without much effort to have your automated scripts for cards text rules to change also the cards rules text that is in manalink source files ( apocalypse.c,.......) when there are oracle changes in text rules like you do for Manalink.csv?
And also keep the valuable ~ instead of card's name if not in cards name in the title? I know some or a lot are not updated but I did put updated(mostly) rules text to all of the ones that are coded (and didn't have) for all card set source files.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: Updating card rules text in Mananlink source files possi

Postby Korath » 09 Sep 2020, 17:13

Not easily - I do it manually in Shandalar source - though I suppose it's possible. (Much harder in Manalink because the comments aren't formatted consistently.) I don't think it's a good idea to do it automatically, in any case: if the commented rules text is different from the Oracle text, it's a hint that the card's implementation is out of date, too, and might need to be updated.

Usually I try to mention any functional changes in the commit comment when updating Oracle text (see e.g. git log -n1 09d4d25b8), but I wouldn't rely on that to be comprehensive.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: Updating card rules text in Mananlink source files possi

Postby Aswan jaguar » 09 Sep 2020, 19:48

Korath wrote:I don't think it's a good idea to do it automatically, in any case: if the commented rules text is different from the Oracle text, it's a hint that the card's implementation is out of date, too, and might need to be updated.
I thought about that and I agree to a point with you. There were 2 things that made me ask for this first is of course to save time as some changes affect a lot of cards like the one with "mill' ability change for Bruvac the Grandiloquent which affects around +150 cards whose cards rules were changed. Secondly, ( as long as I know what needs to be fixed that is ) for me it is easier when I have the rules text already changed in the source files to search for those cards to fix instead of having a separate list from gatherer or elsewhere.
Korath wrote:Usually I try to mention any functional changes in the commit comment when updating Oracle text
Very, very helpful you brought to my attention a lot of changes this way.
Korath wrote:but I wouldn't rely on that to be comprehensive
Of course I can't expect you to be thoroughly comprehensive and type everything in comments. Still, they are a great help.

If you do it manually on shandalar source whose comments are consistent then certainly it is the only way for Manalink.

By the way if you have a way for me to search for card rules text in manalink source that don't have "~" but still use name when "~" should better be used instead it would be a great help even if I don't get all of those. I do change those I meet when do other stuff but still must be a lot.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: Updating card rules text in Mananlink source files possi

Postby Korath » 09 Sep 2020, 20:29

The mill wording change was one of the worst. Something like 230 nonfunctional card changes, with three functional changes quietly hidden amongst them. And it was coupled with a rules update that made me have to inspect each manually anyway. I don't trust the "Here's what's changed lately in Gatherer!" announcements to be comprehensive, either.

The logic for replacing <cardname> with ~ is in magic_updater/generate-cards-txt.pl. But it'd be easier to just run that and compare its output to the comments.

(As long as you're fiddling with card text comments, please, please move them out of the first column when they're inside functions. It confuses the bejeezus out of git grep -p and the equivalent functionality in git diff.)
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: Updating card rules text in Mananlink source files possi

Postby Aswan jaguar » 10 Sep 2020, 08:22

Korath wrote:As long as you're fiddling with card text comments, please, please move them out of the first column when they're inside functions
Please give me an example of card text comments being an issue and them not being an issue to see what I can do.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: Updating card rules text in Mananlink source files possi

Postby Korath » 10 Sep 2020, 14:34

Code: Select all
$ git grep -p 'untapped Wizard' src/cards/
src/cards/champions_of_kamigawa.c=Legendary Creature - Human Wizard 0/2
src/cards/champions_of_kamigawa.c:Tap an untapped Wizard you control: Draw a card. */
src/cards/champions_of_kamigawa.c:              if( new_pick_target(&td, "Select an untapped Wizard you control.", 0, 1 | GS_LITERAL_PROMPT) ){
src/cards/commander_2017.c=int card_teferis_protection(int player, int card, event_t event){
src/cards/commander_2017.c: * Tap an untapped Wizard you control: Return target nonland permanent you don't control to its owner's hand. */
src/cards/commander_2017.c=int card_inalla_archmage_ritualist(int player, int card, event_t event){
src/cards/commander_2017.c: * Tap five untapped Wizards you control: Target player loses 7 life. */
src/cards/morningtide.c=Creature - Merfolk Wizard 2/2
src/cards/morningtide.c:|1|U, Tap two untapped Wizards you control: Copy target instant or sorcery spell. You may choose new targets for the copy. */
src/cards/odissey.c=int card_patron_wizard(int player, int card, event_t event){
src/cards/odissey.c:     * Tap an untapped Wizard you control: Counter target spell unless its controller pays |1. */
src/cards/odissey.c:            if( new_pick_target(&td2, "Select an untapped Wizard you control.", 0, 1 | GS_LITERAL_PROMPT) ){
src/cards/onslaught.c=Creature — Human Wizard 1/1
src/cards/onslaught.c:Tap two untapped Wizards you control: Tap target permanent.
src/cards/onslaught.c=Creature - Human Wizard 1/3
src/cards/onslaught.c:Tap five untapped Wizards you control: Search target player's library for up to five cards and exile them. Then that player shuffles his or her library.*/
Compare the hits in odissey.c, which shows the containing function name, to all the others.

The two in commander_2017.c do show a function name... but they're misleading. Only one of them is inside the named function, and the other is at global scope, with the function name shown that of the most recent preceding function. There's no way to tell which is which. Normally grep hits that look like these only happen at global scope, and you can't count on that in Manalink.

For diff, compare the @@ hunk header lines in
Code: Select all
$ git diff b24778a33^!
diff --git a/src/cards/aether_revolt.c b/src/cards/aether_revolt.c
index c32045674..be2c411db 100644
--- a/src/cards/aether_revolt.c
+++ b/src/cards/aether_revolt.c
@@ -713,9 +713,10 @@ At the beginning of combat on your turn, if you control an Ajani planeswalker, p
                int c = active_cards_count[player]-1;
                while( c > -1 ){
                                if( in_play(player, c) ){
-                                       if( is_planeswalker(player, c) && has_subtype(player, c, SUBTYPE_AJANI) )
+                                       if( is_planeswalker(player, c) && has_subtype(player, c, SUBTYPE_AJANI) ){
                                                add_counters(player, card, COUNTER_P1_P1, 1);
                                                break;
+                                       }
                                }
                                c--;
                }
and
Code: Select all
$ git diff 0a5d799a5^!
diff --git a/src/cards/antiquities.c b/src/cards/antiquities.c
index 700b656be..f5eb8e6c4 100644
--- a/src/cards/antiquities.c
+++ b/src/cards/antiquities.c
@@ -2005,21 +2005,18 @@ int card_shapeshifter2(int player, int card, event_t event){
         * ~'s power is equal to the last chosen number and its toughness is equal to 7 minus that number. */

        if (card == -1){
-               // While not on the bf, no number has been chosen; so power is 0 and toughness is 7.
-               if (event == EVENT_TOUGHNESS && affect_me(player, card)){
-                       event_result += 7;
-               }
+               // While not on the bf, no number has been chosen; so power is 0 and toughness is 7 ( which is checked in ct_all so don't put it also here ).
                return 0;
        }

        card_instance_t *instance = get_card_instance(player, card);

        if( event == EVENT_POWER && affect_me(player, card) && instance->targets[1].player > -1 ){
-               event_result=instance->targets[1].player;
+               event_result+= instance->targets[1].player;
        }

        if( event == EVENT_TOUGHNESS && affect_me(player, card) && instance->targets[1].card > -1 ){
-               event_result=instance->targets[1].card;
+               event_result+= instance->targets[1].card - get_base_toughness(player, card);
        }

        if( event == EVENT_RESOLVE_SPELL || event == EVENT_UPKEEP_TRIGGER_ABILITY ){
@@ -2054,7 +2051,6 @@ int card_shapeshifter2(int player, int card, event_t event){
        return 0;
 }

-
 int card_shatterstorm(int player, int card, event_t event){
 /* CARD_ID_SHATTERSTORM        526
 Shatterstorm   |2|R|R
It's even more striking with the -W switch, though I rarely use that.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: Updating card rules text in Mananlink source files possi

Postby Aswan jaguar » 10 Sep 2020, 16:13

So the margin from left of card's rules text has to be in accordance with the code when inside the function right?
I was terrified that you meant this. I am by far the bigger offender for this but on my defense that was already there in some cards and you didn't warn me about this from the beginning or any time later when I started to add rules text to source files and there must be few hundreds of commits with card rules text I committed and have started those from early February 2019. :(
Possibly around 60-70 percent of all coded cards! :shock:
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: Updating card rules text in Mananlink source files possi

Postby FastEddie » 10 Sep 2020, 16:29

If you need to bulk indent several lines of code I can recommend using Notepad++. Open the file, press Shift+Alt, mark the relevant lines with Cursor Down and when you got all of them insert a Space (or more, depends). Assuming of course that the "wrong" indention is the same across a block of text.

This helps only a bit, of course, but at least you don't have to touch every single line by hand... :|
---
Argivian Archaeologist in the Library of Leng studying the Spells of the Ancients
User avatar
FastEddie
 
Posts: 246
Joined: 24 Dec 2019, 10:59
Has thanked: 15 times
Been thanked: 19 times

Re: Updating card rules text in Mananlink source files possi

Postby Aswan jaguar » 10 Sep 2020, 16:36

Thanks for trying to help FastEddie, I do work with notepad++ and just discovered that mark and then tab once is perfect if...
I am attaching an example text file with fixed rules text Korath please check if that's fine.
Attachments
shift rules text to code.txt
(387 Bytes) Downloaded 227 times
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: Updating card rules text in Mananlink source files possi

Postby Korath » 10 Sep 2020, 16:42

FastEddie wrote:I can recommend using Notepad++
(Or emacs, the Editor of Kings. Or vim, the Editor of People Frustrated With Emacs Being Sluggish. Or anything usable, really. You shouldn't ever be indenting C-like source manually.)

In any case, this is an annoyance. A significant annoyance, yes, but only an annoyance. The sort of thing to do in the future as you're editing existing comments anyway, not reason to auto-indent every file without looking at them and potentially hide bugs like the one the b24778a33 diff above fixes.
Aswan jaguar wrote:please check if that's fine.
Yes, thank you.

Back on topic, emacs, and vim, and presumably Notepad++ or any other usable editor, will let you make a macro to copy a card name in the current pane (or tab, I suppose), move to another pane containing generate-cards-txt.pl output, find the appropriate entry, copy it, move back into the original tab, insert it, auto-comment it, and auto-indent it all with one keypress.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: Updating card rules text in Mananlink source files possi

Postby Aswan jaguar » 10 Sep 2020, 17:08

For the other comments inside card functions above code lines that explain the code is the same drill. But what about those comments that are at the end of lines always inside functions are those ok?
example:
Code: Select all
     else   // no more room in targets; just add the counter now
      add_counter(damage->damage_source_player, damage->damage_source_card, COUNTER_GOLD);
   }
As you say and have seen in git I have already started editing existing comments for "~" so I will try to fix as many of these as well while doing so.

Of course drool66 you will have to follow this while coding new cards so we don't do extra work afterwards.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: Updating card rules text in Mananlink source files possi

Postby Korath » 10 Sep 2020, 17:24

They're fine, and not relevant to this (unless that "else" or "add_counter" were at the start of a line). cpp hunk-header detection basically looks for either a letter or underscore in the first column; or a pair of colons, optional whitespace, then a letter or underscore. There's also some logic to keep it from matching jump labels. https://github.com/git/git/blob/master/userdiff.c#L177 if you happen to grok regex.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: Updating card rules text in Mananlink source files possi

Postby FastEddie » 11 Nov 2020, 14:19

So the margin from left of card's rules text has to be in accordance with the code when inside the function right?
I was terrified that you meant this. [...]
Possibly around 60-70 percent of all coded cards! :shock:
As I have some time on my hands right now I wrote a short Python script that does the job (since I don't speak Perl after trying a couple of times this my currently my script language of choice). It indents comments following a card function header (something starting with "int card_") by one tab (or if you prefer you can use one space). So
Code: Select all
int card_benalish_cavalry(int player, int card, event_t event){
/* CARD_ID_BENALISH_CAVALRY   8486
Benalish Cavalry   |1|W
Creature - Human Knight 2/2
Flanking (Whenever a creature without flanking blocks this creature, the blocking creature gets -1/-1 until end of turn.) */

  flanking(player, card, event);
  return 0;
}
becomes
Code: Select all
int card_benalish_cavalry(int player, int card, event_t event){
   /* CARD_ID_BENALISH_CAVALRY   8486
   Benalish Cavalry   |1|W
   Creature - Human Knight 2/2
   Flanking (Whenever a creature without flanking blocks this creature, the blocking creature gets -1/-1 until end of turn.) */

  flanking(player, card, event);
  return 0;
}
Formatting all cards took a couple of seconds at best. I will commit the script once we sorted the git out, here it is for the meanwhile.

If we require indentation by one tab consistently (or one space or whatever) this is no issue either.
Attachments
formatCardComments.zip
(705 Bytes) Downloaded 215 times
---
Argivian Archaeologist in the Library of Leng studying the Spells of the Ancients
User avatar
FastEddie
 
Posts: 246
Joined: 24 Dec 2019, 10:59
Has thanked: 15 times
Been thanked: 19 times

Re: Updating card rules text in Mananlink source files possi

Postby Aswan jaguar » 11 Nov 2020, 16:03

Nice, but a bit late as I have committed this specific change and all other comment changes to possibly "all" of the cards and functions. If Korath can run any test with grep or whatever and tell me where I have failed (probably I have missed some) I will fix those, too.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: Updating card rules text in Mananlink source files possi

Postby FastEddie » 11 Nov 2020, 16:53

Ah, and because we live on different branches I didn't see them. I saw that a lot of comments changed but also a bunch that still was in the first column.
---
Argivian Archaeologist in the Library of Leng studying the Spells of the Ancients
User avatar
FastEddie
 
Posts: 246
Joined: 24 Dec 2019, 10:59
Has thanked: 15 times
Been thanked: 19 times

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 21 guests


Who is online

In total there are 21 users online :: 0 registered, 0 hidden and 21 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 21 guests

Login Form