It is currently 16 Apr 2024, 17:34
   
Text Size

new_global_tutor: return values, return tutored card

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

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

new_global_tutor: return values, return tutored card

Postby FastEddie » 16 Aug 2020, 15:57

I had a closer look at new_global_tutor() related to these two bug fixes:

https://www.slightlymagic.net/forum/viewtopic.php?f=86&t=29382
https://www.slightlymagic.net/forum/viewtopic.php?f=86&t=21113

It turned out that I didn't properly understand the function (to be expected). Therefore this little write-up. The same stuff can be found in tutors.c.

new_global_tutor has the following return values:
    -1 if tutoring got cancelled (manually or because the test didn't pass)
    Otherwise:
      If test.qty > 1: number of cards that were actually tutored
      If test.qty == 1: some positive number if turoting was succesful
If you want to return the iid(s) of the tutored card(s) you can't use the return value (this was basically the issue with the two cards mentioned above). Instead you have to specify the card used as storage in test.storage. targets[].card will be used starting from targets[0], only card is stored.

Based on that I rewrote Saheeli Rai, Three Dreams and Uncage the Menagerie in a way that is more in line with what the developers intented when writing new_global_tutor. Gifts Ungiven is indeed different as the cards go to a separate zone in the meanwhile, therefore I didn't touch it (it needs a little clean-up, will do this seperately).

Saheeli Rai:
Code: Select all
      if( choice == CHOICE_THREE_ARTIFACTS ){
         int chosen[3] = {-1, -1, -1};

         test_definition_t test;
         default_test_definition(&test, TYPE_ARTIFACT);
         test.value_for_special_selection_function = (int)chosen;
         test.special_selection_function = test_not_in_array3;
         test.qty = 1;
         test.no_shuffle = 1;
         test.storage = card;

         int num_chosen;
         for (num_chosen = 0; num_chosen < 3; ++num_chosen)
         {
            if (ai_is_speculating != 1){
               sprintf(test.message, "Select up to three artifact cards with different names. Card #%d of up to 3", num_chosen + 1);
            }
            int pos = new_global_tutor(player, player, TUTOR_FROM_DECK, TUTOR_HAND, 0, AI_MAX_CMC, &test);
            if (pos > -1) {
               chosen[num_chosen] = get_card_instance(player, card)->targets[0].card;
            } else {
               break;
            }
            remove_card_from_deck(player, pos);
         }
         shuffle(player);
      }
Three Dreams:
Code: Select all
   if (event == EVENT_RESOLVE_SPELL ){
      int chosen[3] = {-1, -1, -1};
      int num_chosen;
      
      test_definition_t test;
      default_test_definition(&test, TYPE_ENCHANTMENT);

      test.no_shuffle = 1;
      test.value_for_special_selection_function = (int)chosen;
      test.special_selection_function = test_not_in_array3;
      test.storage = card;

      for (num_chosen = 0; num_chosen < 3; ++num_chosen){
         if (ai_is_speculating != 1){
            sprintf(test.message, "Select up to three Aura cards with different names. Card #%d of up to 3", num_chosen + 1);
         }
         int pos = new_global_tutor(player, player, TUTOR_FROM_DECK, TUTOR_HAND, 0, AI_MAX_VALUE, &test);
         if (pos > -1) {
            chosen[num_chosen] = get_card_instance(player, card)->targets[0].card;
         } else {
            break;
         }
         remove_card_from_deck(player, pos);
      }
      shuffle(player);

      kill_card(player, card, KILL_DESTROY);
   }
Uncage the Menagerie:
Code: Select all
   if( event == EVENT_RESOLVE_SPELL ){
      card_instance_t* instance = get_card_instance(player, card);
      if( instance->info_slot > 0){
         int chosen[20];
         memset( chosen, -1, sizeof(chosen) );
         int num_chosen;
         for (num_chosen = 0; num_chosen < instance->info_slot; ++num_chosen){
            test_definition_t test;
            char buffer[100];
            scnprintf(buffer, 100, "Select creature cards with different names that each have CMC %d. Card %d of up to %d", instance->info_slot, (num_chosen+1), instance->info_slot);
            new_default_test_definition(&test, TYPE_CREATURE, buffer);
            test.cmc = instance->info_slot;
            test.value_for_special_selection_function = (int)chosen;
            test.special_selection_function = test_not_in_array20;
            test.no_shuffle = 1;
            test.storage = card;

            int pos = new_global_tutor(player, player, TUTOR_FROM_DECK, TUTOR_HAND, 0, AI_MAX_VALUE, &test);
            if (pos > -1) {
               chosen[num_chosen] = get_card_instance(player, card)->targets[0].card;
            } else {
               break;
            }
            remove_card_from_deck(player, pos);
         }
         shuffle(player);
      }
      kill_card(player, card, KILL_DESTROY);
   }
Attachments
tutors.zip
(845 Bytes) Downloaded 199 times
ravnica.zip
(949 Bytes) Downloaded 202 times
kaladesh.zip
(788 Bytes) Downloaded 196 times
hour_of_devastation.zip
(653 Bytes) Downloaded 196 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: new_global_tutor: return values, return tutored card

Postby Aswan jaguar » 23 Aug 2020, 16:45

Does new_global_tutor add anything more to these cards so to commit them again?
If not they are good as they are.
---
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: new_global_tutor: return values, return tutored card

Postby FastEddie » 23 Aug 2020, 17:32

No, it just streamlined the code. new_global_tutor should do the job, no need to work around with select_card_from_hand. But Drool66 informed me that these don't work (which is weird because in my local version it did), so something changed in the background. I will into that again and give an update here.
---
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


Return to Development

Who is online

Users browsing this forum: No registered users and 25 guests


Who is online

In total there are 25 users online :: 0 registered, 0 hidden and 25 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 25 guests

Login Form