void Snake_t::gen_target(){ target.set_coordinates(rand()%d_width, rand()%d_height); }
inline float random(int howbig) { return (float) (((float) (fmod(rand(),RAND_MAX))/RAND_MAX))*howbig; }
inline float random(int howsmall, int howbig) { return (float) ((((float) (fmod(rand(),RAND_MAX))/RAND_MAX))*(howbig - howsmall))+howsmall; }
float Map::getRandom() { random = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);// Random value between 0.0f -> 1.0f return random; }
int main (int argc, char * argv[]) { // Create a knowledge base madara::knowledge::KnowledgeBase knowledge; /** * In the tutorial at system_primitives/fractions, we created the following * functions that we used to determine state in a quantum computer. * Unfortunately, these functions only work with one variable (.state) and * are essentially useless as general purpose functions without reworking. * * From system_primitives/fractions.cpp: * * knowledge.define_function ("is_true", * ".state >= 0.5 && .state <= 1"); * * knowledge.define_function ("is_false", * ".state > 0 && .state < 0.5"); * * As a first part of this function tutorial, let's create a MADARA function * that accomplishes the same thing but is extensible for any argument passed * to the function. The secret sauce here is the usage of the .0 variable, * which maps to the first argument to a function call and is set for us * by the MADARA KaRL engine. **/ // Define the two functions is_true and is_false to be MADARA logic functions knowledge.define_function ("is_true", ".0 >= 0.5 && .0 <= 1"); knowledge.define_function ("is_false", ".0 >= 0 && .0 < 0.5"); /** * Define a random integer generating function based on C's rand (). * Note that to do proper random generation, you will want to use srand * with a seed that makes sense (most people use the system clock) **/ knowledge.define_function ("rand", rand_int); knowledge.define_function ("rand_double", rand_double); // set the random seed to be the number of seconds since January 1st, 1970 srand ((unsigned int)time (NULL)); // do a couple of rands to get the seed away from standard seconds rand (); rand (); /** * Let's generate three random doubles with rand_double () and then check * whether or not they are true or false; **/ knowledge.evaluate ( ".var1 = rand_double ();" ".var2 = rand_double ();" ".var3 = rand_double ();" "is_true (.var1) => #print ('The generated var1 ({.var1}) is true\n');" "is_false (.var1) => #print ('The generated var1 ({.var1}) is false\n');" "is_true (.var2) => #print ('The generated var1 ({.var2}) is true\n');" "is_false (.var2) => #print ('The generated var1 ({.var2}) is false\n');" "is_true (.var3) => #print ('The generated var1 ({.var3}) is true\n');" "is_false (.var3) => #print ('The generated var1 ({.var3}) is false\n');" ); /** * Print all the variables just to see what we did. This is very useful for * debugging purposes as you are developing a MADARA application. **/ knowledge.print (); return 0; }
int main(int argc, char **argv) { double timeA, timeB; Sphere *spheres; Vec3 p,c,e; int n; timeA = omp_get_wtime(); n = argc>1 ? atoi(argv[1]) : N; if(n<N)n=100; spheres = malloc(n*sizeof(*spheres)); // position, radius, surface color, reflectivity, transparency, emission color Vec3_new(&p, 0, -10004, -20); Vec3_new1(&c, 0.2); Sphere_new0(&spheres[0], &p, 10000, &c, 0, 0.0); Vec3_new(&p, 0, 0, -20); Vec3_new(&c, 1.00, 0.32, 0.36); Sphere_new0(&spheres[1], &p, 4, &c, 1, 0.5); Vec3_new(&p, 5, -1, -15); Vec3_new(&c, 0.90, 0.76, 0.46); Sphere_new0(&spheres[2], &p, 2, &c, 1, 0.0); Vec3_new(&p, 5, 0, -25); Vec3_new(&c, 0.65, 0.77, 0.97); Sphere_new0(&spheres[3], &p, 3, &c, 1, 0.0); Vec3_new(&p, -5.5, 0, -15); Vec3_new(&c, 0.90, 0.90, 0.90); Sphere_new0(&spheres[4], &p, 3, &c, 1, 0.0); // light Vec3_new(&p, 0, 20, -30); Vec3_new0(&c); Vec3_new1(&e, 3); Sphere_new(&spheres[5], &p, 3, &c, 0, 0, &e); if(n>N){ int i,j,k; Real r,d; Vec3 v; srand48(13); for(i=N;i<n;i++){ k=0; do{ Vec3_new(&p, 12*drand48()-6,9*drand48()-4,-35*drand48()-15); r = 0.1 + drand48(); for(j=0;j<i && r>=0.1;j++){ Vec3_subs(&v,&spheres[j].center,&p); d=Vec3_length(&v)-spheres[j].radius; if(d<r)r=d; } }while(r<0.1 && ++k<1000); if(r>=0.1){ Vec3_new(&c, rand()%4/3.0,rand()%4/3.0,rand()%4/3.0); Sphere_new0(&spheres[i], &p, r, &c, drand48()<0.8?0:1, drand48()<0.8?0:0.8); }else printf("#"); } } if(argc>2){spheres[1].radius=0.4; spheres[1].radius2=0.16;} printf("Calculando...\n"); fflush(stdout); render(n, spheres); timeB = omp_get_wtime(); double timeC = timeB - timeA; printf("Se ha calculado en %f segundos\n",timeC); free(spheres); return 0; }
void Reset() { MortalWound_Timer = 10000 + rand()%5000; SpawnHatchlings_Timer = 6000 + rand()%6000; SpawnSpawns_Timer = 15000 + rand()%30000; }
double rand_my() { double v = ((double) rand() / (RAND_MAX)); return v; }
int main(int argc, char *argv[], char *envp[]) { FILE *fdata; /* .data file (input)*/ FILE *fmodel; /* .model file (output) */ FILE *fauc; /* .model.1st file (output) */ int atnl; /* at newline (flag) */ char *aucname; /* file name of the AUC file */ double baseline; char c; int divider; /* #of bins to divide in this round */ int failures_seen; /* in this bin */ int i, j, k, l; int maxrounds; /* max(@ROUNDS) */ int numbins; /* misnomer, really "this round" */ char *sca0, *sca, *scc; /* tmp variables */ int t; /* XXX - some kind of counter? */ int this_first, this_last; double this_pauc; double randnum; int *rand_seed = NULL; int total_failures; int num_scores; int init_permute_flag = 1; int unknown_meth = REL_ORDER; Score *p; Score *best; double min_auc; gargc = argc; gargv = argv; genvp = envp; /* * Make sure we grok NaNs * (unknown entries in the input file, given as '?', are * stored as not-a-number values) */ if (!isnan(nan(""))) errx(1, "Implementation does not understand NaNs"); /* * PARSE ARGUMENTS */ if (argc < 3) usage(); if ((fdata = fopen(argv[1], "r")) == NULL) err(1, "cannot open %s for reading", argv[1]); if ((fmodel = fopen(argv[2], "w")) == NULL) err(1, "cannot open %s for writing", argv[2]); if ((aucname = (char *)calloc(strlen(argv[2]) + sizeof (".1st"), 1)) == NULL) err(1, "allocating aucname"); strcpy(aucname, argv[2]); strcat(aucname, ".1st"); if ((fauc = fopen(aucname, "w")) == NULL) err(1, "cannot open %s for writing", aucname); argc -= 3; argv += 3; while (argc > 0) { if (!strcmp(argv[0], "rounds") || !strcmp(argv[0], "--rounds")) { if (argc < 2) usage(); if ((sca0 = sca = strdup(argv[1])) == NULL) err(1, "strdup: copying %s", argv[1]); while (*sca == ',') /* strip leading commas, if any */ sca++; scc = sca + strlen(sca); if (scc == sca) /* must have at least one digit! */ usage(); while (*--scc == ',') /* strip trailing commas */ *scc = '\0'; if (strchr(sca, ',')) { /* * comma-separated list of rounds, parse */ n_rounds = 0; for (scc = sca; *scc; scc++) if (*scc == ',') n_rounds++; n_rounds++; if ((rounds = (int *)calloc(n_rounds, sizeof (*rounds))) == NULL) err(1, "calloc %d rounds", n_rounds); for (i = 0; i < n_rounds; i++) { rounds[i] = strtol(sca, &scc, 10); if (rounds[i] <= 0) errx(1, "round %d must be positive", i); sca = scc + 1; } } else { n_rounds = strtol(sca, NULL, 10); } if (n_rounds <= 0) usage(); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "topk") || !strcmp(argv[0], "--topk")) { if (argc < 2) usage(); if ((sca0 = sca = strdup(argv[1])) == NULL) err(1, "strdup: copying %s", argv[1]); scc = sca + strlen(sca); if (scc == sca) /* must have at least one digit! */ usage(); topk = strtol(sca, NULL, 10); if (topk <= 0) usage(); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "miss-limit") || !strcmp(argv[0], "--miss-limit")) { if (argc < 2) usage(); if ((sca0 = sca = strdup(argv[1])) == NULL) err(1, "strdup: copying %s", argv[1]); scc = sca + strlen(sca); if (scc == sca) /* must have at least one digit! */ usage(); unknown_limit = atof(sca); if (unknown_limit < 0 || unknown_limit > 1) usage(); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--no-prob-dist")) { prob_dist_flag = 0; argc -= 1; argv += 1; } else if (!strcmp(argv[0], "--no-permute") || !strcmp(argv[0], "no-permute")) { init_permute_flag = 0; argc -= 1; argv += 1; } else if (!strcmp(argv[0], "--sort-unknowns") || !strcmp(argv[0], "sort-unknowns")) { if (argc < 2) usage(); if ((sca = strdup(argv[1])) == NULL) err(1, "strdup: copying %s", argv[1]); unknown_meth = atoi(sca); if (unknown_meth != RAND_ORDER || unknown_meth != REL_ORDER) { usage(); } argc -= 2; argv += 2; } else if (!strcmp(argv[0], "seed") || !strcmp(argv[0], "--seed")) { if (argc < 2) usage(); if ((sca0 = sca = strdup(argv[1])) == NULL) err(1, "strdup: copying %s", argv[1]); scc = sca + strlen(sca); if (scc == sca) { //must have one digit usage(); } if ((rand_seed = (int *) malloc(sizeof(int))) == NULL) err(1, "calloc one integer", 1); *rand_seed = atoi(sca); argc -= 2; argv += 2; } else { /* No other options supported */ usage(); } } /* * if we got a single number as the "rounds" argument, we * interpret it as the list 1,2,...,n */ if (rounds == NULL) { if ((rounds = (int *)calloc(n_rounds, sizeof (*rounds))) == NULL) err(1, "calloc %d rounds", n_rounds); for (i = 0; i < n_rounds; i++) rounds[i] = i+1; } /* * Prep @F and @last */ /* * find the max value in rounds[], * needed for allocating space for failures[][] and last[][] */ for (i = 0, maxrounds = 0; i < n_rounds; i++) if (maxrounds < rounds[i]) maxrounds = rounds[i]; if ((failures = (int **)calloc(n_rounds + 3, sizeof (*failures))) == NULL) err(1, "calloc %d failures", n_rounds); if ((last = (int **)calloc(n_rounds + 3, sizeof (*last))) == NULL) err(1, "calloc %d last", n_rounds); for (i = 0; i <= n_rounds; i++) { if ((failures[i] = (int *)calloc(maxrounds + 3, sizeof (**failures))) == NULL) err(1, "calloc failures[%d]", i); if ((last[i] = (int *)calloc(maxrounds + 3, sizeof (**last))) == NULL) err(1, "calloc last[%d]", i); } /* * COUNT NAMES and IDS */ /* * Start reading the first line, counting fields */ //first check to make sure there is data in the file c = fgetc(fdata); if (c == EOF) { fclose(fdata); err(1, "Error: Data file %s is empty\n", gargv[1]); } n_names = 1; /* at least one! */ /* attributes a comma separated. So count the number of commas in the first line to calculate the number of attributes in the data. */ while (!isnewline(c) && c != EOF) { if (c == ',') n_names++; c = fgetc(fdata); } /* * We've read the first line; let's keep counting lines. * There is some cruftiness in the code in order to deal with * text files with lines ending in \r\n and not just \n */ n_ids = 1; /* we've already read one line! */ atnl = 0; while ((c = fgetc(fdata)) != EOF) if (isnewline(c)) { if (!atnl) { n_ids++; atnl++; } } else { atnl = 0; } fclose(fdata); if ((fdata = fopen(gargv[1], "r")) == NULL) err(1, "cannot open %s for reading", gargv[1]); if ((tabula = (double **)calloc(n_ids, sizeof (*tabula))) == NULL) err(1, "allocating tabula"); for (i = 0; i < n_ids; i++) { if ((tabula[i] = (double *)calloc(n_names, sizeof (**tabula))) == NULL) err(1, "allocating %d-th row of table\n", i); for (j = 0; j < n_names - 1; j++) if (fscanf(fdata, "%lg,", &tabula[i][j]) != 1) { tabula[i][j] = nan(""); while (fgetc(fdata) != ',') ; } fscanf(fdata, "%lg", &tabula[i][j]); /* * XXX - a well-formed file * MUST not have the result * value (last column) be a '?' * DOUBLE_CHECK */ } total_failures = 0; for (i = 0; i < n_ids; i++) total_failures += tabula[i][n_names - 1]; printf("data_file = %s\n", gargv[1]); printf("model = %s\n", gargv[2]); printf("nr rounds = %d\tnr splits=", n_rounds); for (i = 0; i < n_rounds; i++) printf(" %d", rounds[i]); printf("\nnr_examples = %d\ttotal_failures = %d", n_ids, total_failures); printf("\tnr_attribs = %d\n", n_names); // seed random no generator if (rand_seed == NULL) { srand((unsigned)time(NULL)); } else { srand(*rand_seed); //don't need rand_seed anymore... free(rand_seed); rand_seed = NULL; } if ((order = (int *)calloc(n_ids, sizeof (*order))) == NULL) err(1, "calloc %d order", n_ids); if ((sublist_order = (int *)calloc(n_ids, sizeof (*sublist_order))) == NULL) err(1, "calloc %d sublist_order", n_ids); if ((scores = (Score *)calloc(MAX_VARS, sizeof (Score))) == NULL) err(1, "calloc %d scores", MAX_VARS); for (i = 0; i < MAX_VARS; i++) { scores[i].auc = 0; if ((scores[i].order = (int *)calloc(n_ids, sizeof (*(scores[i].order)))) == NULL) err(1, "calloc %d scores[%d].order", n_ids, i); } if ((ignore_set = (int *)calloc(n_names-1, sizeof (*ignore_set))) == NULL) err(1, "calloc %d ignore_set", n_names-1); if ((this_order = (int *)calloc(n_ids, sizeof (*this_order))) == NULL) err(1, "calloc %d this_order", n_ids); if ((best_order = (int *)calloc(n_ids, sizeof (*best_order))) == NULL) err(1, "calloc %d best_order", n_ids); /* randomize initial ordering */ if (init_permute_flag) { for (i = 0; i < n_ids; i++) order[i] = -1; for (i = 0; i < n_ids; i++) { randnum = (double)rand()/((unsigned)RAND_MAX+1); // [0,1) j = (int)(randnum*n_ids); while (order[j] != -1) j = (j + 1) % n_ids; order[j] = i; } } else { for (i = 0; i < n_ids; i++) { order[i] = i; } } /* find variables to ignore */ for (i = 0; i < n_names-1; i++) { ignore_set[i] = 0; if (check_var(i,n_ids, unknown_limit) < 0) ignore_set[i] = 1; } /* iteration over rounds */ for (numbins = 1; numbins <= n_rounds; numbins++) { printf("round = %d\tsplits = %d\n", numbins, rounds[numbins - 1]); t = 0; failures_seen = 0; for (divider = 0; divider < rounds[numbins - 1]; divider++) { while ((failures_seen < ((divider + 1) * (double)total_failures / rounds[numbins - 1])) && (t < n_ids)) { failures_seen += tabula[order[t]][n_names-1]; t++; } last[numbins][divider] = t - 1; failures[numbins][divider] = failures_seen; if (divider == (rounds[numbins - 1] - 1)) failures[numbins][divider+1] = total_failures - failures_seen; } this_first = 0; /* find the first element of the sublist */ /* iteration over bins in this round */ for (j = 0; j < rounds[numbins - 1]; j++) { if (j < rounds[numbins - 1] - 1) this_last = last[numbins][j]; else this_last = n_ids - 1; printf("\tbin %d: [%d..%d] %d failures", j, this_first, this_last, failures[numbins][j] - (j ? failures[numbins][j-1] : 0)); printf("\t(%.12f%%)\n", (this_last - this_first + 1) * 100.0 / n_ids); // ordering from previous round for (k = this_first; k <= this_last; k++) sublist_order[k - this_first] = order[k]; baseline = pauc(sublist_order, this_last - this_first + 1); // reset scores for (k = 1; k < MAX_VARS; k++) scores[k].auc = 0; min_score_ptr = NULL; num_scores = 0; /* iteration over variables for this bin */ for (exti = 0; exti < n_names - 1; exti++) { if (ignore_set[exti]) continue; /* variable ascending */ for (k = this_first; k <= this_last; k++) this_order[k - this_first] = sublist_order[k - this_first]; if (sort_examples((void *)this_order, this_last - this_first + 1, sizeof (*this_order), compasc, unknown_meth) < 0) err(1, "sort_examples this_order ascending"); this_pauc = pauc(this_order, this_last - this_first + 1); if (numbins == 1) fprintf(fauc, "VAR=%d AUC=%f DIR=asc\n", exti, this_pauc); if (this_pauc > baseline) insert_score(scores, &num_scores, exti, "a", this_pauc, this_order, this_last - this_first + 1); /* variable descending */ for (k = this_first; k <= this_last; k++) this_order[k - this_first] = sublist_order[k - this_first]; if (sort_examples((void *)this_order, this_last - this_first + 1, sizeof (*this_order), compdesc, unknown_meth) < 0) err(1, "sort_examples this_order descending"); this_pauc = pauc(this_order, this_last - this_first + 1); if (numbins == 1) fprintf(fauc, "VAR=%d AUC=%f DIR=desc\n", exti, this_pauc); if (this_pauc > baseline) insert_score(scores, &num_scores, exti, "d", this_pauc, this_order, this_last - this_first + 1); } /* end variables loop */ if (num_scores > 0) { // sort scores in desc order of auc if (mergesort((void *)scores, num_scores, sizeof (*scores), comp_auc_desc) < 0) err(1, "mergesort scores descending"); if (prob_dist_flag) { // pick top variable probabilistically // XXX: pick topk vars and compute avg sort auc_to_dist(scores, num_scores); best = weighted_rand(scores, num_scores); } else best = scores; // merge results into main array for (k = this_first; k <= this_last; k++) order[k] = (*best).order[k - this_first]; // update model fprintf(fmodel, "%.12f,%1d,%s", (this_last + 1) / (double) n_ids, best->var, best->dir); fflush(fmodel); } else { fprintf(fmodel, "%.12f,nop", (this_last + 1) / (double) n_ids); fflush(fmodel); } if (j < rounds[numbins - 1] - 1) { fprintf(fmodel, ";"); fflush(fmodel); } this_first = this_last + 1; } /* end bins loop */ fprintf(fmodel, "\n"); fflush(fmodel); printf(" Overall training AUC %.6f\n", pauc(order, n_ids)); } /* end rounds loop */ fclose(fmodel); fclose(fauc); exit(0); }
void UpdateAI(const uint32 diff) { if (!m_creature->SelectHostilTarget() || !m_creature->getVictim()) return; //Check for Frost Bolt if (FrostBolt_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_FROST_BOLT); FrostBolt_Timer = (rand()%60)*1000; }else FrostBolt_Timer -= diff; //Check for Frost Bolt Nova if (FrostBoltNova_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_FROST_BOLT_NOVA); FrostBoltNova_Timer = 15000; }else FrostBoltNova_Timer -= diff; //Check for Chains Of Kelthuzad if (ChainsOfKelthuzad_Timer < diff) { //DoCast(m_creature->getVictim(),SPELL_CHAINS_OF_KELTHUZAD); //if (rand()%2) //DoScriptText(SAY_CHAIN1, m_creature); //else //DoScriptText(SAY_CHAIN2, m_creature); ChainsOfKelthuzad_Timer = (rand()%30+30)*1000; }else ChainsOfKelthuzad_Timer -= diff; //Check for Mana Detonation if (ManaDetonation_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_MANA_DETONATION); if (rand()%2) DoScriptText(SAY_SPECIAL1_MANA_DET, m_creature); ManaDetonation_Timer = 20000; }else ManaDetonation_Timer -= diff; //Check for Shadow Fissure if (ShadowFisure_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_SHADOW_FISURE); if (rand()%2) DoScriptText(SAY_SPECIAL3_MANA_DET, m_creature); ShadowFisure_Timer = 25000; }else ShadowFisure_Timer -= diff; //Check for Frost Blast if (FrostBlast_Timer < diff) { DoCast(m_creature->getVictim(),SPELL_FROST_BLAST); if (rand()%2) DoScriptText(SAY_FROST_BLAST, m_creature); FrostBlast_Timer = (rand()%30+30)*1000; }else FrostBlast_Timer -= diff; //start phase 3 when we are 40% health if (!Phase3 && (m_creature->GetHealth()*100 / m_creature->GetMaxHealth()) < 40) { Phase3 = true; DoScriptText(SAY_REQUEST_AID, m_creature); //here Lich King should respond to KelThuzad but I don't know which creature to make talk //so for now just make Kelthuzad says it. DoScriptText(SAY_ANSWER_REQUEST, m_creature); } if (Phase3 && (GuardiansOfIcecrown_Count < 5)) { if (GuardiansOfIcecrown_Timer < diff) { //Summon a Guardian of Icecrown in a random alcove (Creature # 16441) //uint32 TimeToWalk; Creature* pUnit = NULL; float Walk_Pos_X; float Walk_Pos_Y; float Walk_Pos_Z; switch(rand()%6) { case 0: pUnit = m_creature->SummonCreature(16441,ADDX_LEFT_FAR,ADDY_LEFT_FAR,ADDZ_LEFT_FAR,ADDO_LEFT_FAR,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000); //Setting walk position Walk_Pos_X = WALKX_LEFT_FAR; Walk_Pos_Y = WALKY_LEFT_FAR; Walk_Pos_Z = WALKZ_LEFT_FAR; break; case 1: pUnit = m_creature->SummonCreature(16441,ADDX_LEFT_MIDDLE,ADDY_LEFT_MIDDLE,ADDZ_LEFT_MIDDLE,ADDO_LEFT_MIDDLE,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000); //Start moving guardian towards the center of the room Walk_Pos_X = WALKX_LEFT_MIDDLE; Walk_Pos_Y = WALKY_LEFT_MIDDLE; Walk_Pos_Z = WALKZ_LEFT_MIDDLE; break; case 2: pUnit = m_creature->SummonCreature(16441,ADDX_LEFT_NEAR,ADDY_LEFT_NEAR,ADDZ_LEFT_NEAR,ADDO_LEFT_NEAR,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000); //Start moving guardian towards the center of the room Walk_Pos_X = WALKX_LEFT_NEAR; Walk_Pos_Y = WALKY_LEFT_NEAR; Walk_Pos_Z = WALKZ_LEFT_NEAR; break; case 3: pUnit = m_creature->SummonCreature(16441,ADDX_RIGHT_FAR,ADDY_RIGHT_FAR,ADDZ_RIGHT_FAR,ADDO_RIGHT_FAR,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000); //Start moving guardian towards the center of the room Walk_Pos_X = WALKX_RIGHT_FAR; Walk_Pos_Y = WALKY_RIGHT_FAR; Walk_Pos_Z = WALKZ_RIGHT_FAR; break; case 4: pUnit = m_creature->SummonCreature(16441,ADDX_RIGHT_MIDDLE,ADDY_RIGHT_MIDDLE,ADDZ_RIGHT_MIDDLE,ADDO_RIGHT_MIDDLE,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000); //Start moving guardian towards the center of the room Walk_Pos_X = WALKX_RIGHT_MIDDLE; Walk_Pos_Y = WALKY_RIGHT_MIDDLE; Walk_Pos_Z = WALKZ_RIGHT_MIDDLE; break; case 5: pUnit = m_creature->SummonCreature(16441,ADDX_RIGHT_NEAR,ADDY_RIGHT_NEAR,ADDZ_RIGHT_NEAR,ADDO_RIGHT_NEAR,TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT,1000); //Start moving guardian towards the center of the room Walk_Pos_X = WALKX_RIGHT_NEAR; Walk_Pos_Y = WALKY_RIGHT_NEAR; Walk_Pos_Z = WALKZ_RIGHT_NEAR; break; } if (pUnit) { //if we find no one to figth walk to the center if (!pUnit->isInCombat()) pUnit->SendMonsterMoveWithSpeed(Walk_Pos_X,Walk_Pos_Y,Walk_Pos_Z); //Safe storing of creatures GuardiansOfIcecrown[GuardiansOfIcecrown_Count] = pUnit->GetGUID(); //Update guardian count GuardiansOfIcecrown_Count++; } //5 seconds until summoning next guardian GuardiansOfIcecrown_Timer = 5000; }else GuardiansOfIcecrown_Timer -= diff; } DoMeleeAttackIfReady(); }
double maths_rand(double a, double b) { return (b - a) * ((double)rand() / RAND_MAX) + a; }
int main(int argc, char *argv[]) { srand(time(NULL)); bool giveme = false; long zero = 0; char buf[100]; bool gotflag = false; puts("Welcome to hell, we have real strong JumpFu here"); start: DBUG("start") puts("Where to?"); fflush(0); zero = 0; fgets(buf, 117, stdin); buf[99] = 0; if (strncmp(buf+10, "WHO GOES THERE", strlen("WHO GOES THERE")) == 10) goto six; else goto two; one: DBUG("one") puts("WELCOME BACK"); goto start; two: DBUG("two") puts("Who are you? Where are you even going?"); fflush(0); if (buf[69]=='8') goto eleven; if (buf[69]=='9') goto five; goto one; three: DBUG("three") puts("Here we go again..."); fflush(0); goto eight; four: DBUG("four") if (!zero) goto nine; five: DBUG("five") giveme = true; if (!zero) goto eight; six: DBUG("six") giveme = false; seven: //lucky number seven DBUG("seven") if (giveme){ gotflag = true; print_flag(); goto end; }else{ puts("NO!!! GO AWAY"); fflush(0); } eight: DBUG("eight") puts("Goodnight! See you later!"); fflush(0); sleep(1); if (rand() % 2) goto one; else goto twelve; nine: DBUG("nine") goto two; ten: DBUG("ten") if (!zero) goto end; goto one; eleven: DBUG("eleven") if (strncmp(&zero, "risky!", strlen("risky"))) goto eight; goto six; twelve: DBUG("twelve") if (zero) goto seven; else goto ten; end: DBUG("end") if (!gotflag) puts("Looks like you are leavin here empty handed."); else puts("Nice work. You won."); fflush(0); return 0; }
float randomDouble(double min, double max){ return (rand() / (static_cast<float>(RAND_MAX) + 1.0)) * (max - min) + min; }
int randomInt(int min, int max){ return rand() % (max-min) + min; }
// CONSTRUCTOR FOR BABIES (born creatures) Creature::Creature(sf::Vector2u& w, Creature* dad, Creature* mum) : moveAction(w, position) { windowSize = &w; init(); // POSITION OF MUM position = sf::Vector2f(mum->getPosition().x, mum->getPosition().y); // INHERIT CHARACTERISTICS FROM MUM OR DAD CREATURE // SIZE: INTERPOLATION OF MUM AND DAD int mutationRisk = rand()%100; size = (dad->getSize() + mum->getSize()) / 2; if(mutationRisk > 95) size = rand()%5 + 10.f; // SIGHT: INTERPOLATION OF MUM AND DAD mutationRisk = rand()%100; sightRadius = (dad->getSightRadius() + mum->getSightRadius()) / 2; if(mutationRisk > 95) sightRadius = size + rand()%100; // COLOR: RANDOM MUM OR DAD mutationRisk = rand()%100; body.setFillColor((rand()%2 == 0) ? dad->getColor() : mum->getColor()); if(mutationRisk > 95) body.setFillColor(sf::Color(rand()%255, rand()%255, rand()%255, 200)); // LIFETIME: RANDOM MUM OR DAD mutationRisk = rand()%100; timeToLive = (rand()%2 == 0) ? dad->getTTL() : mum->getTTL(); if(mutationRisk > 95) timeToLive = rand()%10000 + 100; // REPLICATION TIMER: RANDOM MUM OR DAD mutationRisk = rand()%100; timeToReplicate = (rand()%2 == 0) ? dad->getTTR() : mum->getTTR(); if(mutationRisk > 95) timeToReplicate = rand()%800 + 200; // REPLICATION DURATION:INTERPOLATION OF MUM AND DAD mutationRisk = rand()%100; replicationDuration = (dad->getReplicationDuration() + mum->getReplicationDuration()) / 2; if(mutationRisk > 95) replicationDuration = rand()%1000 + 200; }
int random(int a,int b) //returns a pseudo random integer between a and b { int d=b-a; return a+rand()%d; }
void UpdateAI(const uint32 diff) { if (!UpdateVictim()) return; if (Assassins_Timer) { if (Assassins_Timer <= diff) { SpawnAssassin(); Assassins_Timer = 0; } else Assassins_Timer -= diff; } if (InBlade) { if (Wait_Timer) { if (Wait_Timer <= diff) { if (target_num <= 0) { // stop bladedance InBlade = false; me->SetSpeed(MOVE_RUN, 2); (*me).GetMotionMaster()->MoveChase(me->getVictim()); Blade_Dance_Timer = 30000; Wait_Timer = 0; if (HeroicMode) Charge_timer = 5000; } else { //move in bladedance float x, y, randx, randy; randx = float(rand() % 40); randy = float(rand() % 40); x = 210 + randx ; y = -60 - randy ; (*me).GetMotionMaster()->MovePoint(1, x, y, me->GetPositionZ()); Wait_Timer = 0; } } else Wait_Timer -= diff; } } else { if (Blade_Dance_Timer) { if (Blade_Dance_Timer <= diff) { target_num = TARGET_NUM; Wait_Timer = 1; InBlade = true; Blade_Dance_Timer = 0; me->SetSpeed(MOVE_RUN, 4); return; } else Blade_Dance_Timer -= diff; } if (Charge_timer) { if (Charge_timer <= diff) { DoCast(SelectUnit(SELECT_TARGET_RANDOM, 0), H_SPELL_CHARGE); Charge_timer = 0; } else Charge_timer -= diff; } if (Summon_Assistant_Timer <= diff) { for (uint32 i = 0; i < summoned; i++) { switch (rand() % 3) { case 0: me->SummonCreature(MOB_HEARTHEN_GUARD, AddsEntrance[0], AddsEntrance[1], AddsEntrance[2], 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000); break; case 1: me->SummonCreature(MOB_SHARPSHOOTER_GUARD, AddsEntrance[0], AddsEntrance[1], AddsEntrance[2], 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000); break; case 2: me->SummonCreature(MOB_REAVER_GUARD, AddsEntrance[0], AddsEntrance[1], AddsEntrance[2], 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 10000); break; } } if (rand() % 100 < 6) summoned++; Summon_Assistant_Timer = 15000 + (rand() % 5000) ; } else Summon_Assistant_Timer -= diff; DoMeleeAttackIfReady(); } if (resetcheck_timer <= diff) { float tempx; tempx = me->GetPositionX(); if (tempx > 255 || tempx < 205) { EnterEvadeMode(); return; } resetcheck_timer = 5000; } else resetcheck_timer -= diff; }
void UpdateAI(const uint32 diff) { if (!UpdateVictim()) { if(UnsummonCheck < diff && m_creature->isAlive()) { m_creature->SetLootRecipient(NULL); m_creature->SetVisibility(VISIBILITY_OFF); m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); m_creature->RemoveCorpse(); }else UnsummonCheck -= diff; return; } if(Fireball_Timer < diff) { if(Unit *victim = SelectUnit(SELECT_TARGET_RANDOM,0)) DoCast(victim, SPELL_FIREBALL,true); Fireball_Timer = 4000+rand()%3000; }else Fireball_Timer -= diff; if(flight) // phase 1 - the flight { Creature *Vazruden = Unit::GetCreature(*m_creature,VazrudenGUID); if(Fly_Timer < diff || !(Vazruden && Vazruden->isAlive() && (Vazruden->GetHealth()*5 > Vazruden->GetMaxHealth()))) { flight = false; BellowingRoar_Timer = 6000; ConeOfFire_Timer = 12000; m_creature->RemoveUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT + MOVEMENTFLAG_LEVITATING); m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); m_creature->GetMotionMaster()->Clear(); if(Unit *victim = SelectUnit(SELECT_TARGET_NEAREST,0)) m_creature->AI()->AttackStart(victim); DoStartMovement(m_creature->getVictim()); DoScriptText(EMOTE, m_creature); return; }else Fly_Timer -= diff; if(Turn_Timer < diff) { uint32 waypoint = (Fly_Timer/10000)%2; if(m_creature->GetDistance(VazrudenRing[waypoint][0],VazrudenRing[waypoint][1],VazrudenRing[waypoint][2]) > 5) m_creature->GetMotionMaster()->MovePoint(0,VazrudenRing[waypoint][0],VazrudenRing[waypoint][1],VazrudenRing[waypoint][2]); Turn_Timer = 10000; }else Turn_Timer -= diff; } else // phase 2 - land fight { if(ConeOfFire_Timer < diff) { DoCast(m_creature, SPELL_CONE_OF_FIRE); ConeOfFire_Timer = 12000; Fireball_Timer = 4000; }else ConeOfFire_Timer -= diff; if(HeroicMode && BellowingRoar_Timer < diff) { DoCast(m_creature, SPELL_BELLOWING_ROAR); BellowingRoar_Timer = 45000; }else BellowingRoar_Timer -= diff; DoMeleeAttackIfReady(); } }
float random(float minimum, float maximum) { return minimum + static_cast <float> (rand()) / ( static_cast <float> (RAND_MAX/(maximum - minimum))); }
int pdgl_main_body() { static float hull_planes[]= { 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, -1, 1, 0, 1, -1, 0, 0, 1, -1, -1, 0, 1, 0, -1, 0, 1, 1, -1, 0, 1, 0, 0, 1, 1, 0, 0, -1, 1, }; static int t; char buf[64]; float mins[3], maxs[3]; float io[3], iv[4], fw[2], pt[4], f, g, v; float im[16], im1[16]; int i, j, k; unsigned short *kcur; main_time+=pdgl_dt_f; V3F_COPY(main_cam_org, main_dlight_org); V3F_ZERO(main_dlight_org+3); main_dlight_org[3]=sin(main_time*0.25)*75; main_dlight_org[4]=cos(main_time*0.25)*75; main_dlight_org[5]=10; kcur=pdgl_keybuf; f=main_cam_ang[2]*(M_PI/180); fw[0]=-sin(f); fw[1]=cos(f); bsdeGetAttrFV(main_cam_id, BSDE_ORIGIN, main_cam_org, 3); bsdeGetAttrFV(main_cam_id, BSDE_VELOCITY, main_cam_vel, 3); if(main_cam_raw) { bsdeHide(main_cam_id); } else { bsdeUnhide(main_cam_id); } io[0]=main_cam_org[0]-10*sin(f); io[1]=main_cam_org[1]+10*cos(f); io[2]=main_cam_org[2]; f=(((rand()&0xFFF)/2048.0)-1)*0.1; g=(((rand()&0xFFF)/2048.0)-1)*0.1; io[0]+=f; io[1]+=g; v=1000; while(*kcur) { if(*kcur==K_ESCAPE) { main_kill=1; return(-1); } if(*kcur==K_F10) { // Tex_DoScreenshot(); } if(*kcur==K_F2) { main_cam_raw=!main_cam_raw; } if(*kcur=='a') { i=bsdeNewOBB(-1, -1, -1, 1, 1, 1); main_objs[main_nobjs++]=i; main_addsolid(i); // bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3); bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3); bsdeSetAttrF(i, BSDE_DENSITY, 1); bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3); if(PDGL_KeyDown(K_ALT)) bsdeSetAttrFV(i, BSDE_VELOCITY, VEC3(v*fw[0], v*fw[1], 0), 3); } if(*kcur=='A') { i=bsdeNewAABB(-2, -2, -2, 2, 2, 2); main_objs[main_nobjs++]=i; main_addsolid(i); // bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3); bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3); bsdeSetAttrF(i, BSDE_DENSITY, 1); bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3); if(PDGL_KeyDown(K_ALT)) bsdeSetAttrFV(i, BSDE_VELOCITY, VEC3(v*fw[0], v*fw[1], 0), 3); } if(*kcur=='s') { i=bsdeNewSphere(1); main_objs[main_nobjs++]=i; main_addsolid(i); // bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3); bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3); bsdeSetAttrF(i, BSDE_DENSITY, 1); bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3); if(PDGL_KeyDown(K_ALT)) bsdeSetAttrFV(i, BSDE_VELOCITY, VEC3(v*fw[0], v*fw[1], 0), 3); } if(*kcur=='c') { i=bsdeNewCappedCylinder(2, 1); main_objs[main_nobjs++]=i; main_addsolid(i); // bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3); bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3); bsdeSetAttrF(i, BSDE_DENSITY, 1); bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3); if(PDGL_KeyDown(K_ALT)) bsdeSetAttrFV(i, BSDE_VELOCITY, VEC3(v*fw[0], v*fw[1], 0), 3); } if(*kcur=='C') { i=bsdeNewCylinder(2, 1); main_objs[main_nobjs++]=i; main_addsolid(i); // bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3); bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3); bsdeSetAttrF(i, BSDE_DENSITY, 1); bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3); if(PDGL_KeyDown(K_ALT)) bsdeSetAttrFV(i, BSDE_VELOCITY, VEC3(v*fw[0], v*fw[1], 0), 3); } if(*kcur=='h') { i=bsdeNewHullF(hull_planes, 10); main_objs[main_nobjs++]=i; main_addsolid(i); // bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3); bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3); bsdeSetAttrF(i, BSDE_DENSITY, 1); bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3); if(PDGL_KeyDown(K_ALT)) bsdeSetAttrFV(i, BSDE_VELOCITY, VEC3(v*fw[0], v*fw[1], 0), 3); } if(*kcur=='m') { i=bsdeNewTriMeshF(main_gear_vecs, main_gear_tris, main_gear_nvecs, main_gear_ntris); main_objs[main_nobjs++]=i; main_addsolid(i); // bsdeSetAttrFV(i, BSDE_ORIGIN, VEC3(f, g, 10), 3); bsdeSetAttrFV(i, BSDE_ORIGIN, io, 3); bsdeSetAttrF(i, BSDE_DENSITY, 1); bsdeSetAttrFV(i, BSDE_VELOCITY, main_cam_vel, 3); if(PDGL_KeyDown(K_ALT)) bsdeSetAttrFV(i, BSDE_VELOCITY, VEC3(v*fw[0], v*fw[1], 0), 3); } kcur++; } V3F_ZERO(iv); if(PDGL_KeyDown(K_SHIFT)) { f=main_cam_ang[2]*(M_PI/180); if(PDGL_KeyDown(K_LEFTARROW)) { // main_cam_org[0]-=pdgl_dt_f*15*cos(f); // main_cam_org[1]-=pdgl_dt_f*15*sin(f); iv[0]-=pdgl_dt_f*15*cos(f); iv[1]-=pdgl_dt_f*15*sin(f); } if(PDGL_KeyDown(K_RIGHTARROW)) { // main_cam_org[0]+=pdgl_dt_f*15*cos(f); // main_cam_org[1]+=pdgl_dt_f*15*sin(f); iv[0]+=pdgl_dt_f*15*cos(f); iv[1]+=pdgl_dt_f*15*sin(f); } } else { if(PDGL_KeyDown(K_LEFTARROW))main_cam_ang[2]+=90*pdgl_dt_f; if(PDGL_KeyDown(K_RIGHTARROW))main_cam_ang[2]-=90*pdgl_dt_f; } if(PDGL_KeyDown(K_UPARROW))main_cam_ang[0]+=90*pdgl_dt_f; if(PDGL_KeyDown(K_DOWNARROW))main_cam_ang[0]-=90*pdgl_dt_f; f=main_cam_ang[2]*(M_PI/180); if(PDGL_KeyDown(K_HOME)) { // main_cam_org[0]-=pdgl_dt_f*15*sin(f); // main_cam_org[1]+=pdgl_dt_f*15*cos(f); iv[0]-=pdgl_dt_f*15*sin(f); iv[1]+=pdgl_dt_f*15*cos(f); } if(PDGL_KeyDown(K_END)) { // main_cam_org[0]+=pdgl_dt_f*15*sin(f); // main_cam_org[1]-=pdgl_dt_f*15*cos(f); iv[0]+=pdgl_dt_f*15*sin(f); iv[1]-=pdgl_dt_f*15*cos(f); } // if(PDGL_KeyDown(K_PGUP))main_cam_org[2]+=pdgl_dt_f*15; // if(PDGL_KeyDown(K_PGDN))main_cam_org[2]-=pdgl_dt_f*15; if(PDGL_KeyDown(K_PGUP))iv[2]+=pdgl_dt_f*15; if(PDGL_KeyDown(K_PGDN))iv[2]-=pdgl_dt_f*15; if(main_cam_raw) { V3F_ADD(main_cam_org, iv, pt); bsdeSetAttrFV(main_cam_id, BSDE_ORIGIN, pt, 3); V3F_ZERO(pt); bsdeSetAttrFV(main_cam_id, BSDE_VELOCITY, pt, 3); } else { // Vec3F_Add(main_cam_vel, iv, pt); // Vec3F_Scale(iv, 1.0/pdgl_dt_f, pt); // pt[0]=iv[0]/pdgl_dt_f; // pt[1]=iv[1]/pdgl_dt_f; // pt[2]=iv[2]/pdgl_dt_f+main_cam_vel[2]; // bsdeSetAttrFV(main_cam_id, BSDE_VELOCITY, pt, 3); // bsdeGetAttrFV(main_cam_id, BSDE_VELOCITY, pt, 3); // V3F_ADDSCALE(pt, iv, 1.0/pdgl_dt_f, pt); // pt[0]=pt[0]*0.1+iv[0]*(1.0/pdgl_dt_f); // pt[1]=pt[1]*0.1+iv[1]*(1.0/pdgl_dt_f); // pt[2]=pt[2]+iv[2]*(1.0/pdgl_dt_f); // V3F_SCALE(iv, 1.0/pdgl_dt_f, pt); // bsdeSetAttrFV(main_cam_id, BSDE_CONTACT_VELOCITY, pt, 3); // bsdeSetAttrF(main_cam_id, BSDE_CONTACT_POWER, 500); // bsdeSetAttrFV(main_cam_id, BSDE_VELOCITY, pt, 3); V3F_SCALE(iv, 0.25*1.0/pdgl_dt_f, pt); pt[2]*=0.15; bsdeSetAttrFV(main_cam_id, BSDE_WANTED_VELOCITY, pt, 3); bsdeSetAttrI(main_cam_id, BSDE_WANTED_VELOCITY, 1); } // Draw_SetPerspective_3D(4.0/3.0, 90, 0, // VEC3(0, -15, 5), VEC3(90-45, 0, 0), 0, 0, pdgl_xs, pdgl_ys); // Draw_SetPerspective_3D(4.0/3.0, 90, 0, // VEC3(0, -10, 5), VEC3(90-45, 0, 0), 0, 0, pdgl_xs, pdgl_ys); // Draw_SetPerspective_3D(4.0/3.0, 90, 0, // VEC3(0, -15, 0), VEC3(90, 0, 0), 0, 0, pdgl_xs, pdgl_ys); Draw_SetPerspective_3D(4.0/3.0, 90, 0, main_cam_org, main_cam_ang, 0, 0, pdgl_xs, pdgl_ys); glDisable(GL_CULL_FACE); glDisable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); pt[0]=0.8; pt[1]=0.8; pt[2]=0.8; pt[3]=1; glMaterialfv(GL_FRONT, GL_DIFFUSE, pt); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pt); pt[0]=main_cam_org[0]; pt[1]=main_cam_org[1]; pt[2]=main_cam_org[2]; pt[3]=1; glLightfv(GL_LIGHT0, GL_POSITION, pt); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 1.0/1000.0); // glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0/100000.0); glEnable(GL_LIGHT0); glDisable(GL_LIGHTING); if(main_bsp) { relink_ents(); // pdgl_main_drawlightnode(main_bsp, main_bsp); pdgl_main_faceid=0; pdgl_main_drawnode(main_bsp); } else { draw_ents2(); } glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glColor4f(1, 0, 0, 1); glBegin(GL_LINES); glVertex3f(io[0], io[1], io[2]); glVertex3f(io[0], io[1], io[2]-50); glEnd(); f=bsdeGetWorldAttrF(BSDE_REALTIME); // g=bsdeGetWorldAttrF(BSDE_WORLDTIME); // printf("rt %f wt %f\n", f, g); bsdeStepWorld(pdgl_dt/1000.0); // bsdeStepWorld(1.0/1000.0); Draw_SetSolid2_2D(4.0/3.0, 400, VEC3(0, 0, 0), VEC3(0, 0, 0), 0, 0, pdgl_xs, pdgl_ys); // GfxFont_SetFont("fixed", 0); // kprints(buf, "%2.2f fps", 1.0/(pdgl_dt/1000.0)); // GfxFont_DrawString(buf, -400, 300-12-8, // 8, 8, 0, 255, 0, 255); kcur=pdgl_keybuf; while(*kcur) { if(*kcur==K_F10) { glFinish(); // Tex_DoScreenshot(); } kcur++; } main_vidbuf_t+=pdgl_dt_f; if(main_vidbuf_fd && (main_vidbuf_t>1.0/15.0)) { main_vidbuf_t-=1.0/15.0; glFinish(); glReadPixels (0, 0, 800, 600, GL_RGBA, GL_UNSIGNED_BYTE, main_vidbuf); fwrite(main_vidbuf, 1, 800*600*4, main_vidbuf_fd); } return(0); }
void UpdateAI(const uint32 diff) { //Return since we have no target if (!UpdateVictim()) return; //MortalWound_Timer if (MortalWound_Timer <= diff) { DoCast(me->getVictim(),SPELL_MORTAL_WOUND); MortalWound_Timer = 10000 + rand()%10000; } else MortalWound_Timer -= diff; //Summon 1-3 Spawns of Fankriss at random time. if (SpawnSpawns_Timer <= diff) { switch (rand()%3) { case 0: SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0)); break; case 1: SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0)); SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0)); break; case 2: SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0)); SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0)); SummonSpawn(SelectUnit(SELECT_TARGET_RANDOM,0)); break; } SpawnSpawns_Timer = 30000 + rand()%30000; } else SpawnSpawns_Timer -= diff; // Teleporting Random Target to one of the three tunnels and spawn 4 hatchlings near the gamer. //We will only telport if fankriss has more than 3% of hp so teleported gamers can always loot. if (me->GetHealth()*100 / me->GetMaxHealth() > 3) { if (SpawnHatchlings_Timer <= diff) { Unit* pTarget = NULL; pTarget = SelectUnit(SELECT_TARGET_RANDOM,0); if (pTarget && pTarget->GetTypeId() == TYPEID_PLAYER) { DoCast(pTarget, SPELL_ROOT); if (DoGetThreat(pTarget)) DoModifyThreatPercent(pTarget, -100); switch (rand()%3) { case 0: DoTeleportPlayer(pTarget, -8106.0142f,1289.2900f,-74.419533f,5.112f); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()-3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()+3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()-5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()+5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); break; case 1: DoTeleportPlayer(pTarget, -7990.135354f,1155.1907f,-78.849319f,2.608f); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()-3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()+3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()-5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()+5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); break; case 2: DoTeleportPlayer(pTarget,-8159.7753f,1127.9064f,-76.868660f,0.675f); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()-3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-3, pTarget->GetPositionY()+3, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()-5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); Hatchling = me->SummonCreature(15962, pTarget->GetPositionX()-5, pTarget->GetPositionY()+5, pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 15000); if (Hatchling) ((CreatureAI*)Hatchling->AI())->AttackStart(pTarget); break; } } SpawnHatchlings_Timer = 45000 + rand()%15000; } else SpawnHatchlings_Timer -= diff; } DoMeleeAttackIfReady(); }
void KilledUnit(Unit* Victim) { if(!(rand()%5)) DoScriptText(SAY_SLAY, me); }
/********************************************************************* * * GUIDEMO_Speed */ void GUIDEMO_Speed(void) { int TimeStart, i; U32 PixelsPerSecond; unsigned aColorIndex[8]; int xSize, ySize, vySize; GUI_RECT Rect, ClipRect; char cText[40] = { 0 }; xSize = LCD_GetXSize(); ySize = LCD_GetYSize(); vySize = LCD_GetVYSize(); #if GUI_SUPPORT_CURSOR GUI_CURSOR_Hide(); #endif if (vySize > ySize) { ClipRect.x0 = 0; ClipRect.y0 = 0; ClipRect.x1 = xSize; ClipRect.y1 = ySize; GUI_SetClipRect(&ClipRect); } GUIDEMO_ShowIntro("High speed", "Multi layer clipping\n" "Highly optimized drivers"); for (i = 0; i< 8; i++) { aColorIndex[i] = GUI_Color2Index(_aColor[i]); } TimeStart = GUIDEMO_GetTime(); for (i = 0; ((GUIDEMO_GetTime() - TimeStart) < 5000) && (GUIDEMO_CheckCancel() == 0); i++) { GUI_SetColorIndex(aColorIndex[i&7]); // // Calculate random positions // Rect.x0 = rand() % xSize - xSize / 2; Rect.y0 = rand() % ySize - ySize / 2; Rect.x1 = Rect.x0 + 20 + rand() % xSize; Rect.y1 = Rect.y0 + 20 + rand() % ySize; GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1); // // Clip rectangle to visible area and add the number of pixels (for speed computation) // if (Rect.x1 >= xSize) { Rect.x1 = xSize - 1; } if (Rect.y1 >= ySize) { Rect.y1 = ySize - 1; } if (Rect.x0 < 0 ) { Rect.x0 = 0; } if (Rect.y1 < 0) { Rect.y1 = 0; } GUI_Exec(); // // Allow short breaks so we do not use all available CPU time ... // } GUIDEMO_NotifyStartNext(); PixelsPerSecond = _GetPixelsPerSecond(); GUI_SetClipRect(NULL); GUIDEMO_DrawBk(0); GUI_SetColor(GUI_WHITE); GUI_SetTextMode(GUI_TM_TRANS); GUI_SetFont(&GUI_FontRounded22); GUI_DrawBitmap(&bmSTLogo70x35, 5, 5); GUIDEMO_AddStringToString(cText, "Pixels/sec: "); GUIDEMO_AddIntToString(cText, PixelsPerSecond); GUI_DispStringHCenterAt(cText, xSize >> 1, (ySize - GUI_GetFontSizeY()) >> 1); GUIDEMO_Delay(4000); #if GUI_SUPPORT_CURSOR GUI_CURSOR_Show(); #endif }
void UpdateAI(const uint32 diff) { //Only if not incombat check if the event is started if (!me->isInCombat() && pInstance && pInstance->GetData(DATA_KARATHRESSEVENT)) { Unit *pTarget = Unit::GetUnit((*me), pInstance->GetData64(DATA_KARATHRESSEVENT_STARTER)); if (pTarget) { AttackStart(pTarget); GetAdvisors(); } } //Return since we have no target if (!UpdateVictim()) return; //someone evaded! if (pInstance && !pInstance->GetData(DATA_KARATHRESSEVENT)) { EnterEvadeMode(); return; } //CataclysmicBolt_Timer if (CataclysmicBolt_Timer <= diff) { //select a random unit other than the main tank Unit *pTarget = SelectUnit(SELECT_TARGET_RANDOM, 1); //if there aren't other units, cast on the tank if (!pTarget) pTarget = me->getVictim(); if (pTarget) DoCast(pTarget, SPELL_CATACLYSMIC_BOLT); CataclysmicBolt_Timer = 10000; } else CataclysmicBolt_Timer -= diff; //SearNova_Timer if (SearNova_Timer <= diff) { DoCast(me->getVictim(), SPELL_SEAR_NOVA); SearNova_Timer = 20000+rand()%40000; } else SearNova_Timer -= diff; //Enrage_Timer if (Enrage_Timer <= diff) { DoCast(me, SPELL_ENRAGE); Enrage_Timer = 90000; } else Enrage_Timer -= diff; //Blessing of Tides Trigger if (!HealthAbovePct(75) && !BlessingOfTides) { BlessingOfTides = true; bool continueTriggering = false; Creature* Advisor; for (uint8 i = 0; i < MAX_ADVISORS; ++i) if (Advisors[i]) { Advisor = (Unit::GetCreature(*me, Advisors[i])); if (Advisor && Advisor->isAlive()) { continueTriggering = true; break; } } if (continueTriggering) { DoCast(me, SPELL_BLESSING_OF_THE_TIDES); me->MonsterYell(SAY_GAIN_BLESSING_OF_TIDES, LANG_UNIVERSAL, NULL); DoPlaySoundToSet(me, SOUND_GAIN_BLESSING_OF_TIDES); } } DoMeleeAttackIfReady(); }
inline double random(double howbig) { return (double) (((double) (fmod(rand(),RAND_MAX))/RAND_MAX))*howbig; }
void UpdateAI(const uint32 diff) { //Only if not incombat check if the event is started if (!me->isInCombat() && pInstance && pInstance->GetData(DATA_KARATHRESSEVENT)) { Unit *pTarget = Unit::GetUnit((*me), pInstance->GetData64(DATA_KARATHRESSEVENT_STARTER)); if (pTarget) { AttackStart(pTarget); } } //Return since we have no target if (!UpdateVictim()) return; //someone evaded! if (pInstance && !pInstance->GetData(DATA_KARATHRESSEVENT)) { EnterEvadeMode(); return; } if (!me->HasAura(SPELL_WINDFURY_WEAPON)) { DoCast(me, SPELL_WINDFURY_WEAPON); } //FrostShock_Timer if (FrostShock_Timer <= diff) { DoCast(me->getVictim(), SPELL_FROST_SHOCK); FrostShock_Timer = 25000+rand()%5000; } else FrostShock_Timer -= diff; //Spitfire_Timer if (Spitfire_Timer <= diff) { DoCast(me, SPELL_SPITFIRE_TOTEM); Unit *SpitfireTotem = Unit::GetUnit(*me, CREATURE_SPITFIRE_TOTEM); if (SpitfireTotem) { CAST_CRE(SpitfireTotem)->AI()->AttackStart(me->getVictim()); } Spitfire_Timer = 60000; } else Spitfire_Timer -= diff; //PoisonCleansing_Timer if (PoisonCleansing_Timer <= diff) { DoCast(me, SPELL_POISON_CLEANSING_TOTEM); PoisonCleansing_Timer = 30000; } else PoisonCleansing_Timer -= diff; //Earthbind_Timer if (Earthbind_Timer <= diff) { DoCast(me, SPELL_EARTHBIND_TOTEM); Earthbind_Timer = 45000; } else Earthbind_Timer -= diff; DoMeleeAttackIfReady(); }
inline double random(double howsmall, double howbig) { return (double) ((((double) (fmod(rand(),RAND_MAX))/RAND_MAX))*(howbig - howsmall))+howsmall; }
void UpdateAI(const uint32 diff) { //Only if not incombat check if the event is started if (!me->isInCombat() && pInstance && pInstance->GetData(DATA_KARATHRESSEVENT)) { Unit *pTarget = Unit::GetUnit((*me), pInstance->GetData64(DATA_KARATHRESSEVENT_STARTER)); if (pTarget) { AttackStart(pTarget); } } //Return since we have no target if (!UpdateVictim()) return; //someone evaded! if (pInstance && !pInstance->GetData(DATA_KARATHRESSEVENT)) { EnterEvadeMode(); return; } //WaterBoltVolley_Timer if (WaterBoltVolley_Timer <= diff) { DoCast(me->getVictim(), SPELL_WATER_BOLT_VOLLEY); WaterBoltVolley_Timer = 30000; } else WaterBoltVolley_Timer -= diff; //TidalSurge_Timer if (TidalSurge_Timer <= diff) { DoCast(me->getVictim(), SPELL_TIDAL_SURGE); // Hacky way to do it - won't trigger elseways me->getVictim()->CastSpell(me->getVictim(), SPELL_TIDAL_SURGE_FREEZE, true); TidalSurge_Timer = 15000+rand()%5000; } else TidalSurge_Timer -= diff; //Cyclone_Timer if (Cyclone_Timer <= diff) { //DoCast(me, SPELL_SUMMON_CYCLONE); // Doesn't work Cyclone_Timer = 30000+rand()%10000; Creature *Cyclone = me->SummonCreature(CREATURE_CYCLONE, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), float(rand()%5), TEMPSUMMON_TIMED_DESPAWN, 15000); if (Cyclone) { CAST_CRE(Cyclone)->SetFloatValue(OBJECT_FIELD_SCALE_X, 3.0f); Cyclone->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); Cyclone->setFaction(me->getFaction()); Cyclone->CastSpell(Cyclone, SPELL_CYCLONE_CYCLONE, true); Unit *pTarget = SelectUnit(SELECT_TARGET_RANDOM, 0); if (pTarget) { Cyclone->AI()->AttackStart(pTarget); } } } else Cyclone_Timer -= diff; //Heal_Timer if (Heal_Timer <= diff) { // It can be cast on any of the mobs Unit *pUnit = NULL; while (pUnit == NULL || !pUnit->isAlive()) { pUnit = selectAdvisorUnit(); } if (pUnit && pUnit->isAlive()) DoCast(pUnit, SPELL_HEAL); Heal_Timer = 60000; } else Heal_Timer -= diff; DoMeleeAttackIfReady(); }
void test(std::ostream &outStream = std::cout ) const { size_t size = 1; std::vector<Real> X(size,4.*(Real)rand()/(Real)RAND_MAX - 2.); std::vector<int> T(size,0); Distribution<Real>::test(X,T,outStream); }
void UpdateAI(const uint32 diff) { if (ResetTimer) { if (ResetTimer <= diff) { ResetTimer = 0; Unit *pMidnight = Unit::GetUnit(*m_creature, Midnight); if (pMidnight) { pMidnight->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); pMidnight->SetVisibility(VISIBILITY_ON); } Midnight = 0; m_creature->SetVisibility(VISIBILITY_OFF); m_creature->Kill(m_creature); } } else ResetTimer -= diff; //Return since we have no target if (!UpdateVictim()) return; if (m_creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE)) return; if (CleaveTimer <= diff) { DoCast(m_creature->getVictim(), SPELL_SHADOWCLEAVE); CleaveTimer = urand(10000,15000); } else CleaveTimer -= diff; if (CurseTimer <= diff) { DoCast(m_creature->getVictim(), SPELL_INTANGIBLE_PRESENCE); CurseTimer = 30000; } else CurseTimer -= diff; if (RandomYellTimer <= diff) { DoScriptText(RAND(SAY_RANDOM1,SAY_RANDOM2), m_creature); RandomYellTimer = urand(30000,60000); } else RandomYellTimer -= diff; if (m_creature->GetUInt32Value(UNIT_FIELD_DISPLAYID) == MOUNTED_DISPLAYID) { if (ChargeTimer <= diff) { Unit *pTarget; std::list<HostileReference *> t_list = m_creature->getThreatManager().getThreatList(); std::vector<Unit *> target_list; for (std::list<HostileReference *>::iterator itr = t_list.begin(); itr!= t_list.end(); ++itr) { pTarget = Unit::GetUnit(*m_creature, (*itr)->getUnitGuid()); if (pTarget && !pTarget->IsWithinDist(m_creature, ATTACK_DISTANCE, false)) target_list.push_back(pTarget); pTarget = NULL; } if (target_list.size()) pTarget = *(target_list.begin()+rand()%target_list.size()); DoCast(pTarget, SPELL_BERSERKER_CHARGE); ChargeTimer = 20000; } else ChargeTimer -= diff; } else { if ((m_creature->GetHealth()*100)/m_creature->GetMaxHealth() < 25) { Creature *pMidnight = Unit::GetCreature(*m_creature, Midnight); if (pMidnight && pMidnight->GetTypeId() == TYPEID_UNIT) { CAST_AI(boss_midnightAI, (pMidnight->AI()))->Mount(m_creature); m_creature->SetHealth(pMidnight->GetHealth()); DoResetThreat(); } } } DoMeleeAttackIfReady(); }