Esempio n. 1
0
void do_daily_ecology ()
{
    for (int x = 0; x < WORLD_SIDE_LEN; x++)
        for (int y = 0; y < WORLD_SIDE_LEN; y++) {
            /* approximately 3 monthes needed to turn bulldoze area into green */
            if (MP_GROUP(x,y) == GROUP_DESERT && HAS_UGWATER(x,y) 
                    && rand() %300 == 1)
                do_bulldoze_area(CST_GREEN, x, y);
        }
}
Esempio n. 2
0
int 
bulldoze_item (int x, int y)
{
    int g, size;

    if (MP_TYPE(x,y) == CST_USED) {
	/* This is considered "improper" input.  Silently ignore. */
	return -1;
    }

    size = MP_SIZE(x,y);
    g = MP_GROUP(x,y);

    if (g == GROUP_BARE) {
	/* Nothing to do. */
	return -1;
    }
    else if (g == GROUP_SHANTY) {
	fire_area (x, y);
	adjust_money(-GROUP_SHANTY_BUL_COST);
    }
    else if (g == GROUP_FIRE) {
	if (MP_INFO(x,y).int_2 >= FIRE_LENGTH)
	    return -1;  /* Can't bulldoze ? */
	MP_INFO(x,y).int_2 = FIRE_LENGTH + 1;
	MP_TYPE(x,y) = CST_FIRE_DONE1;
	MP_GROUP(x,y) = GROUP_BURNT;
	adjust_money(-GROUP_BURNT_BUL_COST);
    }
    else {
	adjust_money(-main_groups[g].bul_cost);
	do_bulldoze_area (CST_GREEN, x, y);
	if (g == GROUP_OREMINE)
	{
	    int i, j;
	    for (j = 0; j < 4; j++)
		for (i = 0; i < 4; i++)
		    if (MP_INFO(x + i,y + j).ore_reserve < ORE_RESERVE / 2)
			do_bulldoze_area (CST_WATER, x + i, y + j);
	}
    }
    return size;  /* No longer used... */
}
Esempio n. 3
0
int 
bulldoze_item (int x, int y)
{
    int g, size;

    if (MP_TYPE(x,y) == CST_USED) {
	/* This is considered "improper" input.  Silently ignore. */
#ifdef DEBUG
        fprintf(stderr," try to improperly bulldoze_item CST_USED\n");
#endif
	return -1;
    }

    size = MP_SIZE(x,y);
    g = MP_GROUP(x,y);
    people_pool += MP_INFO(x,y).population;

    if (g == GROUP_DESERT) {
	/* Nothing to do. */
	return -1;
    }
    else if (g == GROUP_SHANTY) {
	remove_a_shanty(x, y);
	adjust_money(-GROUP_SHANTY_BUL_COST);
        numof_shanties--;
    }
    else if (g == GROUP_FIRE) {
	if (MP_INFO(x,y).int_2 >= FIRE_LENGTH)
	    return -1;  /* Can't bulldoze ? */
	MP_INFO(x,y).int_2 = FIRE_LENGTH + 1;
	MP_TYPE(x,y) = CST_FIRE_DONE1;
	MP_GROUP(x,y) = GROUP_BURNT;
	adjust_money(-GROUP_BURNT_BUL_COST);
    }
    else {
	adjust_money(-main_groups[g].bul_cost);
         
        if (g == GROUP_COMMUNE)
             numof_communes--;

        if (g == GROUP_MARKET)
            remove_a_market (x, y);
 
        if (g == GROUP_SUBSTATION || g == GROUP_WINDMILL)
             remove_a_substation (x, y);
 
	if (g == GROUP_OREMINE)	{
	    int i, j;
	    for (j = 0; j < 4; j++)
		for (i = 0; i < 4; i++)
		    if (MP_INFO(x + i,y + j).ore_reserve < ORE_RESERVE / 2)
			do_bulldoze_area (CST_WATER, x + i, y + j);
	} else {
            /* keep compatibility for saving pre_waterwell loaded game */
            if (use_waterwell)
                do_bulldoze_area (CST_DESERT, x, y);
            else
                do_bulldoze_area (CST_GREEN, x, y);
        }
    }

    /* Tell mps about it, in case its selected */
    mps_update();
    return size;  /* No longer used... */
}
Esempio n. 4
0
void
do_tip (int x, int y)
{
  /*
     // int_1 is the amount of waste on the site.
     // int_2 if the amount that has flowed in so far this month
     // int_3 is the amount stored last month.
     // int_4 counts up starting when tip fills, controlling how
              long until the land is useful again.
   */
  int i;

/* XXX: put this in a header somewhere */

/* If the tip is full, age it until it degrades into useful soil */

  if (MP_TYPE(x,y) == CST_TIP_8) {
      MP_INFO(x,y).int_4++;
      if (MP_INFO(x,y).int_4 >= TIP_DEGRADE_TIME) {
	  do_bulldoze_area(CST_DESERT,x,y);
      }
      return;
  }

  /* just grab as much as we can from transport */
  if (x > 0 && (MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0)
    {
      i = MP_INFO(x - 1,y).int_7 / 10;
      MP_INFO(x,y).int_1 += i;
      MP_INFO(x,y).int_2 += i;
      MP_INFO(x - 1,y).int_7 -= i * 10;
      sust_dig_ore_coal_tip_flag = 0;
    }
  if (y > 0 && (MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0)
    {
      i = MP_INFO(x,y - 1).int_7 / 10;
      MP_INFO(x,y).int_1 += i;
      MP_INFO(x,y).int_2 += i;
      MP_INFO(x,y - 1).int_7 -= i * 10;
      sust_dig_ore_coal_tip_flag = 0;
    }

#if defined (commentout)
  /* Increment the "ore" reserve; this prevents a new tip from being
     built on top of a degraded one. */
  MP_INFO(x,y).ore_reserve++;
#endif

  /* now choose an icon. */
  if ((total_time % NUMOF_DAYS_IN_MONTH) == 0)
    {
      i = (MP_INFO(x,y).int_1 * 7) / MAX_WASTE_AT_TIP;
      if (MP_INFO(x,y).int_1 > 0)
	i++;
      switch (i)
	{
	case (0):
	  MP_TYPE(x,y) = CST_TIP_0;
	  break;
	case (1):
	  MP_TYPE(x,y) = CST_TIP_1;
	  break;
	case (2):
	  MP_TYPE(x,y) = CST_TIP_2;
	  break;
	case (3):
	  MP_TYPE(x,y) = CST_TIP_3;
	  break;
	case (4):
	  MP_TYPE(x,y) = CST_TIP_4;
	  break;
	case (5):
	  MP_TYPE(x,y) = CST_TIP_5;
	  break;
	case (6):
	  MP_TYPE(x,y) = CST_TIP_6;
	  break;
	case (7):
	  MP_TYPE(x,y) = CST_TIP_7;
	  break;
	case (8):
	  MP_TYPE(x,y) = CST_TIP_8;
	  MP_INFO(x,y).int_2 = 0;
	  MP_INFO(x,y).int_4 = 0;
	  break;

	}
      MP_INFO(x,y).int_3 = MP_INFO(x,y).int_2;
      MP_INFO(x,y).int_2 = 0;
    }
}
Esempio n. 5
0
int bulldoze_item(int x, int y)
{
    int g, size = 1;
    bool construction_found = false;
    if (!world(x, y)->is_visible())
    {
        /* This is considered "improper" input.  Silently ignore. */
#ifdef DEBUG
        fprintf(stderr, " try to improperly bulldoze_item CST_USED\n");
#endif
        return -1;
    }

    if (world(x, y)->reportingConstruction )
    {
        construction_found = true;
        size = world(x, y)->reportingConstruction->constructionGroup->size;
        g = world(x, y)->reportingConstruction->constructionGroup->group;
    }
    else
    {
        size = 1; //all non-constructions are 1// MP_SIZE(x, y);
        g = world(x, y)->group;
        //size = main_groups[g].size;
    }

    if (g == GROUP_DESERT)
    {
        /* Nothing to do. */
        return -1;
    }
    else if (g == GROUP_SHANTY)
    {
        ConstructionManager::executeRequest
                (
                    new BurnDownRequest(world(x,y)->reportingConstruction)
                );
        adjust_money(-GROUP_SHANTY_BUL_COST);
    }
    else if (g == GROUP_FIRE)
    {
        return -1;          /* Can't bulldoze ? */
    }
    else
    {
        if (!construction_found)
        {   adjust_money(-world(x,y)->getTileConstructionGroup()->bul_cost);}
        else
        {   adjust_money(-world(x, y)->reportingConstruction->constructionGroup->bul_cost);}

        if (g == GROUP_OREMINE)
        {
            ConstructionManager::executeRequest
            (   new OreMineDeletionRequest(world(x, y)->reportingConstruction));
        }
        else
        {   do_bulldoze_area(x, y);}
    }
    /* Tell mps about it, in case its selected */
    mps_update();
    return size;                /* No longer used... */
}
Esempio n. 6
0
void
do_oremine (int x, int y)
{
  /*
     // int_1 is the ore at in stock
     // int_2 is the ore reserve under the ground or at the surface really.
   */
  int xx, yy, xs, ys, xe, ye, cr;
  if (MP_INFO(x,y).int_1 < DIG_MORE_ORE_TRIGGER - 5000)
    {
      xs = x;
      ys = y;
      xe = x + 4;
      ye = y + 4;
      cr = 0;
      for (yy = ys; yy < ye; yy++)
	for (xx = xs; xx < xe; xx++)
	  cr += MP_INFO(xx,yy).ore_reserve;
      MP_INFO(x,y).int_2 = cr;
      if (cr > 0)
	if (get_jobs (x, y, JOBS_DIG_ORE) != 0)
	  for (yy = ys; yy < ye; yy++)
	    for (xx = xs; xx < xe; xx++)
	      if (MP_INFO(xx,yy).ore_reserve > 0)
		{
		  MP_INFO(xx,yy).ore_reserve--;
		  MP_INFO(x,y).int_1 += 5000;
		  ore_made += 5000;
		  sust_dig_ore_coal_tip_flag = 0;
		  /* maybe want an ore tax? */
		  yy = ye;
		  xx = xe;	/* break out */
		}
    }

  if ((MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0)
    {
      if (MP_GROUP(x-1,y) == GROUP_RAIL
	  && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_RAIL
	  && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL
				      - MP_INFO(x - 1,y).int_5))
	{
	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
	    {
	      MP_INFO(x,y).int_1
		-= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5);
	      MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_RAIL;
	    }
	}
      else if (MP_GROUP(x-1,y) == GROUP_ROAD
	       && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_ROAD
	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD
					   - MP_INFO(x - 1,y).int_5))
	{
	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
	    {
	      MP_INFO(x,y).int_1
		-= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5);
	      MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_ROAD;
	    }
	}
      else if (MP_GROUP(x - 1,y) == GROUP_TRACK
	       && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_TRACK
	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK
					   - MP_INFO(x - 1,y).int_5))
	{
	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
	    {
	      MP_INFO(x,y).int_1
		-= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5);
	      MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_TRACK;
	    }
	}
    }

  if ((MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0)
    {
      if (MP_GROUP(x,y-1) == GROUP_RAIL
	  && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_RAIL
	  && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL
				      - MP_INFO(x,y - 1).int_5))
	{
	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
	    {
	      MP_INFO(x,y).int_1
		-= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5);
	      MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_RAIL;
	    }
	}
      else if (MP_GROUP(x,y-1) == GROUP_ROAD
	       && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_ROAD
	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD
					   - MP_INFO(x,y - 1).int_5))
	{
	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
	    {
	      MP_INFO(x,y).int_1
		-= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5);
	      MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_ROAD;
	    }
	}
      else if (MP_GROUP(x,y-1) == GROUP_TRACK
	       && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_TRACK
	       && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK
					   - MP_INFO(x,y - 1).int_5))
	{
	  if (get_jobs (x, y, JOBS_LOAD_ORE) != 0)
	    {
	      MP_INFO(x,y).int_1
		-= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5);
	      MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_TRACK;
	    }
	}
    }


  /* choose a graphic */
  if ((total_time & 0x7f) == 0)
    {
      xx = 7 * (MP_INFO(x,y).int_2 + (3 * ORE_RESERVE / 2))
	/ (16 * ORE_RESERVE);
      switch (xx)
	{
	case (0):
	  MP_TYPE(x,y) = CST_OREMINE_8;
	  break;
	case (1):
	  MP_TYPE(x,y) = CST_OREMINE_7;
	  break;
	case (2):
	  MP_TYPE(x,y) = CST_OREMINE_6;
	  break;
	case (3):
	  MP_TYPE(x,y) = CST_OREMINE_5;
	  break;
	case (4):
	  MP_TYPE(x,y) = CST_OREMINE_4;
	  break;
	case (5):
	  MP_TYPE(x,y) = CST_OREMINE_3;
	  break;
	case (6):
	  MP_TYPE(x,y) = CST_OREMINE_2;
	  break;
	case (7):
	  MP_TYPE(x,y) = CST_OREMINE_1;
	  break;
	}
	if (MP_INFO(x,y).int_2 <= 0) {
#if defined (commentout)
	    do_bulldoze_area (CST_GREEN, x, y);
	    place_item(x,y,CST_TIP_0);
#endif
	    int i,j;
	    for (j = 0; j < 4; j++) {
		for (i = 0; i < 4; i++) {
		    do_bulldoze_area (CST_WATER, x+i, y+j);
		}
	    }
	    connect_rivers ();
	    refresh_main_screen ();
	}
    }
}
Esempio n. 7
0
void do_fire(int x, int y)
{
    /*
       // int_1 unused
       // int_2 is the fire length
       // int_3 is the real_time before the fire can spread or -1 if triggered 
       // int_4 is the idle land length
       // MP_ANIM is the next animation frame time, since 1.91
     */
    int i;
    /* this so we don't get whole blocks changing in one go. */
    if (MP_INFO(x, y).int_2 == 0)

        MP_INFO(x, y).int_2 = rand() % (FIRE_LENGTH / 5);
    if (MP_INFO(x, y).int_2 > FIRE_LENGTH) {
        if (MP_INFO(x, y).int_4 == 0)   /* rand length here also */
            MP_INFO(x, y).int_4 = rand() % (AFTER_FIRE_LENGTH / 6);
        MP_INFO(x, y).int_4++;
        if (MP_INFO(x, y).int_4 > AFTER_FIRE_LENGTH)
            if (use_waterwell) {
                do_bulldoze_area(CST_DESERT, x, y);
            } else {
                do_bulldoze_area(CST_GREEN, x, y);
        } else if (MP_INFO(x, y).int_4 > (3 * AFTER_FIRE_LENGTH) / 4)
            MP_TYPE(x, y) = CST_FIRE_DONE4;
        else if (MP_INFO(x, y).int_4 > (2 * AFTER_FIRE_LENGTH) / 4)
            MP_TYPE(x, y) = CST_FIRE_DONE3;
        else if (MP_INFO(x, y).int_4 > (AFTER_FIRE_LENGTH) / 4)
            MP_TYPE(x, y) = CST_FIRE_DONE2;
        else
            MP_TYPE(x, y) = CST_FIRE_DONE1;
        return;
    }
    MP_INFO(x, y).int_2++;
    if (real_time > MP_ANIM(x, y)) {
        MP_ANIM(x, y) = real_time + FIRE_ANIMATION_SPEED;
        if (MP_TYPE(x, y) == CST_FIRE_1)
            MP_TYPE(x, y) = CST_FIRE_2;
        else if (MP_TYPE(x, y) == CST_FIRE_2)
            MP_TYPE(x, y) = CST_FIRE_3;
        else if (MP_TYPE(x, y) == CST_FIRE_3)
            MP_TYPE(x, y) = CST_FIRE_4;
        else if (MP_TYPE(x, y) == CST_FIRE_4)
            MP_TYPE(x, y) = CST_FIRE_5;
        else if (MP_TYPE(x, y) == CST_FIRE_5)
            MP_TYPE(x, y) = CST_FIRE_1;
    }
    if (MP_INFO(x, y).int_3 == -1) {
        if ((rand() % FIRE_DAYS_PER_SPREAD) == 1) {
            i = rand() % 4;
            switch (i) {
            case (0):
                do_random_fire(x - 1, y, 0);
                break;
            case (1):
                do_random_fire(x, y - 1, 0);
                break;
            case (2):
                do_random_fire(x + 1, y, 0);
                break;
            case (3):
                do_random_fire(x, y + 1, 0);
                break;
            }
        }
    } else if (MP_INFO(x, y).int_3 == 0) {
        /* check here 'cos we can wait in the ok box for ever. */
        MP_INFO(x, y).int_3 = real_time + 15000;        /* 15 secs seem fair */
    } else if (real_time >= MP_INFO(x, y).int_3)
        MP_INFO(x, y).int_3 = -1;
}