Permanent* MTGPlayer_playCard(MTGPlayer* player,int cardIndex, char* err) { MTGCard* card = (MTGCard*)player->hand->entries[cardIndex]; if (card == cd.IllusoryAngel && !player->hasCastSpell) { sprintf(err, "Can play IllusoryAngel only if you have casted another spell"); return NULL; } if (card->subtypes.is_convoke) { if (player->canConvoke) { if (player == player1) { memset(player->convokeMana, 0, 6*sizeof(int)); selectConvoke(player,cardIndex); player->canConvoke = !player->canConvoke; sprintf(err,"Select creatures to convoke"); return NULL; } else { AI_selectConvoke(player, cardIndex); } } else if (player == player1) player->canConvoke = !player->canConvoke; } if (player == player1 && !MTGPlayer_payMana(player, card->manaCost)) { memset(player->convokeMana, 0, 6*sizeof(int)); sprintf(err,"Not enough mana to play %s (%d/%d)",card->name,player->mana[0],card->cmc); return NULL; } else if (player == player2 && !AI_payMana(card->manaCost)) { memset(player->convokeMana, 0, 6*sizeof(int)); return NULL; } memset(player->convokeMana, 0, 6*sizeof(int)); if (card->subtypes.is_land && player->playedLand) { sprintf(err,"You can only play one Land per turn"); return NULL; } //create permanent Permanent* permanent = NewPermanent(card,player); //apply card effects if (card->subtypes.is_land) { player->playedLand = true; AppendToList(player->lands, permanent); } else AppendToList(stack, permanent); //remove card from hand RemoveListIndex(player->hand,cardIndex); return permanent; }
bool MTGPlayer_activateAbility(MTGPlayer* player,Permanent* permanent,char* err) { Ability* a = permanent->abilities->entries[permanent->selectedAbility-1]; if (permanent->subtypes.is_planeswalker) { Manacost *m = a->manaCost->entries[0]; if (permanent->is_activated) { sprintf(err,"%s is already activated",permanent->name); return false; } else if (permanent->loyalty + m->num < 0) { sprintf(err,"Not enough loyalty to activate %s",permanent->name); return false; } else { permanent->is_activated = true; permanent->loyalty += m->num; RemoveListObject(player->battlefield, permanent); AppendToList(stack, permanent); return true; } } if (a->needs_tap) { if (permanent->has_summoning_sickness) { sprintf(err, "%s has summoning sickness!",permanent->name); return false; } else if (permanent->is_tapped) { sprintf(err, "%s is already tapped!",permanent->name); return false; } } if (permanent->equipment) { for (unsigned int i=0;i<permanent->equipment->size;i++) { Permanent* q = permanent->equipment->entries[i]; if (q->source == cd.Encrust) { sprintf(err,"%s cannot use abilities (%s)",permanent->name,q->name); return false; } } } if ((player==player1 && MTGPlayer_payMana(player,a->manaCost)) || (player==player2 && AI_payMana(a->manaCost))) { if (a->needs_tap) permanent->is_tapped = true; if (a->lifeCost > 0) Event_loseLife(permanent, player, a->lifeCost); RemoveListObject(player->battlefield, permanent); AppendToList(stack, permanent); return true; } else { sprintf(err,"Not enough mana to activate %s",permanent->name); return false; } }
List* IntersectList(List* lsa, List* lsb) { if (!lsa||!lsb) { return NULL; } List* combined = InitList(); //IMPROVE algorithm later //TODO intersect lists with repeats, color highlight correct word unsigned int i,j; for (i = 0; i < lsa->size; i++) { printf("lsa: %p\n",GetListItem(lsa,i)); } for (i = 0; i < lsb->size; i++) { printf("lsb: %p\n",GetListItem(lsb,i)); } for (i = 0; i < lsa->size; i++) { for (j = 0; j < lsb->size; j++) { void* p = GetListItem(lsa, i); if (GetListItem(lsb, j) == p) { AppendToList(combined, p); } } } for (i = 0; i < combined->size; i++) { printf("combined: %p\n",GetListItem(combined,i)); } return combined; }
//-------------------------------------------------------------------------------- // CArrayIterator::init(4) //-------------------------------------------------------------------------------- Boolean CArrayIterator::init(CDynamicArray* itsDynamicArray, ArrayIndex itsLowBound, ArrayIndex itsHighBound, Boolean itsForward) { if (!super::init()) return false; require(itsDynamicArray, Fail); fNextLink = this; fPreviousLink = this; fDynamicArray = itsDynamicArray; // link me in to the list of iterations in progress fDynamicArray->fIterator = AppendToList(fDynamicArray->fIterator); // sanity check the bounds InitBounds(itsLowBound, itsHighBound, itsForward); return true; Fail: return false; } // CArrayIterator::init
bool MTGPlayer_drawCards(MTGPlayer* p,int num) { if (p->library->size < num) return false; for (int i=0;i<num;i++) { AppendToList(p->hand,p->library->entries[p->library->size-1-i]); } p->library->size -=num; return true; }
bool MTGPlayer_tap(MTGPlayer* player,Permanent* permanent) { List* options = InitList(); char buffer[256]; char* c = buffer; for (unsigned int i=0;i<permanent->abilities->size;i++) { char* s = c; Ability* a = permanent->abilities->entries[i]; for (unsigned int j=0;j<a->manaCost->size;j++) { Manacost* m = a->manaCost->entries[j]; char color; switch (m->color1) { case WHITE: color = 'W'; break; case BLUE: color = 'U'; break; case BLACK: color = 'B'; break; case RED: color = 'R'; break; case GREEN: color = 'G'; break; case COLORLESS: color = ' '; break; } c += sprintf(c,"{%d%c}",m->num,color); } c += sprintf(c,"%s",a->needs_tap?"{T}":"") + 1; AppendToList(options, s); } if (permanent->subtypes.is_land) { if (permanent->subtypes.is_plains) AppendToList(options, "W"); if (permanent->subtypes.is_island) AppendToList(options, "U"); if (permanent->subtypes.is_swamp) AppendToList(options, "B"); if (permanent->subtypes.is_mountain) AppendToList(options, "R"); if (permanent->subtypes.is_forest) AppendToList(options, "G"); if (permanent->source == cd.DarksteelCitadel) AppendToList(options, "C"); permanent->is_tapped = true; } if (options->size > 1) { if (player == player1) selectAbility(permanent,options); else AI_selectAbility(permanent,options); DeleteList(options); return false; } else { permanent->selectedAbility = 1; DeleteList(options); return true; } }
void loadDeck(char* name,List* cards) { char buffer[128]; FILE* file = fopen(name,"r"); if (!file) return; while (fgets(buffer,128,file)) { MTGCard* card = (MTGCard*) HashTable_findVar(cdt,buffer,strlen(buffer) - 1); AppendToList(cards,card); } fclose(file); }
void MTGPlayer_discardFromBattlefield(MTGPlayer* player,int cardIndex,Destination dest) { Permanent* p; if (cardIndex >= 0) p = MTGPlayer_getBattlefieldPermanent(player->battlefield, cardIndex); else p = player->lands->entries[-cardIndex - 1]; Event_onDestroy(p,dest); if (p->equipment) { for (unsigned int j=0;j<p->equipment->size;j++) { Permanent* q = p->equipment->entries[j]; if (q->subtypes.is_equipment) { q->target = NULL; AppendToList(q->owner->battlefield, q); } else { Event_onDestroy(q,GRAVEYARD); AppendToList(q->owner->graveyard, q->source); DeletePermanent(q); } } DeleteList(p->equipment); } if (p->abilities) DeleteList(p->abilities); if (p->source) AppendToList(dest==EXILE?player->exile:dest==GRAVEYARD?player->graveyard:player->hand,p->source); //remove card from battlefield if (p->subtypes.is_aura) RemoveListObject(p->target->equipment, p); else if (p->subtypes.is_equipment && p->target) RemoveListObject(p->target->equipment, p); else if (cardIndex >= 0) RemoveListObject(player->battlefield, p); else RemoveListIndex(player->lands, -cardIndex - 1); free(p); }
static void sub_8089A8C(void) { sPokeMenuOptionsNo = 0; // if checking pokemon is an egg, we can't give it an item and it doesn't know any move if (GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_IS_EGG)) { AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_SUMMARY); AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_SWITCH); AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_CANCEL); } else { u16 moveID, tableID; for (moveID = 0; moveID < 4; moveID++) // 4, max number of possible field moves { for (tableID = 0; sPokeMenuFieldMoves[tableID] != sFieldMovesTerminator; tableID++) { if (GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_MOVE1 + moveID) == sPokeMenuFieldMoves[tableID]) { u8 fieldID = tableID + POKEMENU_FIRST_FIELD_MOVE_ID; AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, fieldID); break; } } } AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_SUMMARY); // can't switch a pokemon if it's the only one in the party if (GetMonData(&gPlayerParty[1], MON_DATA_SPECIES) != 0) AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_SWITCH); if (ItemIsMail(GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_HELD_ITEM))) AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_MAIL); else AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_ITEM); AppendToList(sPokeMenuOptionsOrder, &sPokeMenuOptionsNo, POKEMENU_CANCEL); } }
int AddToMap(Map* mp, char* key, void* value) { if (!mp) return 0; List* ls = FindInHashTable(mp->tb,key); if (!ls) { ls = InitList(); if (!InsertIntoHashTable(mp->tb,key,ls)) { printf("Warning(Map): cannot insert %s into hash table!\n",key); return 0; } mp->size++; } if (!AppendToList(ls,value)) { printf("Warning(Map): cannot append to list!\n"); return 0; } return 1; }
static void AppendToConfig(const char *s) { AppendToList(s, &builtinConfig, &builtinLines); }
VolumePropertiesDialog::VolumePropertiesDialog (wxWindow* parent, const VolumeInfo &volumeInfo) : VolumePropertiesDialogBase (parent) { list <int> colPermilles; PropertiesListCtrl->InsertColumn (0, LangString["PROPERTY"], wxLIST_FORMAT_LEFT, 208); colPermilles.push_back (500); PropertiesListCtrl->InsertColumn (1, LangString["VALUE"], wxLIST_FORMAT_LEFT, 192); colPermilles.push_back (500); Gui->SetListCtrlWidth (PropertiesListCtrl, 70, false); Gui->SetListCtrlHeight (PropertiesListCtrl, 17); Gui->SetListCtrlColumnWidths (PropertiesListCtrl, colPermilles, false); AppendToList ("LOCATION", wstring (volumeInfo.Path)); #ifndef TC_WINDOWS AppendToList ("VIRTUAL_DEVICE", wstring (volumeInfo.VirtualDevice)); #endif AppendToList ("SIZE", Gui->SizeToString (volumeInfo.Size)); AppendToList ("TYPE", Gui->VolumeTypeToString (volumeInfo.Type, volumeInfo.TrueCryptMode, volumeInfo.Protection)); AppendToList ("READ_ONLY", LangString [volumeInfo.Protection == VolumeProtection::ReadOnly ? "UISTR_YES" : "UISTR_NO"]); wxString protection; if (volumeInfo.Type == VolumeType::Hidden) protection = LangString["NOT_APPLICABLE_OR_NOT_AVAILABLE"]; else if (volumeInfo.HiddenVolumeProtectionTriggered) protection = LangString["HID_VOL_DAMAGE_PREVENTED"]; else protection = LangString [volumeInfo.Protection == VolumeProtection::HiddenVolumeReadOnly ? "UISTR_YES" : "UISTR_NO"]; AppendToList ("HIDDEN_VOL_PROTECTION", protection); AppendToList ("ENCRYPTION_ALGORITHM", volumeInfo.EncryptionAlgorithmName); AppendToList ("KEY_SIZE", StringFormatter (L"{0} {1}", volumeInfo.EncryptionAlgorithmKeySize * 8, LangString ["BITS"])); if (volumeInfo.EncryptionModeName == L"XTS") AppendToList ("SECONDARY_KEY_SIZE_XTS", StringFormatter (L"{0} {1}", volumeInfo.EncryptionAlgorithmKeySize * 8, LangString ["BITS"])); wstringstream blockSize; blockSize << volumeInfo.EncryptionAlgorithmBlockSize * 8; if (volumeInfo.EncryptionAlgorithmBlockSize != volumeInfo.EncryptionAlgorithmMinBlockSize) blockSize << L"/" << volumeInfo.EncryptionAlgorithmMinBlockSize * 8; AppendToList ("BLOCK_SIZE", blockSize.str() + L" " + LangString ["BITS"]); AppendToList ("MODE_OF_OPERATION", volumeInfo.EncryptionModeName); if (volumeInfo.Pim <= 0) AppendToList ("PKCS5_PRF", volumeInfo.Pkcs5PrfName); else AppendToList ("PKCS5_PRF", StringFormatter (L"{0} (Dynamic)", volumeInfo.Pkcs5PrfName)); #if 0 AppendToList ("PKCS5_ITERATIONS", StringConverter::FromNumber (volumeInfo.Pkcs5IterationCount)); AppendToList ("VOLUME_CREATE_DATE", Gui->VolumeTimeToString (volumeInfo.VolumeCreationTime)); AppendToList ("VOLUME_HEADER_DATE", Gui->VolumeTimeToString (volumeInfo.HeaderCreationTime)); #endif AppendToList ("VOLUME_FORMAT_VERSION", StringConverter::ToWide (volumeInfo.MinRequiredProgramVersion < 0x10b ? 1 : 2)); AppendToList ("BACKUP_HEADER", LangString[volumeInfo.MinRequiredProgramVersion >= 0x10b ? "UISTR_YES" : "UISTR_NO"]); #ifdef TC_LINUX if (string (volumeInfo.VirtualDevice).find ("/dev/mapper/veracrypt") != 0) { #endif AppendToList ("TOTAL_DATA_READ", Gui->SizeToString (volumeInfo.TotalDataRead)); AppendToList ("TOTAL_DATA_WRITTEN", Gui->SizeToString (volumeInfo.TotalDataWritten)); #ifdef TC_LINUX } #endif Layout(); Fit(); Center(); StdButtonsOK->SetDefault(); }
void MTGPlayer_discard(MTGPlayer* player,int cardIndex) { AppendToList(player->graveyard, player->hand->entries[cardIndex]); //remove card from hand RemoveListIndex(player->hand, cardIndex); }
void ErrorWindow::MessageReceived(BMessage* message) { switch (message->what) { case M_RUN_PROJECT: case M_RUN_IN_TERMINAL: case M_RUN_IN_DEBUGGER: case M_RUN_WITH_ARGS: case M_MAKE_PROJECT: case M_FORCE_REBUILD: { fParent->PostMessage(message); break; } case M_TOGGLE_ERRORS: case M_TOGGLE_WARNINGS: { RefreshList(); break; } case M_COPY_ERRORS: { CopyList(); break; } case M_CLEAR_ERROR_LIST: { EmptyList(); fErrors.msglist.MakeEmpty(); break; } case M_BUILD_WARNINGS: case M_BUILD_FAILURE: { ErrorList list; list.Unflatten(*message); AppendToList(list); break; } case M_JUMP_TO_MSG: { int32 selection = fErrorList->CurrentSelection(); if (selection >= 0) { ErrorItem* item = (ErrorItem*)fErrorList->ItemAt(selection); error_msg* gcc = item->GetMessage(); if (gcc->path.Length() < 1) break; entry_ref ref; BEntry entry(gcc->path.String()); entry.GetRef(&ref); message->what = EDIT_OPEN_FILE; message->AddRef("refs", &ref); if (gcc->line > 0) message->AddInt32("line", gcc->line); be_app->PostMessage(message); } break; } default: BWindow::MessageReceived(message); } }