void Cage::paint() { int &width = getWidth(0); int &height = getHeight(0); int maxX = width/cellSize+1; int maxY = height/cellSize+1; if (maxX >= MATRIX_SIZE || maxY >= MATRIX_SIZE) return; //size(width, height); background(backColor); applyWave(); Areas &areas = getAreas(0); for (unsigned int i=0; i<areas.size(); i++) { Area &area = areas.at(i); if (area.pt[0] > 0 && area.pt[1] > 0 && area.pt[0] < width && area.pt[1] < height) { int x1 = (area.pt[0]-(area.width/2 ))/cellSize - influence; int y1 = (area.pt[1]-(area.height/2))/cellSize - influence; int x2 = (area.pt[0]+(area.width/2 ))/cellSize + influence; int y2 = (area.pt[1]+(area.height/2))/cellSize + influence; zeroMatrix(x1, y1, x2, y2); } } m[0][0] = 1; m[maxX-1][0] = 1; color(boxColor); for (int i=0; i<maxX; i++) for (int j=0; j<maxY; j++) { if ( i > 0 && m[i-1][j] == 1 && chance(prob/500.0) ) { m[i][j] = 1; } if ( j > 0 && m[i][j-1] == 1 && chance(prob/500.0) ) { m[i][j] = 1; } if ( i < maxX-1 && m[i+1][j] == 1 && chance(prob/500.0) ) { m[i][j] = 1; } if ( j < maxY-1 && m[i][j+1] == 1 && chance(prob/500.0) ) { m[i][j] = 1; } if ( m[i][j] == 1) { image(box, i*cellSize+random(boxDeviation)-boxDeviation/2, j*cellSize+random(boxDeviation)-boxDeviation/2, boxSize, boxSize); } } }
static float getRandomTechDirection() { if (chance(TECH_ROLL_PROB)) { return chance(0.5f) ? 0.f : 180.f; } else { return 90.f; } }
void OpponentAI::interactWithOtherTruck(const Rectangle& truckRect, const Rectangle& opRect, const TimeDuration& deltaTime) { if (getTruckController()->isDestroyed()) { return; } // if we are out of armor, avoid collisions, but still shoot. if(getTruckController()->getTruck()->truckParams.truckArmor <= 0) { if (getTruckController()->getShotGun().isObjectInRange(truckRect, opRect)) { if (getTruckController()->getShotGun().isReadyToShoot() && chance(rng) < deltaTime.realSeconds()) { setInteracted(true); shoot = true; getTruckController()->getShotGun().shoot(); getTruckController()->getTruck()->activateAttachedAnimation(Truck::ShotgunBlast); // TODO: If we want, this is where an opponent shotgun sound would go } } return; } // else we have armor, so try to attack if (isOpponentLeft(truckRect, opRect) && !isOpponentUpper(truckRect, opRect) && !isOpponentBelow(truckRect, opRect)) { if (truckRect.left - opRect.right < hitRange) { getTruckController()->getTruck()->setInputLeft(true); setInteracted(true); //LOGI("Hit left"); } } else if (isOpponentRight(truckRect, opRect) && !isOpponentUpper(truckRect, opRect) && !isOpponentBelow(truckRect, opRect)) { if (opRect.left - truckRect.right < hitRange) { getTruckController()->getTruck()->setInputRight(true); setInteracted(true); //LOGI("Hit right"); } } else if (getTruckController()->getShotGun().isObjectInRange(truckRect, opRect)) { if (getTruckController()->getShotGun().isReadyToShoot() && chance(rng) < deltaTime.realSeconds()) { setInteracted(true); shoot = true; getTruckController()->getShotGun().shoot(); getTruckController()->getTruck()->activateAttachedAnimation(Truck::ShotgunBlast); // TODO: If we want to, this is where an opponent shotgun sound would go. } } }
void mutate(Net<SIZE> & subject, double rate) { for (int c = 0; c < SIZE; ++c) { for (int r = 0; r < SIZE; ++r) { if (subject.hasSynapse(c, r) && chance(rate)) { if (chance(0.5)) { subject[c][r] += rand() - .5; } else { subject[c][r] = randMax(2) - 1.; } } } } }
static int _generate_star(PyObject *s, void *vg) { gen_state_t *g = (gen_state_t *)vg; if (SYMOBJ(s)->clean || g->clean || (!gen_state_hit_limit(g) && !gen_state_hit_depth(g))) { if (gen_state_inc_star_depth(g, s)) return -1; if (!SYMOBJ(s)->clean && !g->clean && chance(.1)) { // For the repetition generator, I think it helps to do self sometimes... DBGN(D_GEN, "-> *1 self %s/%d (L%d)\n", SYMOBJ(SYMOBJ(s)->data.star.child)->name, SYMOBJ(SYMOBJ(s)->data.star.child)->id, SYMOBJ(SYMOBJ(s)->data.star.child)->line_no); if (_generate(SYMOBJ(s), g)) return -1; if (_generate(SYMOBJ(SYMOBJ(s)->data.star.child), g)) return -1; } else if (!SYMOBJ(s)->clean && !g->clean && chance(.09)) { DBGN(D_GEN, "-> *1 %s/%d self (L%d)\n", SYMOBJ(SYMOBJ(s)->data.star.child)->name, SYMOBJ(SYMOBJ(s)->data.star.child)->id, SYMOBJ(SYMOBJ(s)->data.star.child)->line_no); if (_generate(SYMOBJ(SYMOBJ(s)->data.star.child), g)) return -1; if (_generate(SYMOBJ(s), g)) return -1; } else { // When sym.star_depth is 1, the average is recommended_count. For every nesting, the average is halved. int count, i; //old: //count = rnd(rnd(SYMOBJ(s)->data.star.recommended_count * powl(2, GRMOBJ(g->grammar)->star_depth - (int)gen_state_get_star_depth(g, s)))); //new: eliminate star_depth parameter, average is recommended_count/2 at depth=1, * 0.75 at each nesting count = rnd(SYMOBJ(s)->data.star.recommended_count); for (i = 1; i < gen_state_get_star_depth(g, s); i++) count = rnd(count); if (PyErr_Occurred()) return -1; DBGN(D_GEN, "-> *%d %s/%d (L%d)\n", count, SYMOBJ(SYMOBJ(s)->data.star.child)->name, SYMOBJ(SYMOBJ(s)->data.star.child)->id, SYMOBJ(SYMOBJ(s)->data.star.child)->line_no); for (i = 0; i < count; i++) { if (!SYMOBJ(s)->clean && !g->clean && (gen_state_hit_limit(g) || gen_state_hit_depth(g))) break; if (_generate(SYMOBJ(SYMOBJ(s)->data.star.child), g)) return -1; } } if (gen_state_dec_star_depth(g, s)) { return -1; } } return 0; }
//does the same as insert errors, but has a half chance of inserting one of the //remaining errors next to an existing one void insert_errors_dependent(uint8_t* block, int length, int num_errors) { //int* error_positions = (int*)malloc(num_errors * sizeof(int)); int last_error_position = random(0, length * 8); unsigned int i; for (i = 0; i < num_errors; i++) { int error_position; //half chance of being inserted next to last error if(chance(1.0/2.0)) error_position = last_error_position + 1; else error_position = random(0, length * 8); if(error_position >= length * 8) error_position = random(0, length * 8); /*while(1) { int j; for(j = 0; j < i; j++) { if(error_positions[j] == error_position) error_position = random(0, length * 8); } if(j == i) //all tested, no errors are at same position break; }*/ block[error_position / 8] = insert_error(block[error_position / 8], error_position % 8); last_error_position = error_position; } //free(error_positions); }
void morale_update(region *r) { int morale = region_get_morale(r); assert(r->land); if (r->land->ownership && r->land->ownership->owner) { int stability = turn - r->land->ownership->morale_turn; int maxmorale = MORALE_DEFAULT; building *b = largestbuilding(r, cmp_taxes, false); if (b) { int bsize = buildingeffsize(b, false); assert(b->type->taxes>0); maxmorale = (bsize + 1) * MORALE_TAX_FACTOR / b->type->taxes; } if (morale < maxmorale) { if (stability > MORALE_COOLDOWN && r->land->ownership->owner && morale < MORALE_MAX) { double ch = popularity(); if (is_cursed(r->attribs, &ct_generous)) { ch *= 1.2; /* 20% improvement */ } if (stability >= MORALE_AVERAGE * 2 || chance(ch)) { region_set_morale(r, morale + 1, turn); } } } else if (morale > maxmorale) { region_set_morale(r, morale - 1, turn); } } else if (morale > MORALE_DEFAULT) { region_set_morale(r, morale - 1, turn); } }
void terraform_resources(region * r) { int i; const terrain_type *terrain = r->terrain; static int terraform_all = -1; if (terraform_all < 0) { terraform_all = get_param_int(global.parameters, "rules.terraform.all", 0); } if (terrain->production == NULL) return; for (i = 0; terrain->production[i].type; ++i) { rawmaterial *rm; const terrain_production *production = terrain->production + i; const resource_type *rtype = production->type; for (rm = r->resources; rm; rm = rm->next) { if (rm->type->rtype == rtype) break; } if (rm) { continue; } if (terraform_all || chance(production->chance)) { add_resource(r, dice_rand(production->startlevel), dice_rand(production->base), dice_rand(production->divisor), production->type); } } }
void mutationStep(std::vector<std::pair<Net<SIZE>*, double>> & grades) { sort(grades.begin(), grades.end(), [](const std::pair<Net<SIZE>*, double> & left, const std::pair<Net<SIZE>*, double> & right) { return left.second > right.second; }); auto randNet = [&grades]() -> Net<SIZE> & { return *grades[randMax(grades.size() - 1)].first; }; const Net<SIZE> & best = *grades.front().first; // cross the lower half with low chance of mutation for (int c = 0; c < grades.size() / 2; ++c) { *grades[c].first = cross(best, randNet()); if (chance(0.05)) { mutate(*grades[c].first, 0.33); } } // mutate 20% of the middle for (int c = 0; c < grades.size() / 5; ++c) { mutate(*grades[c + grades.size() / 2].first, 0.5); } }
/* Wenn der Curse schwächer ist als der cast_level, dann wird er * aufgelöst, bzw seine Kraft (vigour) auf 0 gesetzt. * Ist der cast_level zu gering, hat die Antimagie nur mit einer Chance * von 100-20*Stufenunterschied % eine Wirkung auf den Curse. Dann wird * die Kraft des Curse um die halbe Stärke der Antimagie reduziert. * Zurückgegeben wird der noch unverbrauchte Rest von force. */ float destr_curse(curse * c, int cast_level, float force) { if (cast_level < c->vigour) { /* Zauber ist nicht stark genug */ double probability = 0.1 + (cast_level - c->vigour) * 0.2; /* pro Stufe Unterschied -20% */ if (chance(probability)) { force -= c->vigour; if (c->type->change_vigour) { c->type->change_vigour(c, -((float)cast_level + 1) / 2); } else { c->vigour -= cast_level + 1 / 2; } } } else { /* Zauber ist stärker als curse */ if (force >= c->vigour) { /* reicht die Kraft noch aus? */ force -= c->vigour; if (c->type->change_vigour) { c->type->change_vigour(c, -c->vigour); } else { c->vigour = 0; } } } return force; }
/*ARGSUSED*/ static int infect_people(struct natstr *np, struct sctstr *sp) { double pop, pop_space, bad_stuff, pollution, cleanup; double plg_chance; if (opt_NO_PLAGUE) /* no plague nothing to do */ return PLG_HEALTHY; if (np->nat_level[NAT_TLEV] <= 10.0) return PLG_HEALTHY; /* * make plague where there was none before... */ pop = sp->sct_item[I_CIVIL] + sp->sct_item[I_MILIT] + sp->sct_item[I_UW]; pop_space = max_pop(np->nat_level[NAT_RLEV], sp); bad_stuff = sp->sct_item[I_IRON] + sp->sct_item[I_OIL] + sp->sct_item[I_RAD] * 2; pollution = bad_stuff / 10.0 + np->nat_level[NAT_TLEV] + 100.0; cleanup = sp->sct_effic + sp->sct_mobil + 100 + np->nat_level[NAT_RLEV]; plg_chance = ((pop / pop_space) * (pollution / cleanup) - 1.0) * 0.01; if (chance(plg_chance)) return PLG_EXPOSED; return PLG_HEALTHY; }
/*! \author Luxor */ void cChar::walkNextStep() { if ( isFrozen() ) return; if ( !hasPath() ) return; if ( !path->pathFound() ) path->exec(); sLocation pos = path->getNextPos(); if ( pos == getPosition() ) return; if ( isWalkable( pos, WALKFLAG_DYNAMIC|WALKFLAG_CHARS, this ) == illegal_z ) { safedelete( path ); return; } pCreatureInfo creature = creatures.getCreature( getId() ); if( creature!=NULL ) { if( creature->canFly() && ( fly_steps>0 ) ) if ( chance( 20 ) ) playAction( 0x13 ); // Flying animation } uint8_t dirXY = getDirFromXY(pos); dir = dirXY & 0x07; MoveTo( pos ); sendToPlayers( this, dirXY ); setNpcMoveTime(); }
/* wiederbeleben */ int sp_reanimate(struct castorder * co) { fighter * fi = co->magician.fig; int level = co->level; double power = co->force; battle *b = fi->side->battle; unit *mage = fi->unit; int healable, j = 0; double c = 0.50 + 0.02 * power; double k = EFFECT_HEALING_SPELL * power; bool use_item = has_ao_healing(mage); message *msg; if (use_item) { k *= 2; c += 0.10; } healable = count_healable(b, fi); healable = (int)_min(k, healable); while (healable--) { fighter *tf = select_corpse(b, fi); if (tf != NULL && tf->side->casualties > 0 && u_race(tf->unit) != get_race(RC_DAEMON) && (chance(c))) { assert(tf->alive < tf->unit->number); /* t.fighter->person[].hp beginnt mit t.index = 0 zu z�hlen, * t.fighter->alive ist jedoch die Anzahl lebender in der Einheit, * also sind die hp von t.fighter->alive * t.fighter->hitpoints[t.fighter->alive-1] und der erste Tote * oder weggelaufene ist t.fighter->hitpoints[tf->alive] */ tf->person[tf->alive].hp = 2; ++tf->alive; ++tf->side->size[SUM_ROW]; ++tf->side->size[tf->unit->status + 1]; ++tf->side->healed; --tf->side->casualties; assert(tf->side->casualties >= 0); --tf->side->dead; assert(tf->side->dead >= 0); ++j; } } if (j <= 0) { level = j; } if (use_item) { msg = msg_message("reanimate_effect_1", "mage amount item", mage, j, get_resourcetype(R_AMULET_OF_HEALING)); } else { msg = msg_message("reanimate_effect_0", "mage amount", mage, j); } message_all(b, msg); msg_release(msg); return level; }
void getUpFromGround(AI* ai) { if (chance(GET_UP_ATTACK_PROB)) { addMove(ai, &_mv_getUpAttack); } else { hitTech(ai); } }
void postTechOption(AI* ai) { if (chance(GET_UP_ATTACK_PROB)) { addMove(ai, &_mv_jab); } else { addMove(ai, &_mv_spotDodge); } }
int check_lmines(coord x, coord y, double weight) { struct sctstr sect; int dam = 0; getsect(x, y, §); if (SCT_LANDMINES(§) > 0 && sect.sct_oldown != player->cnum && chance(DMINE_LHITCHANCE(sect.sct_mines)) && chance(weight / 100.0)) { pr_beep(); pr("Blammo! Landmines detected! in %s ", xyas(sect.sct_x, sect.sct_y, player->cnum)); dam = roll(20); --sect.sct_mines; putsect(§); pr("%d damage sustained.\n", dam); } return dam; }
void newbie_help( CHAR_DATA * ch, char * argument ) { NEWBIE_DATA * pNewbie; CHAR_DATA * helper; bool found = FALSE; char buf[ MAX_STRING_LENGTH ]; /* Check for newbie helper in the same room as ch */ for ( helper = ch->in_room->people; helper; helper = helper->next_in_room ) { if ( IS_NPC( helper ) && ( CHECK_BIT( helper->act, ACT_NEWBIE ) ) ) { break; } } if ( !helper ) { return; } for ( pNewbie = newbie_first; pNewbie; pNewbie = pNewbie->next ) { if ( argument[ 0 ] == pNewbie->keyword[ 0 ] && !str_cmp( argument, pNewbie->keyword ) ) { found = TRUE; break; } } /* if keyword not found, have 30% chance that helper says something -- don't want mob responding to every say not found as a keyword */ if ( !found ) { if ( chance( 30 ) ) { act( AT_WHITE, "$n tells you 'I'm not sure if I can help you. Try being more specific.'", helper, buf, ch, TO_VICT ); } } else if ( chance( 50 ) ) { do_say( helper, pNewbie->answer2 ); } else { do_say( helper, pNewbie->answer1 ); } return; }
static int fire_torp(struct shpstr *sp, struct shpstr *targ, int ntargets) { int range, erange, dam; if ((mchr[targ->shp_type].m_flags & M_SUB) && (mchr[sp->shp_type].m_flags & M_SUBT) == 0) return 0; /* need sub-torp to torpedo a sub */ erange = roundrange(torprange(sp)); range = mapdist(sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y); if (range > erange) return 0; if (!line_of_sight(NULL, sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y)) return 0; dam = shp_torp(sp, 1); putship(sp->shp_uid, sp); if (dam < 0) return 0; pr("Captain! Torpedoes sighted!\n"); if (chance(shp_torp_hitchance(sp, range))) { pr("BOOM!...\n"); if (!(mchr[targ->shp_type].m_flags & M_SUB)) { if (mchr[sp->shp_type].m_flags & M_SUB) nreport(targ->shp_own, N_TORP_SHIP, 0, 1); else nreport(targ->shp_own, N_SHIP_TORP, sp->shp_own, 1); } if (sp->shp_own != 0) wu(0, sp->shp_own, "%s @ %s torpedoed %s\n", prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own), prsub(targ)); if (ntargets > 2) dam /= ntargets / 2; shipdamage(targ, dam); putship(targ->shp_uid, targ); } else { pr("Missed!\n"); if (sp->shp_own != 0) wu(0, sp->shp_own, "%s missed %s with a torpedo at %s\n", prship(sp), prsub(targ), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); } return 1; }
void garderPointage(Jet jet, Pointage* feuilleScore, char figure) { switch (figure) { case '1': feuilleScore->un = nbDeFace(jet,UN); break; case '2': feuilleScore->deux = nbDeFace(jet,DEUX); break; case '3': feuilleScore->trois = nbDeFace(jet,TROIS); break; case '4': feuilleScore->quatre = nbDeFace(jet,QUATRE); break; case '5': feuilleScore->cinq = nbDeFace(jet,CINQ); break; case '6': feuilleScore->six = nbDeFace(jet,SIX); break; case 'b': case 'B': feuilleScore->brelan = brelan(jet); break; case 'c': case 'C': feuilleScore->carre = carre(jet); break; case 'm': case 'M': feuilleScore->mainPleine = mainPleine(jet); break; case 'p': case 'P': feuilleScore->pSuite = petiteSuite(jet); break; case 'g': case 'G': feuilleScore->gSuite = grandeSuite(jet); break; case 'y': case 'Y': feuilleScore->yahtzee = yahtzee(jet); break; case 'h': case 'H': feuilleScore->chance = chance(jet); break; } }
void hitTech(AI* ai) { addLogic(ai, &getOffGroundLogic); addLogic(ai, &resetOnHitLogic); addLogic(&cpuPlayer, &recoveryLogic); addLogic(&cpuPlayer, &onLedgeLogic); if (chance(HIT_TECH_PROB)) { SET_TECH_DIR(getRandomTechDirection()); addMove(ai, &_mv_tech); addLogic(ai, &actAfterTechLogic); } }
void imprimerScoresPossibles(Jet jet) { printf("**********************************************\n"); printf("* QUEL POINTAGE VOULEZ-VOUS GARDER? *\n"); printf("**********************************************\n"); printf("* (1) : %2d * (B)relan = %2d *\n", nbDeFace(jet,UN), brelan(jet)); printf("* (2) : %2d * (C)arré = %2d *\n", nbDeFace(jet,DEUX), carre(jet)); printf("* (3) : %2d * (M)ain Pleine = %2d *\n", nbDeFace(jet,TROIS), mainPleine(jet)); printf("* (4) : %2d * (P)etite suite = %2d *\n", nbDeFace(jet,QUATRE), petiteSuite(jet)); printf("* (5) : %2d * (G)rande suite = %2d *\n", nbDeFace(jet,CINQ), grandeSuite(jet)); printf("* (6) : %2d * (Y)ahtzee = %2d *\n", nbDeFace(jet,SIX), yahtzee(jet)); printf("* * C(h)ance = %2d *\n", chance(jet)); printf("**********************************************\n"); }
void reduce_skill_days(unit *u, skill_t sk, int days) { skill *sv = unit_skill(u, sk); if (sv) { while (days > 0) { if (days >= STUDYDAYS * u->number) { reduce_skill(u, sv, 1); days -= STUDYDAYS; } else { if (chance (days / ((double) STUDYDAYS * u->number))) /* (rng_int() % (30 * u->number) < days)*/ reduce_skill(u, sv, 1); days = 0; } } } }
static int _generate_concat(PyObject *s, void *vg) { gen_state_t *g = vg; int i; for (i = 0; i < SYMOBJ(s)->data.concat.n_children; i++) { if (!g->tracking && !SYMOBJ(s)->clean && !g->clean && chance(.001)) { i += rnd(SYMOBJ(s)->data.concat.n_children); // skip part of this concatenation } else { if (_generate(SYMOBJ(SYMOBJ(s)->data.concat.children[i]), g)) return -1; } } return 0; }
void insert_errors2(uint8_t* block, int length, float BER) { unsigned int i; for(i = 0; i < length; i++) { unsigned int j; for(j = 0; j < 8; j++) { if(chance(BER)) { block[i] = insert_error(block[i], j); num_errors_inserted++; } } } }
static void do_transfer_curse(curse * c, unit * u, unit * u2, int n) { int cursedmen = 0; int men = get_cursedmen(u, c); bool dogive = false; const curse_type *ct = c->type; switch ((ct->flags | c->flags) & CURSE_SPREADMASK) { case CURSE_SPREADALWAYS: dogive = true; men = u2->number + n; break; case CURSE_SPREADMODULO: { int i; int u_number = u->number; for (i = 0; i < n + 1 && u_number > 0; i++) { if (rng_int() % u_number < cursedmen) { ++men; --cursedmen; dogive = true; } --u_number; } break; } case CURSE_SPREADCHANCE: if (chance(u2->number / (double)(u2->number + n))) { men = u2->number + n; dogive = true; } break; case CURSE_SPREADNEVER: break; } if (dogive) { curse *cnew = make_curse(c->magician, &u2->attribs, c->type, c->vigour, c->duration, c->effect, men); cnew->flags = c->flags; if (ct->typ == CURSETYP_UNIT) set_cursedmen(cnew, men); } }
/*! \brief apply wear out to item, delete if necessary \author Ripper, rewritten by Luxor \return bool \param s socket of player who wear out the item \param pi pointer to item to wear out \todo become a method of cItem */ static bool Item_ToolWearOut(NXWSOCKET s, P_ITEM pi) { VALIDATEPIR(pi, false); if ( s < 0 || s >= now ) return false; P_CHAR pc = pointers::findCharBySerial(currchar[s]); VALIDATEPCR(pc, false); if( chance(5) ) { // has item been destroyed ?? pi->hp--; if ( pi->hp <= 0 ) { pc->sysmsg("Your %s has been destroyed", pi->getCurrentNameC()); pi->Delete(); return true; } } return false; }
void plane_sweep(struct emp_qelem *plane_list, coord x, coord y) { struct plnstr *pp; struct plchrstr *pcp; struct emp_qelem *qp; struct emp_qelem *next; struct plist *ip; struct sctstr sect; int mines_there; int found = 0; getsect(x, y, §); mines_there = sect.sct_mines; if (mines_there == 0) return; if (sect.sct_type != SCT_WATER) return; for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there)); qp = next) { next = qp->q_forw; ip = (struct plist *)qp; pp = &ip->plane; pcp = ip->pcp; if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */ continue; if (chance((100.0 - pln_acc(pp)) / 100.0)) { pr("Sweep! in %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); mines_there--; found = 1; } } if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0)) writemap(player->cnum); sect.sct_mines = mines_there; putsect(§); }
/** handles the "orcish" curse that makes units grow like old orks * This would probably be better handled in an age-function for the curse, * but it's now being called by randomevents() */ static void orc_growth(void) { region *r; for (r = regions; r; r = r->next) { unit *u; for (u = r->units; u; u = u->next) { static bool init = false; static const curse_type *ct_orcish = 0; curse *c = 0; if (!init) { init = true; ct_orcish = ct_find("orcish"); } if (ct_orcish) c = get_curse(u->attribs, ct_orcish); if (c && !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY) && !fval(u, UFL_HERO)) { int n; int increase = 0; int num = get_cursedmen(u, c); double prob = curse_geteffect(c); const item_type * it_chastity = it_find("ao_chastity"); if (it_chastity) { num -= i_get(u->items, it_chastity); } for (n = num; n > 0; n--) { if (chance(prob)) { ++increase; } } if (increase) { unit *u2 = create_unit(r, u->faction, increase, u_race(u), 0, NULL, u); transfermen(u2, u, u2->number); ADDMSG(&u->faction->msgs, msg_message("orcgrowth", "unit amount race", u, increase, u_race(u))); } } } } }
static order *get_money_for_dragon(region * r, unit * udragon, int wanted) { int n; bool attacks = attack_chance > 0.0; /* falls genug geld in der region ist, treiben wir steuern ein. */ if (rmoney(r) >= wanted) { /* 5% chance, dass der drache aus einer laune raus attackiert */ if (!attacks || chance(1.0 - u_race(udragon)->aggression)) { /* Drachen haben in E3 und E4 keine Einnahmen. Neuer Befehl Pluendern erstmal nur fuer Monster?*/ return create_order(K_LOOT, default_locale, NULL); } } /* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an * und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */ n = 0; if (attacks && is_guard(udragon, GUARD_TAX)) { unit *u; for (u = r->units; u; u = u->next) { if (u->faction != udragon->faction && cansee(udragon->faction, r, u, 0) && !in_safe_building(u, udragon)) { int m = get_money(u); if (m != 0) { order *ord = monster_attack(udragon, u); if (ord) { addlist(&udragon->orders, ord); n += m; } } } } } /* falls die einnahmen erreicht werden, bleibt das monster noch eine */ /* runde hier. */ if (n + rmoney(r) >= wanted) { return create_order(K_LOOT, default_locale, NULL); } /* wenn wir NULL zurueckliefern, macht der drache was anderes, z.b. weggehen */ return NULL; }
void create_icebergs(void) { region *r; for (r = regions; r; r = r->next) { if (r->terrain == newterrain(T_ICEBERG_SLEEP) && chance(0.05)) { bool has_ocean_neighbour = false; direction_t dir; region *rc; unit *u; freset(r, RF_SELECT); for (dir = 0; dir < MAXDIRECTIONS; dir++) { rc = rconnect(r, dir); if (rc && fval(rc->terrain, SEA_REGION)) { has_ocean_neighbour = true; break; } } if (!has_ocean_neighbour) continue; rsetterrain(r, T_ICEBERG); fset(r, RF_SELECT); move_iceberg(r); for (u = r->units; u; u = u->next) { freset(u->faction, FFL_SELECT); } for (u = r->units; u; u = u->next) { if (!fval(u->faction, FFL_SELECT)) { fset(u->faction, FFL_SELECT); ADDMSG(&u->faction->msgs, msg_message("iceberg_create", "region", r)); } } } } }