From 9b5686b40ccd1fbe85a526f255813a607d21ffea Mon Sep 17 00:00:00 2001 From: mateuszb Date: Fri, 3 Aug 2007 13:56:36 +0000 Subject: [PATCH] * choosing random creature generators * fixed bug in CPreGame --- CAmbarCendamo.cpp | 267 +++++++++++++++++++++++++++++++++++++++++++++- CPreGame.cpp | Bin 115098 -> 115432 bytes 2 files changed, 262 insertions(+), 5 deletions(-) diff --git a/CAmbarCendamo.cpp b/CAmbarCendamo.cpp index b59a3a8a3..783cf3a50 100644 --- a/CAmbarCendamo.cpp +++ b/CAmbarCendamo.cpp @@ -2016,11 +2016,38 @@ void CAmbarCendamo::processMap(std::vector & defsToUnpack) std::vector town1DefNames; //with fort std::vector town1DefNumbers; - for(int dd=0; dd<9; ++dd) + for(int dd=0; dddobjinfo->objs[dd+385].defName); town1DefNumbers.push_back(-1); } + + std::vector< std::vector > creGenNames; + std::vector< std::vector > creGenNumbers; + creGenNames.resize(F_NUMBER); + creGenNumbers.resize(F_NUMBER); + + for(int ff=0; ffdobjinfo->objs[395+7*ff+dd].defName); + creGenNumbers[ff].push_back(-1); + } + } + + for(int dd=0; dd<7; ++dd) + { + creGenNumbers[8].push_back(-1); + } + + creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName); + creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName); + creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[455].defName); + creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName); + creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName); + creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName); + creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[459].defName); //variables initialized for(int j=0; jobjh->objInstances.size(); ++j) @@ -2511,8 +2538,238 @@ void CAmbarCendamo::processMap(std::vector & defsToUnpack) } } //end of main switch } //end of main loop - //for(int j=0; jobjh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent) - //{ - // DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber]; - //} + for(int j=0; jobjh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent) + { + DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber]; + switch(getDefType(curDef)) + { + case EDefType::CREGEN_DEF: + { + if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->asCastle) + { + DefInfo nxt = curDef; + nxt.bytes[16] = 17; + for(int vv=0; vvobjh->objInstances.size(); ++vv) + { + if(getDefType(map.defy[CGI->objh->objInstances[vv].defNumber])==EDefType::TOWN_DEF) + { + if( + ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[0]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[0] + && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[1]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[1] + && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[2]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[2] + && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[3]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[3]) + { + for(int mm=0; mmobjh->objInstances[vv].defNumber].name; + std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper); + if(town1DefNames[mm]==hlp) + { + nxt.bytes[20] = mm; + } + } + } + } + } + int lvl = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str())-1; + nxt.name = creGenNames[nxt.bytes[20]][lvl]; + if(creGenNumbers[nxt.bytes[20]][lvl]!=-1) + { + CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl]; + continue; + } + std::vector::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), + nxt.name); + if(pit == CGameInfo::mainObj->dobjinfo->objs.end()) + { + nxt.isOnDefList = false; + } + else + { + nxt.printPriority = pit->priority; + nxt.isOnDefList = true; + } + map.defy.push_back(nxt); // add this def to the vector + defsToUnpack.push_back(nxt.name); + CGI->objh->objInstances[j].defNumber = map.defy.size()-1; + if(creGenNumbers[nxt.bytes[20]][lvl]==-1) + { + creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1; + } + } + else //if not as castle + { + DefInfo nxt = curDef; + nxt.bytes[16] = 17; + std::vector possibleTowns; + for(int bb=0; bb<8; ++bb) + { + if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->castles[0] & (1<objh->objInstances[j].info)->castles[1]) + possibleTowns.push_back(8); + nxt.bytes[20] = possibleTowns[rand()%possibleTowns.size()]; + int lvl = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str())-1; + nxt.name = creGenNames[nxt.bytes[20]][lvl]; + if(creGenNumbers[nxt.bytes[20]][lvl]!=-1) + { + CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl]; + continue; + } + std::vector::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), + nxt.name); + if(pit == CGameInfo::mainObj->dobjinfo->objs.end()) + { + nxt.isOnDefList = false; + } + else + { + nxt.printPriority = pit->priority; + nxt.isOnDefList = true; + } + map.defy.push_back(nxt); // add this def to the vector + defsToUnpack.push_back(nxt.name); + CGI->objh->objInstances[j].defNumber = map.defy.size()-1; + if(creGenNumbers[nxt.bytes[20]][lvl]==-1) + { + creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1; + } + } + break; + } + case EDefType::CREGEN2_DEF: + { + if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->asCastle) + { + DefInfo nxt = curDef; + nxt.bytes[16] = 17; + for(int vv=0; vvobjh->objInstances.size(); ++vv) + { + if(getDefType(map.defy[CGI->objh->objInstances[vv].defNumber])==EDefType::TOWN_DEF) + { + if( + ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[0]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[0] + && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[1]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[1] + && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[2]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[2] + && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[3]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[3]) + { + for(int mm=0; mmobjh->objInstances[vv].defNumber].name; + std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper); + if(town1DefNames[mm]==hlp) + { + nxt.bytes[20] = mm; + } + } + } + } + } + int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel; + nxt.name = creGenNames[nxt.bytes[20]][lvl]; + if(creGenNumbers[nxt.bytes[20]][lvl]!=-1) + { + CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl]; + continue; + } + std::vector::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), + nxt.name); + if(pit == CGameInfo::mainObj->dobjinfo->objs.end()) + { + nxt.isOnDefList = false; + } + else + { + nxt.printPriority = pit->priority; + nxt.isOnDefList = true; + } + map.defy.push_back(nxt); // add this def to the vector + defsToUnpack.push_back(nxt.name); + CGI->objh->objInstances[j].defNumber = map.defy.size()-1; + if(creGenNumbers[nxt.bytes[20]][lvl]==-1) + { + creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1; + } + } + else //if not as castle + { + DefInfo nxt = curDef; + nxt.bytes[16] = 17; + std::vector possibleTowns; + for(int bb=0; bb<8; ++bb) + { + if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->castles[0] & (1<objh->objInstances[j].info)->castles[1]) + possibleTowns.push_back(8); + nxt.bytes[20] = possibleTowns[rand()%possibleTowns.size()]; + int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel; + nxt.name = creGenNames[nxt.bytes[20]][lvl]; + if(creGenNumbers[nxt.bytes[20]][lvl]!=-1) + { + CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl]; + continue; + } + std::vector::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), + nxt.name); + if(pit == CGameInfo::mainObj->dobjinfo->objs.end()) + { + nxt.isOnDefList = false; + } + else + { + nxt.printPriority = pit->priority; + nxt.isOnDefList = true; + } + map.defy.push_back(nxt); // add this def to the vector + defsToUnpack.push_back(nxt.name); + CGI->objh->objInstances[j].defNumber = map.defy.size()-1; + if(creGenNumbers[nxt.bytes[20]][lvl]==-1) + { + creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1; + } + } + } + case EDefType::CREGEN3_DEF: + { + DefInfo nxt = curDef; + nxt.bytes[16] = 17; + nxt.bytes[20] = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str()); + int lvl = rand()%(((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->minLevel; + nxt.name = creGenNames[nxt.bytes[20]][lvl]; + if(creGenNumbers[nxt.bytes[20]][lvl]!=-1) + { + CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl]; + continue; + } + std::vector::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), + nxt.name); + if(pit == CGameInfo::mainObj->dobjinfo->objs.end()) + { + nxt.isOnDefList = false; + } + else + { + nxt.printPriority = pit->priority; + nxt.isOnDefList = true; + } + map.defy.push_back(nxt); // add this def to the vector + defsToUnpack.push_back(nxt.name); + CGI->objh->objInstances[j].defNumber = map.defy.size()-1; + if(creGenNumbers[nxt.bytes[20]][lvl]==-1) + { + creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1; + } + break; + } + }//end of main switch + } //end of sencond for loop } diff --git a/CPreGame.cpp b/CPreGame.cpp index 7cec1c1c9d4386705433ee5c0a1cd8f7b3e0a66f..fe86a061fc4d9d577253ec49eb2c91372c1d0f05 100644 GIT binary patch delta 341 zcmYLFF$%&!5FD`(Yd?@q4MGrmf1rObF=8~ilS_hFr4V0WA@~Z#r|1_18~@5);LR%#oPu2fj4x#2@GDzIgYAzZNKEh7}#s