bool Crafter::craftable(const Item_t& it, Item_t* miss) const{ recipe rec = getRecipe(it); /*printf("rec.i = %d | i = %d\n", rec.nbIron, _nbIron); printf("rec.g = %d\n", rec.nbGold); printf("rec.r = %d\n", rec.nbRuby); */ if(rec.nbRuby > _nbRuby){ *miss = IT_RUBY; return false; } if(rec.nbGold > _nbGold){ *miss = IT_GOLD; return false; } if(rec.nbIron > _nbIron){ *miss = IT_IRON; return false; } return true; }
bool Crafter::craftAndPutIn(Item_t it){ Item_t miss = IT_NONE; recipe rec = getRecipe(it); if(!craftable(it, &miss)) return false; printf("youp\n"); _nbIron -= rec.nbIron; _nbGold -= rec.nbGold; _nbRuby -= rec.nbRuby; _output.push_back(it); return true; }
Item* Crafter::craft(Item_t it){ Item_t miss = IT_NONE; printf("craft()\n"); recipe rec = getRecipe(it); if(!craftable(it, &miss)){ printf("not enought ressources...\n"); return NULL; } printf("youp\n"); _nbIron -= rec.nbIron; _nbGold -= rec.nbGold; _nbRuby -= rec.nbRuby; return putOut(it); }
bool Crafter::craftSuper(Item_t it){ recipe rec = getRecipe(it); int ressManquante = 0; if(_nbEmerald <= 0) return false; // On detecte s'il manque une ressource if(rec.nbRuby > _nbRuby) ressManquante += (rec.nbRuby - _nbRuby); if(rec.nbGold > _nbGold) ressManquante += (rec.nbGold - _nbGold); if(rec.nbIron > _nbIron) ressManquante += (rec.nbIron - _nbIron); if(ressManquante > 1){ // On ne consomme qu'un emerald par SUPER recette return false; }else if(ressManquante == 1){ // S'il manque une seule ressource, on la remplace if(rec.nbRuby > _nbRuby){ _nbRuby -= (rec.nbRuby - 1); _nbEmerald -= 1; _nbGold -= rec.nbGold; _nbIron -= rec.nbIron; } if(rec.nbGold > _nbGold){ _nbGold -= (rec.nbGold - 1); _nbEmerald -= 1; _nbRuby -= rec.nbRuby; _nbIron -= rec.nbIron; } if(rec.nbIron > _nbIron){ _nbIron -= (rec.nbIron - 1); _nbEmerald -= 1; _nbGold -= rec.nbGold; _nbRuby -= rec.nbRuby; } }else{ // S'il ne manque pas de ressource, on remplace la plus élevée if(rec.nbRuby > 0){ _nbIron -= rec.nbIron; _nbGold -= rec.nbGold; _nbRuby -= (rec.nbRuby - 1); _nbEmerald -= 1; } else if(rec.nbGold > 0){ _nbIron -= rec.nbIron; _nbGold -= (rec.nbGold - 1); _nbRuby -= rec.nbRuby; _nbEmerald -= 1; } else if(rec.nbIron > 0){ _nbIron -= (rec.nbIron - 1); _nbGold -= rec.nbGold; _nbRuby -= rec.nbRuby; _nbEmerald -= 1; } } //_output.push_back(si); return true; }
bool saveDotaData (char const* dest) { MPQFILE file = MPQOpenFile (((CDotAReplayApp*) ::AfxGetApp ())->res, dest, MPQFILE_REWRITE); if (file) { static int hsub[256]; static int isub[512]; memset (hsub, 0, sizeof hsub); memset (isub, 0, sizeof isub); int mxh = bk_numHeroes; for (int i = 1; i < numHeroes; i++) { bool found = false; for (int j = 1; j < bk_numHeroes && !found; j++) { if (samename (heroes[i].name, bk_heroes[j].name)) { hsub[j] = i; found = true; } } if (!found) hsub[mxh++] = i; } int mxi = bk_numItems; for (int i = 1; i < numItems; i++) { bool found = false; for (int j = 1; j < bk_numItems && !found; j++) { if (items[i].type/2 == bk_items[j].type/2 && samename (items[i].name, bk_items[j].name)) { isub[j] = i; found = true; } } if (!found) isub[mxi++] = i; } MPQFilePuts (file, "[HERO]\r\n"); for (int m = 0; m < mxh; m++) { int i = hsub[m]; DotaHero* hero = &heroes[i]; MPQFilePuts (file, mprintf ("\"%s\",\"%s\",%d,\"%s\",%d,%d", hero->name, hero->oname, hero->tavern, hero->imgTag, hero->slot, hero->point)); for (int j = 0; j < 5; j++) MPQFilePuts (file, mprintf (",%s", make_id (hero->abils[j]))); for (int j = 0; j < hero->numIds; j++) MPQFilePuts (file, mprintf (",%s", make_id (hero->ids[j]))); MPQFilePuts (file, "\r\n"); } MPQFilePuts (file, "[ITEM]\r\n"); for (int m = 0; m < mxi; m++) { int i = isub[m]; DotaItem* item = getItem (i); MPQFilePuts (file, mprintf ("\"%s\",%d,\"%s\"", item->name, item->cost, item->imgTag)); for (int j = 0; j < item->numIds; j++) MPQFilePuts (file, mprintf (",%s", make_id (item->ids[j]))); MPQFilePuts (file, "\r\n"); } MPQFilePuts (file, "[ABILITY]\r\n"); for (int i = 1; i < numAbilities; i++) { DotaAbility* abil = getAbility (i); MPQFilePuts (file, mprintf ("\"%s\",%d,\"%s\"", abil->name, abil->slot, abil->imgTag)); for (int j = 0; j < abil->numIds; j++) MPQFilePuts (file, mprintf (",%s", make_id (abil->ids[j]))); MPQFilePuts (file, "\r\n"); } MPQFilePuts (file, "[RECIPE]\r\n"); for (int i = 0; i < numRecipes; i++) { DotaRecipe* recipe = getRecipe (i); MPQFilePuts (file, make_id (recipe->result)); for (int j = 0; j < recipe->numsrc; j++) MPQFilePuts (file, mprintf (",%s,%d", make_id (recipe->srcid[j]), recipe->srccount[j])); MPQFilePuts (file, "\r\n"); } MPQCloseFile (file); } else return false; MPQFlushListfile (((CDotAReplayApp*) ::AfxGetApp ())->res); return true; }