void gameloop() { while(1) { fps(); count++; monstermove(); monstermake(); bulletmove(); attackcheck(); keycheck(); draw(); Console_Flip(); gamewait(); if(endcheck() == 1) { Print("clear!\n", 10, 5); Print("game end...", 10, 6); _getch(); Console_Close(); exit(0); } } }
// <varpart> ::= <empty> // | VAR <vardeclaration> ; { <vardeclaration> ; } void SyntaxAnalyzer::varPart(std::set<symboltype> followers) { std::set<symboltype> starters(followers); //copy followers starters.insert(varsy); //symbol not found in starters, do nothing if(!startcheck(starters, followers)) { return; } //it's optional if (symbol == varsy) { accept(varsy); //at least one declaration is required do { varDeclaration(); accept(semicolon); } while (symbol == ident); } endcheck(followers); } // varpart( )
/* does end of month actions */ void passmonth(char &clearformess,char canseethings) { short oldlaw[LAWNUM]; memmove(oldlaw,law,sizeof(short)*LAWNUM); int l, v, p; //TIME ADVANCE day=1; month++; if(month==13) { month=1; year++; } switch(endgamestate) { case ENDGAME_NONE: if(publicmood(-1)>60) { endgamestate=ENDGAME_CCS_APPEARANCE; attitude[VIEW_CONSERVATIVECRIMESQUAD]=0; } break; case ENDGAME_CCS_APPEARANCE: if(publicmood(-1)>80) endgamestate=ENDGAME_CCS_ATTACKS; break; case ENDGAME_CCS_ATTACKS: if(publicmood(-1)>90) endgamestate=ENDGAME_CCS_SIEGES; break; case ENDGAME_CCS_SIEGES: case ENDGAME_CCS_DEFEATED: //if(publicmood(-1)>85&&presparty!=LIBERAL_PARTY) // endgamestate=ENDGAME_MARTIALLAW; break; } //CLEAR RENT EXEMPTIONS for(l=0;l<len(location);l++) location[l]->newrental=0; //YOUR PAPER AND PUBLIC OPINION AND STUFF vector<int> nploc; for(l=0;l<len(location);l++) { if((location[l]->compound_walls & COMPOUND_PRINTINGPRESS)&& !location[l]->siege.siege&& location[l]->renting!=RENTING_CCS) nploc.push_back(l); } // Check for game over endcheck(END_DEAD); dispersalcheck(clearformess); int guardianpower=0; if(len(nploc)&&!disbanding) { //DO SPECIAL EDITIONS int loottypeindex=choosespecialedition(clearformess); if(loottypeindex!=-1) { guardianpower+=10*len(nploc); printnews(loottypeindex,len(nploc)); if(loottype[loottypeindex]->get_idname()=="LOOT_INTHQDISK"|| //For special edition xml file? -XML loottype[loottypeindex]->get_idname()=="LOOT_SECRETDOCUMENTS") { for(int l=0;l<len(nploc);l++) criminalizepool(LAWFLAG_TREASON,-1,nploc[l]); } } } int libpower[VIEWNUM]={0}; //STORIES STALE EVEN IF NOT PRINTED for(v=0;v<VIEWNUM;v++)public_interest[v]/=2; int conspower=200-attitude[VIEW_AMRADIO]-attitude[VIEW_CABLENEWS]; //HAVING SLEEPERS for(int pl=len(pool)-1;pl>0;pl--) if(pool[pl]->alive&&(pool[pl]->flag & CREATUREFLAG_SLEEPER)) sleepereffect(*pool[pl],clearformess,canseethings,libpower); //Manage graffiti for(int l=0;l<len(location);l++) // Check each location { for(int c=len(location[l]->changes)-1;c>=0;c--) // Each change to the map { if(location[l]->changes[c].flag==SITEBLOCK_GRAFFITI|| location[l]->changes[c].flag==SITEBLOCK_GRAFFITI_CCS|| location[l]->changes[c].flag==SITEBLOCK_GRAFFITI_OTHER) // Find changes that refer specifically to graffiti { int power=0,align=0; if(location[l]->changes[c].flag==SITEBLOCK_GRAFFITI) align=1; if(location[l]->changes[c].flag==SITEBLOCK_GRAFFITI_CCS) align=-1; //Purge graffiti from more secure sites (or from non-secure //sites about once every five years), but these will //influence people more for the current month if(securityable(location[l]->type)) { location[l]->changes.erase(location[l]->changes.begin()+c); power=5; } else { if(location[l]->renting==RENTING_CCS) location[l]->changes[c].flag=SITEBLOCK_GRAFFITI_CCS; // Convert to CCS tags else if(location[l]->renting==RENTING_PERMANENT) location[l]->changes[c].flag=SITEBLOCK_GRAFFITI; // Convert to LCS tags else { power=1; if(!LCSrandom(10)) location[l]->changes[c].flag=SITEBLOCK_GRAFFITI_OTHER; // Convert to other tags if(!LCSrandom(10)&&endgamestate<ENDGAME_CCS_DEFEATED&&endgamestate>0) location[l]->changes[c].flag=SITEBLOCK_GRAFFITI_CCS; // Convert to CCS tags if(!LCSrandom(30)) location[l]->changes.erase(location[l]->changes.begin()+c); // Clean up } } if(align==1) { background_liberal_influence[VIEW_LIBERALCRIMESQUAD]+=power; background_liberal_influence[VIEW_CONSERVATIVECRIMESQUAD]+=power; } else if(align==-1) { background_liberal_influence[VIEW_LIBERALCRIMESQUAD]-=power; background_liberal_influence[VIEW_CONSERVATIVECRIMESQUAD]-=power; } } } } int mediabalance=0; int issuebalance[VIEWNUM-5]; //int stimulus=0; //double cost=0; //double tax=0; //PUBLIC OPINION NATURAL MOVES for(v=0;v<VIEWNUM;v++) { // Liberal essays add their power to the effect of sleepers libpower[v]+=background_liberal_influence[v]; background_liberal_influence[v]=static_cast<short>(background_liberal_influence[v]*0.66); if(v==VIEW_LIBERALCRIMESQUADPOS) continue; if(v==VIEW_LIBERALCRIMESQUAD) continue; //if(v==VIEW_POLITICALVIOLENCE) //{ // change_public_opinion(VIEW_POLITICALVIOLENCE,-1,0); // continue; //} if(v==VIEW_CONSERVATIVECRIMESQUAD) continue; if(v!=VIEW_AMRADIO&&v!=VIEW_CABLENEWS) { issuebalance[v] = libpower[v] - conspower; mediabalance += issuebalance[v]; // Heavy randomization -- balance of power just biases the roll int roll = issuebalance[v] + LCSrandom(400)-200; // If +/-50 to either side, that side wins the tug-of-war if(roll < -50) change_public_opinion(v,-1,0); else if(roll > 50) change_public_opinion(v,1,0); else // Else random movement change_public_opinion(v,LCSrandom(2)*2-1,0); } // AM Radio and Cable News popularity slowly shift to reflect public // opinion over time -- if left unchecked, their subtle influence // on society will become a self-perpetuating Conservative nightmare! else if(v==VIEW_AMRADIO||v==VIEW_CABLENEWS) { if(publicmood(-1)<attitude[v])change_public_opinion(v,-1); else change_public_opinion(v,1); } } // Temporary Stalinizing Code (TODO: Implement the Stalinist Comrade Squad for changing public opinion, then remove this) if(stalinmode) for(int v=0;v<VIEWNUM-3;v++) { if(stalinview(v,false)) { if((attitude[v]+=3)>100) attitude[v]=100; } else { if(--attitude[v]<0) attitude[v]=0; } } // End Temporary Stalinizing Code (TODO: Implement the Stalinist Comrade Squad for changing public opinion, then remove this) // Seduction monthly experience stipends for those liberals // who have been getting it on with their love slaves/masters // in the background for(int s=0;s<len(pool);s++) { pool[s]->train(SKILL_SEDUCTION,loveslaves(*pool[s])*5); if(pool[s]->flag & CREATUREFLAG_LOVESLAVE) pool[s]->train(SKILL_SEDUCTION,5); } /******************************************************* * INTELLIGENCE REPORT * * ONLY IF SHOWMECHANICS OR SHOWWAIT IS DEFINED * * EYES ONLY - LCS PROPERTY - TOP SECRET * *******************************************************/ #if defined(SHOWMECHANICS) || defined(SHOWWAIT) if(canseethings) { music.play(MUSIC_ELECTIONS); erase(); set_color(COLOR_WHITE,COLOR_BLACK,1); mvaddstr(0,23,"LCS MONTHLY INTELLIGENCE REPORT"); mvaddstr(2,27,"CURRENT POLITICAL TRENDS"); int numviews=(endgamestate>=ENDGAME_CCS_DEFEATED||newscherrybusted<2)?VIEWNUM-1:VIEWNUM; for(int v=-1-stalinmode,y=4,x=0,pip;v<numviews;v++) { if((y-4)*2>=numviews+1+stalinmode) y=4,x=40; for(pip=2;pip>=-2;pip--) { set_alignment_color(pip,true); if(pip==2) mvaddchar(y,x+22,'\x11'); addstr("ÄÄÄ"); if(pip==-2) addchar('\x10'); } if(v>=0) pip=14-(attitude[v]*14)/100; else pip=14-(publicmood(v)*14)/100; set_alignment_color((14-pip)/3-2,true); mvaddstr(y,x,getview(v,false)); mvaddchar(y++,x+23+pip,'O'); } set_color(COLOR_GREEN,COLOR_BLACK,1); mvaddstr(23,0,"Elite Liberal "); set_color(COLOR_WHITE,COLOR_BLACK,0); addstr("- "); set_color(COLOR_CYAN,COLOR_BLACK,1); addstr("Liberal "); set_color(COLOR_WHITE,COLOR_BLACK,0); addstr("- "); set_color(COLOR_YELLOW,COLOR_BLACK,1); addstr("moderate "); set_color(COLOR_WHITE,COLOR_BLACK,0); addstr("- "); set_color(COLOR_MAGENTA,COLOR_BLACK,1); addstr("Conservative "); set_color(COLOR_WHITE,COLOR_BLACK,0); addstr("- "); set_color(COLOR_RED,COLOR_BLACK,1); addstr("Arch-Conservative"); set_color(COLOR_WHITE,COLOR_BLACK,0); mvaddstr(24,0,"Press any key to reflect on these poll numbers."); clearformess=1; getkey(); } #endif /******************************************************* * * * END INTELLIGENCE REPORT * * * *******************************************************/ //ELECTIONS if(month==11){elections(clearformess,canseethings);clearformess=1;} //SUPREME COURT if(month==6){supremecourt(clearformess,canseethings);clearformess=1;} //CONGRESS congress(clearformess,canseethings);clearformess=1; //DID YOU WIN? if(wincheck()) { liberalagenda(1); savehighscore(END_WON); reset(savefile_name); viewhighscores(); end_game(); } //CONTROL LONG DISBANDS if(disbanding&&year-disbandtime>=50) { music.play(MUSIC_DEFEAT); set_color(COLOR_WHITE,COLOR_BLACK,1); erase(); move(12,10); addstr("The Liberal Crime Squad is now just a memory.", gamelog); gamelog.newline(); getkey(); set_color(COLOR_WHITE,COLOR_BLACK,0); erase(); move(12,12); addstr("The last LCS members have all been hunted down.", gamelog); gamelog.newline(); getkey(); set_color(COLOR_BLACK,COLOR_BLACK,1); erase(); move(12,14); addstr("They will never see the utopia they dreamed of...", gamelog); gamelog.newline(); gamelog.nextMessage(); getkey(); savehighscore(END_DISBANDLOSS); reset(savefile_name); viewhighscores(); end_game(); } //UPDATE THE WORLD IN CASE THE LAWS HAVE CHANGED updateworld_laws(law,oldlaw); //THE SYSTEM! for(p=len(pool)-1;p>=0;p--) { if(disbanding) break; if(!pool[p]->alive) continue; if(pool[p]->flag & CREATUREFLAG_SLEEPER) continue; if(pool[p]->location==-1) continue; if(location[pool[p]->location]->type==SITE_GOVERNMENT_POLICESTATION) { if(clearformess) erase(); else makedelimiter(); if(pool[p]->flag & CREATUREFLAG_MISSING) { set_color(COLOR_MAGENTA,COLOR_BLACK,1); move(8,1); addstr("Cops re-polluted ", gamelog); addstr(pool[p]->name, gamelog); addstr("'s mind with Conservatism!", gamelog); gamelog.nextMessage(); getkey(); removesquadinfo(*pool[p]); delete_and_remove(pool,p); continue; } else if(pool[p]->flag & CREATUREFLAG_ILLEGALALIEN && law[LAW_IMMIGRATION]!=2) { set_color(COLOR_MAGENTA,COLOR_BLACK,1); move(8,1); addstr(pool[p]->name, gamelog); addstr(" has been shipped out to the INS to face ", gamelog); if(law[LAW_IMMIGRATION]==-2 && law[LAW_DEATHPENALTY]==-2) addstr("execution.", gamelog); else addstr("deportation.", gamelog); gamelog.newline(); getkey(); removesquadinfo(*pool[p]); delete_and_remove(pool,p); continue; } else { //TRY TO GET RACKETEERING CHARGE int copstrength=100; if(law[LAW_POLICEBEHAVIOR]==-2) copstrength=200; if(law[LAW_POLICEBEHAVIOR]==-1) copstrength=150; if(law[LAW_POLICEBEHAVIOR]==1) copstrength=75; if(law[LAW_POLICEBEHAVIOR]==2) copstrength=50; copstrength=(copstrength*pool[p]->heat)/4; if(copstrength>200)copstrength=200; //Confession check if(LCSrandom(copstrength)>pool[p]->juice + pool[p]->get_attribute(ATTRIBUTE_HEART,true)*5 - pool[p]->get_attribute(ATTRIBUTE_WISDOM,true)*5 + pool[p]->get_skill(SKILL_PSYCHOLOGY)*5 /*+ pool[p]->get_skill(SKILL_SURVIVAL)*5*/ && pool[p]->hireid!=-1) { int nullify=0; int p2=getpoolcreature(pool[p]->hireid); if(pool[p2]->alive && (pool[p2]->location==-1 || location[pool[p2]->location]->type!=SITE_GOVERNMENT_PRISON)) { //Charge the boss with racketeering! criminalize(*pool[p2],LAWFLAG_RACKETEERING); //Rack up testimonies against the boss in court! pool[p2]->confessions++; } if(!nullify) { //Issue a raid on this guy's base! if(pool[p]->base>=0)location[pool[p]->base]->heat+=300; set_color(COLOR_WHITE,COLOR_BLACK,1); move(8,1); addstr(pool[p]->name, gamelog); addstr(" has broken under the pressure and ratted you out!", gamelog); gamelog.newline(); getkey(); set_color(COLOR_WHITE,COLOR_BLACK,1); move(9,1); addstr("The traitor will testify in court, and safehouses may be compromised.", gamelog); gamelog.nextMessage(); getkey(); removesquadinfo(*pool[p]); delete_and_remove(pool,p); continue; //no trial for this person; skip to next person } //else continue to trial } set_color(COLOR_WHITE,COLOR_BLACK,1); move(8,1); addstr(pool[p]->name, gamelog); addstr(" is moved to the courthouse for trial.", gamelog); gamelog.nextMessage(); getkey(); pool[p]->location=find_courthouse(*pool[p]); Armor prisoner(*armortype[getarmortype("ARMOR_PRISONER")]); pool[p]->give_armor(prisoner,NULL); } } else if(location[pool[p]->location]->type==SITE_GOVERNMENT_COURTHOUSE) { trial(*pool[p]); clearformess=1; } else if(location[pool[p]->location]->type==SITE_GOVERNMENT_PRISON) if(prison(*pool[p])) clearformess=1; } //NUKE EXECUTION VICTIMS for(p=len(pool)-1;p>=0;p--) { if(pool[p]->location==-1) continue; if(location[pool[p]->location]->type==SITE_GOVERNMENT_PRISON&&!pool[p]->alive) { removesquadinfo(*pool[p]); pool[p]->die(); pool[p]->location=-1; } } //MUST DO AN END OF GAME CHECK HERE BECAUSE OF EXECUTIONS endcheck(END_EXECUTED); //DISPERSAL CHECK dispersalcheck(clearformess); //FUND REPORTS if(canseethings)fundreport(clearformess); ledger.resetMonthlyAmounts(); if(clearformess) erase(); //HEAL CLINIC PEOPLE for(p=0;p<len(pool);p++) { if(disbanding) break; if(!(pool[p]->alive)) continue; if(pool[p]->clinic>0) { pool[p]->clinic--; for(int w=0;w<BODYPARTNUM;w++) { if((pool[p]->wound[w]&WOUND_NASTYOFF)||(pool[p]->wound[w]&WOUND_CLEANOFF)) pool[p]->wound[w]=(char)WOUND_CLEANOFF; else pool[p]->wound[w]=0; } int healthdamage = 0; if(pool[p]->special[SPECIALWOUND_RIGHTLUNG]!=1) { pool[p]->special[SPECIALWOUND_RIGHTLUNG]=1; if(LCSrandom(2)) healthdamage++; } if(pool[p]->special[SPECIALWOUND_LEFTLUNG]!=1) { pool[p]->special[SPECIALWOUND_LEFTLUNG]=1; if(LCSrandom(2)) healthdamage++; } if(pool[p]->special[SPECIALWOUND_HEART]!=1) { pool[p]->special[SPECIALWOUND_HEART]=1; if(LCSrandom(3)) healthdamage++; } pool[p]->special[SPECIALWOUND_LIVER]=1; pool[p]->special[SPECIALWOUND_STOMACH]=1; pool[p]->special[SPECIALWOUND_RIGHTKIDNEY]=1; pool[p]->special[SPECIALWOUND_LEFTKIDNEY]=1; pool[p]->special[SPECIALWOUND_SPLEEN]=1; pool[p]->special[SPECIALWOUND_RIBS]=RIBNUM; if(!pool[p]->special[SPECIALWOUND_NECK]) pool[p]->special[SPECIALWOUND_NECK]=2; if(!pool[p]->special[SPECIALWOUND_UPPERSPINE]) pool[p]->special[SPECIALWOUND_UPPERSPINE]=2; if(!pool[p]->special[SPECIALWOUND_LOWERSPINE]) pool[p]->special[SPECIALWOUND_LOWERSPINE]=2; // Inflict permanent health damage pool[p]->set_attribute(ATTRIBUTE_HEALTH,pool[p]->get_attribute(ATTRIBUTE_HEALTH,0)-healthdamage); if(pool[p]->get_attribute(ATTRIBUTE_HEALTH,0)<=0) pool[p]->set_attribute(ATTRIBUTE_HEALTH,1); if(pool[p]->blood<=20&&pool[p]->clinic<=2)pool[p]->blood=50; if(pool[p]->blood<=50&&pool[p]->clinic<=1)pool[p]->blood=75; // If at clinic and in critical condition, transfer to university hospital if(pool[p]->clinic > 2 && pool[p]->location > -1 && location[pool[p]->location]->type==SITE_HOSPITAL_CLINIC) { int hospital=find_hospital(*pool[p]); if(hospital!=-1) { pool[p]->location=hospital; set_color(COLOR_WHITE,COLOR_BLACK,1); move(8,1); addstr(pool[p]->name, gamelog); addstr(" has been transferred to ", gamelog); addstr(location[hospital]->name, gamelog); addstr(".", gamelog); gamelog.nextMessage(); getkey(); } } // End treatment if(pool[p]->clinic==0) { pool[p]->blood=100; if(clearformess) erase(); else makedelimiter(); set_color(COLOR_WHITE,COLOR_BLACK,1); move(8,1); addstr(pool[p]->name, gamelog); addstr(" has left ", gamelog); addstr(location[pool[p]->location]->name, gamelog); addstr(".", gamelog); gamelog.nextMessage(); int hs=find_homeless_shelter(*pool[p]); if(hs==-1) hs=0; //TODO: Error unable to find location if(location[pool[p]->base]->siege.siege|| location[pool[p]->base]->renting==RENTING_NOCONTROL) pool[p]->base=hs; pool[p]->location=pool[p]->base; getkey(); } } } }
void dispersalcheck(char &clearformess) { int p = 0; //NUKE DISPERSED SQUAD MEMBERS WHOSE MASTERS ARE NOT AVAILABLE if(pool.size()>0) { // *JDS* I'm documenting this algorithm carefully because it // took me awhile to figure out what exactly was going on here. // // nukeme tracks whether each person has a secure chain of command. // // if nukeme == 1, no confirmation of contact has been made // if nukeme == 0, confirmation that THEY are safe is given, // but it is still needed to check whether their subordinates // can reach them. // if nukeme == -1, confirmation has been made that this squad // member is safe, and their immediate subordinates have also // checked. // // The way the algorithm works, everyone starts at nukeme = 1. // Then we start at the top of the chain of command and walk // down it slowly, marking people 0 and then -1 as we sweep // down the chain. If someone is dead or in an unreachable state, // they block progression down the chain to their subordinates, // preventing everyone who requires contact with that person // from being marked safe. After everyone reachable has been // reached and marked safe, all remaining squad members are nuked. vector<int> nukeme; nukeme.resize(pool.size()); for(p=pool.size()-1;p>=0;p--) { // If member is dead or has no boss (founder level), mark // them nukeme = 0, using them as a starting point at the top // of the chain. if(!pool[p]->alive||pool[p]->hireid==-1)nukeme[p]=0; // All remaining members are marked nukeme = 1. else nukeme[p]=1; } char changed; do // while(changed!=0) { changed=0; char inprison, alive; // Go through the entire pool to locate people at nukeme = 0, // so we can verify that their subordinates can reach them. for(p=pool.size()-1;p>=0;p--) { if(pool[p]->location!=-1&&location[pool[p]->location]->type==SITE_GOVERNMENT_PRISON) inprison=1; else inprison=0; if(pool[p]->alive)alive=1; else alive=0; // If in prison or unreachable due to a member of the command structure // above being in prison if(nukeme[p]==0&&alive&&inprison||nukeme[p]==2) { // If you're here because you're unreachable, mark as checked and unreachable if(!inprison) { // Roll to see if you go into hiding or not if(!pool[p]->hiding&& pool[p]->attval(ATTRIBUTE_HEART)*5+pool[p]->juice<LCSrandom(200)) { nukeme[p]=1; } else nukeme[p]=3; } else nukeme[p]=-1; // Else you're in prison; you're guaranteed contactable // Find all subordinates if you didn't lose contact completely if(nukeme[p]!=1) { for(int p2=pool.size()-1;p2>=0;p2--) { if(pool[p2]->hireid==pool[p]->id) { nukeme[p2]=2; // Mark them as unreachable changed=1; // Need another iteration } } } } // Otherwise, if they're both alive and reachable else if(nukeme[p]==0&&alive&&!inprison) { // Start looking through the pool again. for(int p2=pool.size()-1;p2>=0;p2--) { // Locate each of this person's subordinates. if(pool[p2]->hireid==pool[p]->id) { // Protect them from being dispersed -- their boss is // safe. Their own subordinates will then be considered // in the next loop iteration. nukeme[p2]=0; // If they're hiding indefinately and their boss isn't // hiding at all, then have them discreetly return in a // couple of weeks if(pool[p2]->hiding==-1&&!pool[p]->hiding) { pool[p2]->hiding=LCSrandom(10)+3; } changed=1; // Take note that another iteration is needed. } } // Now that we've dealt with this person's subordinates, mark // them so that we don't look at them again in this loop. nukeme[p]=-1; } } }while(changed); // If another iteration is needed, continue the loop. // After checking through the entire command structure, proceed // to nuke all squad members who are unable to make contact with // the LCS. for(p=pool.size()-1;p>=0;p--) { if(nukeme[p]==1||nukeme[p]==3) { if(clearformess) { erase(); } else { makedelimiter(8,0); } if(!pool[p]->hiding&&nukeme[p]==3) { set_color(COLOR_WHITE,COLOR_BLACK,1); move(8,1); addstr(pool[p]->name); addstr(" has lost touch with the Liberal Crime Squad."); move(9,1); addstr("The Liberal has gone into hiding..."); refresh(); getch(); } else if(nukeme[p]==1) { set_color(COLOR_WHITE,COLOR_BLACK,1); move(8,1); addstr(pool[p]->name); addstr(" has lost touch with the Liberal Crime Squad."); refresh(); getch(); } removesquadinfo(*pool[p]); if(nukeme[p]==1) { delete pool[p]; pool.erase(pool.begin() + p); } else { int hs=0; for(int l=0;l<location.size();l++) { if(location[l]->type==SITE_RESIDENTIAL_SHELTER) { hs=l; break; } } pool[p]->location=-1; pool[p]->base=hs; pool[p]->hiding=-1; // Hide indefinately } } } } //MUST DO AN END OF GAME CHECK HERE BECAUSE OF DISPERSAL endcheck(END_DISPERSED); }
/* Manage the whole stuff. */ void makeit() { checkstruct *check; picstruct *dfield, *field,*pffield[MAXFLAG], *wfield,*dwfield; catstruct *imacat; tabstruct *imatab; patternstruct *pattern; static time_t thetime1, thetime2; struct tm *tm; unsigned int modeltype; int nflag[MAXFLAG], nparam2[2], i, nok, ntab, next, ntabmax, forcextflag, nima0,nima1, nweight0,nweight1, npsf0,npsf1, npat,npat0; next = 0; nok = 1; /* Processing start date and time */ dtime = counter_seconds(); thetimet = time(NULL); tm = localtime(&thetimet); sprintf(prefs.sdate_start,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_start,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); NFPRINTF(OUTPUT, ""); QPRINTF(OUTPUT, "----- %s %s started on %s at %s with %d thread%s\n\n", BANNER, MYVERSION, prefs.sdate_start, prefs.stime_start, prefs.nthreads, prefs.nthreads>1? "s":""); /* Initialize globals variables */ initglob(); NFPRINTF(OUTPUT, "Setting catalog parameters"); readcatparams(prefs.param_name); useprefs(); /* update things accor. to prefs parameters */ /* Check if a specific extension should be loaded */ /* Never true for an NDF, although we could through all NDFs in a container, */ /* so we make selectext go away. */ nima0 = -1; forcextflag = 0; /* Do the same for other data (but do not force single extension mode) */ nima1 = -1; /* selectext(prefs.image_name[1]) */ nweight0 = -1; /* selectext(prefs.wimage_name[0]) */ nweight1 = -1; /* selectext(prefs.wimage_name[1]) */ if (prefs.dpsf_flag) { npsf0 = -1; /* selectext(prefs.psf_name[0]) */ npsf1 = -1; /* selectext(prefs.psf_name[1]) */ } else npsf0 = -1; /* selectext(prefs.psf_name[0]) */ for (i=0; i<prefs.nfimage_name; i++) nflag[i] = -1; /* selectext(prefs.fimage_name[i]) */ if (prefs.psf_flag) { /*-- Read the first PSF extension to set up stuff such as context parameters */ NFPRINTF(OUTPUT, "Reading PSF information"); if (prefs.dpsf_flag) { thedpsf = psf_load(prefs.psf_name[0],nima0<0? 1 :(npsf0<0? 1:npsf0)); thepsf = psf_load(prefs.psf_name[1], nima1<0? 1 :(npsf1<0? 1:npsf1)); } else thepsf = psf_load(prefs.psf_name[0], nima0<0? 1 :(npsf0<0? 1:npsf0)); /*-- Need to check things up because of PSF context parameters */ updateparamflags(); useprefs(); } if (prefs.prof_flag) { #ifdef USE_MODEL fft_init(prefs.nthreads); /* Create profiles at full resolution */ NFPRINTF(OUTPUT, "Preparing profile models"); modeltype = (FLAG(obj2.prof_offset_flux)? MODEL_BACK : MODEL_NONE) |(FLAG(obj2.prof_dirac_flux)? MODEL_DIRAC : MODEL_NONE) |(FLAG(obj2.prof_spheroid_flux)? (FLAG(obj2.prof_spheroid_sersicn)? MODEL_SERSIC : MODEL_DEVAUCOULEURS) : MODEL_NONE) |(FLAG(obj2.prof_disk_flux)? MODEL_EXPONENTIAL : MODEL_NONE) |(FLAG(obj2.prof_bar_flux)? MODEL_BAR : MODEL_NONE) |(FLAG(obj2.prof_arms_flux)? MODEL_ARMS : MODEL_NONE); theprofit = profit_init(thepsf, modeltype); changecatparamarrays("VECTOR_MODEL", &theprofit->nparam, 1); changecatparamarrays("VECTOR_MODELERR", &theprofit->nparam, 1); nparam2[0] = nparam2[1] = theprofit->nparam; changecatparamarrays("MATRIX_MODELERR", nparam2, 2); if (prefs.dprof_flag) thedprofit = profit_init(thedpsf, modeltype); if (prefs.pattern_flag) { npat0 = prefs.prof_disk_patternvectorsize; if (npat0<prefs.prof_disk_patternmodvectorsize) npat0 = prefs.prof_disk_patternmodvectorsize; if (npat0<prefs.prof_disk_patternargvectorsize) npat0 = prefs.prof_disk_patternargvectorsize; /*---- Do a copy of the original number of pattern components */ prefs.prof_disk_patternncomp = npat0; pattern = pattern_init(theprofit, prefs.pattern_type, npat0); if (FLAG(obj2.prof_disk_patternvector)) { npat = pattern->size[2]; changecatparamarrays("DISK_PATTERN_VECTOR", &npat, 1); } if (FLAG(obj2.prof_disk_patternmodvector)) { npat = pattern->ncomp*pattern->nfreq; changecatparamarrays("DISK_PATTERNMOD_VECTOR", &npat, 1); } if (FLAG(obj2.prof_disk_patternargvector)) { npat = pattern->ncomp*pattern->nfreq; changecatparamarrays("DISK_PATTERNARG_VECTOR", &npat, 1); } pattern_end(pattern); } QPRINTF(OUTPUT, "Fitting model: "); for (i=0; i<theprofit->nprof; i++) { if (i) QPRINTF(OUTPUT, "+"); QPRINTF(OUTPUT, "%s", theprofit->prof[i]->name); } QPRINTF(OUTPUT, "\n"); if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration)) { thepprofit = profit_init(thepsf, MODEL_DIRAC); theqprofit = profit_init(thepsf, MODEL_EXPONENTIAL); } #else error(EXIT_FAILURE, "*Error*: model-fitting is not supported in this build.\n", " Please check your configure options"); #endif } if (prefs.filter_flag) { NFPRINTF(OUTPUT, "Reading detection filter"); getfilter(prefs.filter_name); /* get the detection filter */ } if (FLAG(obj2.sprob)) { NFPRINTF(OUTPUT, "Initializing Neural Network"); neurinit(); NFPRINTF(OUTPUT, "Reading Neural Network Weights"); getnnw(); } if (prefs.somfit_flag) { int margin; thesom = som_load(prefs.som_name); if ((margin=(thesom->inputsize[1]+1)/2) > prefs.cleanmargin) prefs.cleanmargin = margin; if (prefs.somfit_vectorsize>thesom->neurdim) { prefs.somfit_vectorsize = thesom->neurdim; sprintf(gstr,"%d", prefs.somfit_vectorsize); warning("Dimensionality of the SOM-fit vector limited to ", gstr); } } /* Prepare growth-curve buffer */ if (prefs.growth_flag) initgrowth(); /* Allocate memory for multidimensional catalog parameter arrays */ alloccatparams(); useprefs(); /*-- Init the CHECK-images */ if (prefs.check_flag) { checkenum c; NFPRINTF(OUTPUT, "Initializing check-image(s)"); for (i=0; i<prefs.ncheck_type; i++) if ((c=prefs.check_type[i]) != CHECK_NONE) { if (prefs.check[c]) error(EXIT_FAILURE,"*Error*: 2 CHECK_IMAGEs cannot have the same ", " CHECK_IMAGE_TYPE"); prefs.check[c] = initcheck(prefs.check_name[i], prefs.check_type[i], next); free(prefs.check_name[i]); } } NFPRINTF(OUTPUT, "Initializing catalog"); initcat(); /* Initialize XML data */ if (prefs.xml_flag || prefs.cat_type==ASCII_VO) init_xml(next); /* Go through all images */ /* for all images in an MEF */ /*---- Initial time measurement*/ time(&thetime1); thecat.currext = nok+1; dfield = field = wfield = dwfield = NULL; /*---- Init the Detection and Measurement-images */ if (prefs.dimage_flag) { dfield = newfield(prefs.image_name[0], DETECT_FIELD, nok); field = newfield(prefs.image_name[1], MEASURE_FIELD, nok); if ((field->width!=dfield->width) || (field->height!=dfield->height)) error(EXIT_FAILURE, "*Error*: Frames have different sizes",""); /*---- Prepare interpolation */ if (prefs.dweight_flag && prefs.interp_type[0] == INTERP_ALL) init_interpolate(dfield, -1, -1); if (prefs.interp_type[1] == INTERP_ALL) init_interpolate(field, -1, -1); } else { field = newfield(prefs.image_name[0], DETECT_FIELD | MEASURE_FIELD, nok); /*-- Prepare interpolation */ if ((prefs.dweight_flag || prefs.weight_flag) && prefs.interp_type[0] == INTERP_ALL) init_interpolate(field, -1, -1); /* 0.0 or anything else */ } /*-- Init the WEIGHT-images */ if (prefs.dweight_flag || prefs.weight_flag) { weightenum wtype; PIXTYPE interpthresh; if (prefs.nweight_type>1) { /*------ Double-weight-map mode */ if (prefs.weight_type[1] != WEIGHT_NONE) { /*-------- First: the "measurement" weights */ wfield = newweight(prefs.wimage_name[1],field,prefs.weight_type[1], nok); wtype = prefs.weight_type[1]; interpthresh = prefs.weight_thresh[1]; /*-------- Convert the interpolation threshold to variance units */ weight_to_var(wfield, &interpthresh, 1); wfield->weight_thresh = interpthresh; if (prefs.interp_type[1] != INTERP_NONE) init_interpolate(wfield, prefs.interp_xtimeout[1], prefs.interp_ytimeout[1]); } /*------ The "detection" weights */ if (prefs.weight_type[0] != WEIGHT_NONE) { interpthresh = prefs.weight_thresh[0]; if (prefs.weight_type[0] == WEIGHT_FROMINTERP) { dwfield=newweight(prefs.wimage_name[0],wfield,prefs.weight_type[0], nok); weight_to_var(wfield, &interpthresh, 1); } else { dwfield = newweight(prefs.wimage_name[0], dfield?dfield:field, prefs.weight_type[0], nok); weight_to_var(dwfield, &interpthresh, 1); } dwfield->weight_thresh = interpthresh; if (prefs.interp_type[0] != INTERP_NONE) init_interpolate(dwfield, prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]); } } else { /*------ Single-weight-map mode */ wfield = newweight(prefs.wimage_name[0], dfield?dfield:field, prefs.weight_type[0], nok); wtype = prefs.weight_type[0]; interpthresh = prefs.weight_thresh[0]; /*------ Convert the interpolation threshold to variance units */ weight_to_var(wfield, &interpthresh, 1); wfield->weight_thresh = interpthresh; if (prefs.interp_type[0] != INTERP_NONE) init_interpolate(wfield, prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]); } } /*-- Init the FLAG-images */ for (i=0; i<prefs.nimaflag; i++) { pffield[i] = newfield(prefs.fimage_name[i], FLAG_FIELD, nok); if ((pffield[i]->width!=field->width) || (pffield[i]->height!=field->height)) error(EXIT_FAILURE, "*Error*: Incompatible FLAG-map size in ", prefs.fimage_name[i]); } /*-- Compute background maps for `standard' fields */ QPRINTF(OUTPUT, dfield? "Measurement image:" : "Detection+Measurement image: "); makeback(field, wfield, prefs.wscale_flag[1]); QPRINTF(OUTPUT, (dfield || (dwfield&&dwfield->flags^INTERP_FIELD))? "(M) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n" : "(M+D) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n", field->backmean, field->backsig, (field->flags & DETECT_FIELD)? field->dthresh: field->thresh); if (dfield) { QPRINTF(OUTPUT, "Detection image: "); makeback(dfield, dwfield? dwfield : (prefs.weight_type[0] == WEIGHT_NONE?NULL:wfield), prefs.wscale_flag[0]); QPRINTF(OUTPUT, "(D) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n", dfield->backmean, dfield->backsig, dfield->dthresh); } else if (dwfield && dwfield->flags^INTERP_FIELD) { makeback(field, dwfield, prefs.wscale_flag[0]); QPRINTF(OUTPUT, "(D) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n", field->backmean, field->backsig, field->dthresh); } /*-- For interpolated weight-maps, copy the background structure */ if (dwfield && dwfield->flags&(INTERP_FIELD|BACKRMS_FIELD)) copyback(dwfield->reffield, dwfield); if (wfield && wfield->flags&(INTERP_FIELD|BACKRMS_FIELD)) copyback(wfield->reffield, wfield); /*-- Prepare learn and/or associations */ if (prefs.assoc_flag) init_assoc(field); /* initialize assoc tasks */ /*-- Update the CHECK-images */ if (prefs.check_flag) for (i=0; i<MAXCHECK; i++) if ((check=prefs.check[i])) reinitcheck(field, check); if (!forcextflag && nok>1) { if (prefs.psf_flag) { /*------ Read other PSF extensions */ NFPRINTF(OUTPUT, "Reading PSF information"); psf_end(thepsf, thepsfit); if (prefs.dpsf_flag) { psf_end(thedpsf, thedpsfit); thedpsf = psf_load(prefs.psf_name[0], nok); thepsf = psf_load(prefs.psf_name[1], nok); } else thepsf = psf_load(prefs.psf_name[0], nok); } #ifdef USE_MODEL if (prefs.prof_flag) { /*------ Create profiles at full resolution */ profit_end(theprofit); theprofit = profit_init(thepsf, modeltype); if (prefs.dprof_flag) { profit_end(thedprofit); thedprofit = profit_init(thedpsf, modeltype); } if (prefs.pattern_flag) { pattern = pattern_init(theprofit, prefs.pattern_type, npat0); pattern_end(pattern); } if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration)) { profit_end(thepprofit); profit_end(theqprofit); thepprofit = profit_init(thepsf, MODEL_DIRAC); theqprofit = profit_init(thepsf, MODEL_EXPONENTIAL); } } #endif } /*-- Initialize PSF contexts and workspace */ if (prefs.psf_flag) { psf_readcontext(thepsf, field); psf_init(); if (prefs.dpsf_flag) { psf_readcontext(thepsf, dfield); psf_init(); } } /*-- Copy field structures to static ones (for catalog info) */ if (dfield) { thefield1 = *field; thefield2 = *dfield; } else thefield1 = thefield2 = *field; if (wfield) { thewfield1 = *wfield; thewfield2 = dwfield? *dwfield: *wfield; } else if (dwfield) thewfield2 = *dwfield; reinitcat(field); /*-- Start the extraction pipeline */ NFPRINTF(OUTPUT, "Scanning image"); scanimage(field, dfield, pffield, prefs.nimaflag, wfield, dwfield); NFPRINTF(OUTPUT, "Closing files"); /*-- Finish the current CHECK-image processing */ if (prefs.check_flag) for (i=0; i<MAXCHECK; i++) if ((check=prefs.check[i])) reendcheck(field, check); /*-- Final time measurements*/ if (time(&thetime2)!=-1) { if (!strftime(thecat.ext_date, 12, "%d/%m/%Y", localtime(&thetime2))) error(EXIT_FAILURE, "*Internal Error*: Date string too long ",""); if (!strftime(thecat.ext_time, 10, "%H:%M:%S", localtime(&thetime2))) error(EXIT_FAILURE, "*Internal Error*: Time/date string too long ",""); thecat.ext_elapsed = difftime(thetime2, thetime1); } reendcat(); /* Update XML data */ if (prefs.xml_flag || prefs.cat_type==ASCII_VO) update_xml(&thecat, dfield? dfield:field, field, dwfield? dwfield:wfield, wfield); /*-- Close ASSOC routines */ end_assoc(field); for (i=0; i<prefs.nimaflag; i++) endfield(pffield[i]); endfield(field); if (dfield) endfield(dfield); if (wfield) endfield(wfield); if (dwfield) endfield(dwfield); QPRINTF(OUTPUT, " Objects: detected %-8d / sextracted %-8d \n\n", thecat.ndetect, thecat.ntotal); /* End look around all images in an MEF */ if (nok<0) error(EXIT_FAILURE, "Not enough valid FITS image extensions in ", prefs.image_name[0]); NFPRINTF(OUTPUT, "Closing files"); /* End CHECK-image processing */ if (prefs.check_flag) for (i=0; i<MAXCHECK; i++) { if ((check=prefs.check[i])) endcheck(check); prefs.check[i] = NULL; } if (prefs.filter_flag) endfilter(); if (prefs.somfit_flag) som_end(thesom); if (prefs.growth_flag) endgrowth(); #ifdef USE_MODEL if (prefs.prof_flag) { profit_end(theprofit); if (prefs.dprof_flag) profit_end(thedprofit); if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration)) { profit_end(thepprofit); profit_end(theqprofit); } fft_end(); } #endif if (prefs.psf_flag) psf_end(thepsf, thepsfit); if (prefs.dpsf_flag) psf_end(thedpsf, thedpsfit); if (FLAG(obj2.sprob)) neurclose(); /* Processing end date and time */ thetimet2 = time(NULL); tm = localtime(&thetimet2); sprintf(prefs.sdate_end,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_end,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); prefs.time_diff = counter_seconds() - dtime; /* Write XML */ if (prefs.xml_flag) write_xml(prefs.xml_name); endcat((char *)NULL); if (prefs.xml_flag || prefs.cat_type==ASCII_VO) end_xml(); /* Free FITS headers (now catalogues are closed). */ if (field->fitsheadsize > 0) { free(field->fitshead); } return; }