int
main(int argc, char **argv) {
	int rc = 0;
	bootenv_t env = NULL;
	uint32_t boot_volno;
	myargs args = {
		.action = ACT_NORMAL,
		.file_in  = NULL,
		.file_out = NULL,
		.side = -1,
		.x86 = 0,
		.both = 0,
		.env_in = NULL,

		.arg1 = NULL,
		.options = NULL,
	};

	rc = bootenv_create(&env);
	if (rc != 0) {
		err_msg("Cannot create bootenv handle. rc: %d", rc);
		goto err;
	}

	rc = bootenv_create(&(args.env_in));
	if (rc != 0) {
		err_msg("Cannot create bootenv handle. rc: %d", rc);
		goto err;
	}

	parse_opt(argc, argv, &args);
	if (args.action == ACT_ARGP_ERR) {
		rc = -1;
		goto err;
	}
	if (args.action == ACT_ARGP_ABORT) {
		rc = 0;
		goto out;
	}

	if ((args.side == 0) || (args.side == -1))
		boot_volno = EXAMPLE_BOOTENV_VOL_ID_1;
	else
		boot_volno = EXAMPLE_BOOTENV_VOL_ID_2;

	if( args.x86 )
		rc = read_bootenv(args.file_in, env);
	else
		rc = ubi_read_bootenv(EXAMPLE_UBI_DEVICE, boot_volno, env);
	if (rc != 0) {
		goto err;
	}

	if (args.action == ACT_LIST) {
		rc = list_bootenv(env);
		if (rc != 0) {
			goto err;
		}
		goto out;
	}

	rc = process_key_value(args.env_in, env);
	if (rc != 0) {
		goto err;
	}

	if( args.x86 )
		rc = write_bootenv(args.file_in, env);
	else
		rc = ubi_write_bootenv(EXAMPLE_UBI_DEVICE, boot_volno, env);
	if (rc != 0)
		goto err;

	if( args.both )		/* No side specified, update both */
		rc = do_mirror(boot_volno);

 out:
 err:
	bootenv_destroy(&env);
	bootenv_destroy(&(args.env_in));
	return rc;
}
Exemplo n.º 2
0
void doship(shiptype *ship, int update)
{
    racetype *Race;
    shiptype *ship2;

    /*ship is active */
    ship->active = 1;

    if(!ship->owner) ship->alive = 0;

    if (ship->alive) {
        /* repair radiation */
        if (ship->rad) {
            ship->active = 1;
            /* irradiated ships are immobile.. */
            /* kill off some people */
            /* check to see if ship is active */
            if(success(ship->rad))
                ship->active = 0;
            if(update) {
                ship->popn = round_rand(ship->popn * .80);
                ship->troops = round_rand(ship->troops * .80);
                if (ship->rad >= (int)REPAIR_RATE)
                    ship->rad -= int_rand(0,(int)REPAIR_RATE);
                else
                    ship->rad -= int_rand(0,(int)ship->rad);
            }
        } else
            ship->active = 1;

        if(!ship->popn && Max_crew(ship) && !ship->docked)
            ship->whatdest = LEVEL_UNIV;

        if (ship->whatorbits != LEVEL_UNIV
                && Stars[ship->storbits]->nova_stage>0) {
            /* damage ships from supernovae */
            /* Maarten: modified to take into account MOVES_PER_UPDATE */
            ship->damage += 5 * Stars[ship->storbits]->nova_stage /
                            ((Armor(ship)+1) * segments);
            if (ship->damage >= 100) {
                kill_ship((int)(ship->owner), ship);
                return;
            }
        }

        if(ship->type==OTYPE_FACTORY && !ship->on) {
            Race = races[ship->owner-1];
            ship->tech = Race->tech;
        }

        if(ship->active)
            Moveship(ship, update, 1, 0);

        ship->size = ship_size(ship);	/* for debugging */

        if(ship->whatorbits==LEVEL_SHIP) {
            (void)getship(&ship2, (int)ship->destshipno);
            if(ship2->owner != ship->owner) {
                ship2->owner = ship->owner;
                ship2->governor = ship->governor;
                putship(ship2);
            }
            free(ship2);
            /* just making sure */
        } else if(ship->whatorbits != LEVEL_UNIV &&
                  (ship->popn || ship->type == OTYPE_PROBE)) {
            /* Though I have often used TWCs for exploring, I don't think it is right */
            /* to be able to map out worlds with this type of junk. Either a manned ship, */
            /* or a probe, which is designed for this kind of work.  Maarten */
            StarsInhab[ship->storbits] = 1;
            setbit(Stars[ship->storbits]->inhabited, ship->owner);
            setbit(Stars[ship->storbits]->explored, ship->owner);
            if(ship->whatorbits == LEVEL_PLAN) {
                planets[ship->storbits][ship->pnumorbits]->info[ship->owner-1].explored = 1;
            }
        }

        /* add ships, popn to total count to add AP's */
        if(update) {
            Power[ship->owner-1].ships_owned++;
            Power[ship->owner-1].resource += ship->resource;
            Power[ship->owner-1].fuel += ship->fuel;
            Power[ship->owner-1].destruct += ship->destruct;
            Power[ship->owner-1].popn += ship->popn;
            Power[ship->owner-1].troops += ship->troops;
        }

        if (ship->whatorbits==LEVEL_UNIV) {
            Sdatanumships[ship->owner-1]++;
            Sdatapopns[ship->owner] += ship->popn;
        } else {
            starnumships[ship->storbits][ship->owner-1]++;
            /* add popn of ships to popn */
            starpopns[ship->storbits][ship->owner-1] += ship->popn;
            /* set inhabited for ship */
            /* only if manned or probe.  Maarten */
            if (ship->popn || ship->type==OTYPE_PROBE) {
                StarsInhab[ship->storbits] = 1;
                setbit(Stars[ship->storbits]->inhabited, ship->owner);
                setbit(Stars[ship->storbits]->explored, ship->owner);
            }
        }

        if (ship->active) {
            /* bombard the planet */
            if (can_bombard(ship) && ship->bombard
                    && ship->whatorbits==LEVEL_PLAN
                    && ship->whatdest==LEVEL_PLAN
                    && ship->deststar== ship->storbits
                    && ship->destpnum== ship->pnumorbits) {
                /* ship bombards planet */
                Stinfo[ship->storbits][ship->pnumorbits].inhab = 1;
            }

            /* repair ship by the amount of crew it has */
            /* industrial complexes can repair (robot ships
               and offline factories can't repair) */
            if(ship->damage && Repair(ship))
                do_repair(ship);

            if(update)
                switch (ship->type) {  /* do this stuff during updates only*/
                case OTYPE_CANIST:
                    do_canister(ship);
                    break;
                case OTYPE_GREEN:
                    do_greenhouse(ship);
                    break;
                case STYPE_MIRROR:
                    do_mirror(ship);
                    break;
                case STYPE_GOD:
                    do_god(ship);
                    break;
                case OTYPE_AP:
                    do_ap(ship);
                    break;
                case OTYPE_VN:	/* Von Neumann machine */
                case OTYPE_BERS:
                    if(!ship->special.mind.progenitor)
                        ship->special.mind.progenitor = 1;
                    do_VN(ship);
                    break;
                case STYPE_OAP:
                    do_oap(ship);
                    break;
                case STYPE_HABITAT:
                    do_habitat(ship);
                    break;
                default:
                    break;
                }
            if(ship->type==STYPE_POD)
                do_pod(ship);
        }
    }
}