예제 #1
0
파일: spawn.c 프로젝트: shentino/simud
void spawn_tick() {
   object ob;
   int pop, spawns, max;
   string fname = spawn_src;

   if( !environment(this_object()) ) return;
   remove_call_out("spawn_tick");
//   call_out( "spawn_tick", SPAWN_DELAY + random(SPAWN_DELAY) );

   // pumpkin lord's revenge
   if( localtime()[4] == 9 && random(100) < 50 ) {   // 0-indexed, oct+
      fname = SKELLINGTON;
      max = MAX_SKELLINGTONS;
   } else {
      spawns = count_spawns();
      max = max_population(spawns);
   }
   pop = sizeof(all_clones(fname));
   // Don't spawn over the max.
   if( pop >= max ) return;

   // The following if statement does NOT WORK. Try it for
   // a population of zero -- nothing will EVER spawn.
//   if( (50+random(50)) > (100*pop/max) ) return;

   foreach( ob : all_inventory(environment(this_object())) )
      if( load_object(load_name(ob)) == load_object(fname) ) return;

   ob = clone_object( fname );
   if( !ob ) return;

   // mobs spawn fully healed
   ob->set_hp(ob->query_max_hp());
   ob->set_mana(ob->query_max_mana());
   ob->set_endurance(ob->query_max_endurance());
   ob->set_food(ob->query_max_food() * 3 / 4);
   ob->set_drink(ob->query_max_drink() * 3 / 4);

   // mobs also need some skills if their author forgot to give them
   if( !sizeof(ob->query_skills()) ) {
      ob->set_skill( "combat.dodging", 5 * range(ob->query_stat("spd")) );
      ob->set_skill( "combat.weapon.unarmed", 5 * range(ob->query_stat("str")) );
   }


   ob->move( environment(this_object()) );
   if( query_coord() == 0 )
      ob->set_coord( environment()->query_map_xdim()/2, environment()->query_map_ydim()/2, 0 );
   else
      ob->set_coord( query_coord() );
   ob->validate_position();
   "/daemon/counter"->add_count( "spawn_count_" + fname, 1 );
   debug( fname + " @ "+get_location(environment()), "spawn" );
}
예제 #2
0
파일: sect.c 프로젝트: fstltna/empserver
/*
 * Increase sector efficiency if old type == new type.
 * decrease sector efficiency if old type != new type.
 * Return amount of work used.
 */
static int
upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
	     short *vec, int etu, int *desig, int sctwork, int *cost)
{
    int work_cost = 0;
    int buildeff_work = *workp / 2;
    int n, hcms, lcms, neweff;
    unsigned char old_type = *desig;

    *cost = 0;
    neweff = sp->sct_effic;

    if (*desig != sp->sct_newtype) {
	/*
	 * Tear down existing sector.
	 * Easier to destroy than to build.
	 */
	work_cost = (sp->sct_effic + 3) / 4;
	if (work_cost > buildeff_work)
	    work_cost = buildeff_work;
	buildeff_work -= work_cost;
	n = sp->sct_effic - work_cost * 4;
	if (n <= 0) {
	    n = 0;
	    *desig = sp->sct_newtype;
	}
	neweff = n;
	*cost += work_cost;
	if (!n && IS_BIG_CITY(old_type) && !IS_BIG_CITY(*desig)) {
	    // FIXME use trunc_people() and total_work()
	    int maxpop = max_population(np->nat_level[NAT_RLEV], *desig, n);
	    if (vec[I_CIVIL] > maxpop)
		vec[I_CIVIL] = maxpop;
	    if (vec[I_UW] > maxpop)
		vec[I_UW] = maxpop;
	    *workp = (vec[I_CIVIL] * sctwork) / 100.0
		+ (vec[I_MILIT] * 2 / 5.0) + vec[I_UW];
	    *workp = roundavg((etu * *workp) / 100.0);

	    buildeff_work = MIN((int)(*workp / 2), buildeff_work);
	}
    }
    if (*desig == sp->sct_newtype) {
	work_cost = 100 - neweff;
	if (work_cost > buildeff_work)
	    work_cost = buildeff_work;

	if (dchr[*desig].d_lcms > 0) {
	    lcms = vec[I_LCM];
	    lcms /= dchr[*desig].d_lcms;
	    if (work_cost > lcms)
		work_cost = lcms;
	}
	if (dchr[*desig].d_hcms > 0) {
	    hcms = vec[I_HCM];
	    hcms /= dchr[*desig].d_hcms;
	    if (work_cost > hcms)
		work_cost = hcms;
	}

	neweff += work_cost;
	*cost += work_cost * dchr[*desig].d_build;
	buildeff_work -= work_cost;

	if ((dchr[*desig].d_lcms > 0) || (dchr[*desig].d_hcms > 0)) {
	    vec[I_LCM] -= work_cost * dchr[*desig].d_lcms;
	    vec[I_HCM] -= work_cost * dchr[*desig].d_hcms;
	}
    }
    *workp = (*workp + 1) / 2 + buildeff_work;

    return neweff;
}