示例#1
0
void Save::makeSave(CIndieLib* mI, Ship* mShip, vector<Planet*>& mPlanets)
{
	if (mShip != NULL && mShip->getHealth() > 0)
	{
		setMI(mI);
		getSaveFile()->open("../SpaceGame/Saves/quickSave.txt", ios::trunc);
		if (!getSaveFile()->is_open())
		{
			writeError(1000, 100, "Save", "Can't open file for writing!");
			return;
		}

		writeShip(mShip);
		short int i = 0;
		for (vector<Planet*>::iterator it = mPlanets.begin(); it != mPlanets.end(); ++it)
		{
			writePlanet(*it, i);
			i++;
		}
		getSaveFile()->close();
	}
}
示例#2
0
文件: ship.c 项目: fstltna/ImpFE
/*
 * buildShDetDisp - Clears the existing contents of the ship detail
 *                 window and redraws it based on current known
 *                 ships.
 */
void buildShDetDisp(void)
{
	ULONG itNum;
	USHORT num_comp=0, num_eng=0, num_life=0, num_wpn=0, num_elect=0;
	FeShip_t tmpShip;
	FeItem_t tmpItem;
	int compChar, engChar, lifeChar, photChar, blasChar, sensChar,
		shldChar, telepChar, tractChar;
	char workBuf[90], nameBuf[10], itType, location[15], tBuff[28], inst;

	/* Speed up output */
	fl_freeze_form(fd_ShipDetailForm->ShipDetailForm);
	/* Clear the existing contents, if any */
	fl_clear_browser(fd_ShipDetailForm->ShDetItem);
	compChar = (int) BIG_PART_CHAR[bp_computer];
	engChar = (int) BIG_PART_CHAR[bp_engines];
	lifeChar = (int) BIG_PART_CHAR[bp_lifeSupp];
	photChar = (int) BIG_PART_CHAR[bp_photon];
	blasChar = (int) BIG_PART_CHAR[bp_blaser];
    sensChar = (int) BIG_PART_CHAR[bp_sensors];
	shldChar = (int) BIG_PART_CHAR[bp_shield];
	telepChar = (int) BIG_PART_CHAR[bp_teleport];
	tractChar = (int) BIG_PART_CHAR[bp_tractor];
	/* Loop for each known big item */
	for (itNum=0; itNum < next_item; itNum++)
	{
		/* Make sure the item has been seen and is on the ship */
		if (!readItem(&tmpItem, itNum))
		{
			continue;
		}
		if ((tmpItem.last_seen != 0) && (tmpItem.where == LastShip) &&
			!(tmpItem.flags & BF_ONPLAN))
		{
			if (tmpItem.owner != 0)
			{
				strncpy(nameBuf, Player[tmpItem.owner].name, 9);
				nameBuf[9] = '\0';
			}
			else
			{
				strcpy(nameBuf, "???");
			}
			if (tmpItem.type != 0)
			{
				itType=tmpItem.type;
			}
			else
			{
				itType='?';
			}
			/* Check if it is installed, or just cargo */
			if (tmpItem.flags & BF_INSTALL)
			{
				/* Installed */
				inst='Y';
				/* Increment our running counts */
				if (itType == tractChar)
				{
					num_comp++;
				}
				else if (itType == engChar)
				{
					num_eng++;
				}
				else if (itType == lifeChar)
				{
					num_life++;
				}
				else if ((itType == photChar) || (itType == blasChar))
				{
					num_wpn++;
				}
				else if ((itType == sensChar) || (itType == shldChar) ||
						 (itType == telepChar) || (itType == tractChar))
				{
					num_elect++;
				}
			}
			else
			{
				/* Not installed, just being carried */
				inst=' ';
			}
			sprintf(workBuf, "%8u  %c  %3u  %3u  %5u %c", itNum,
					itType, tmpItem.it_tf, tmpItem.efficiency,
					tmpItem.weight, inst);
			fl_add_browser_line(fd_ShipDetailForm->ShDetItem, workBuf);
		}
	}
	/* read the ship in */
	(void) readShip(&tmpShip, LastShip);
	/* Update using the counts we saw before */
	tmpShip.num_comp = num_comp;
	tmpShip.num_eng = num_eng;
	tmpShip.num_life = num_life;
	tmpShip.num_wpn = num_wpn;
	tmpShip.num_elect = num_elect;
	/* Write ship back */
	(void) writeShip(&tmpShip, LastShip);
	sprintf(workBuf, "%u", tmpShip.fuelLeft);
	fl_set_object_label(fd_ShipDetailForm->Fuel, workBuf);
	sprintf(workBuf, "%u", tmpShip.energy);
	fl_set_object_label(fd_ShipDetailForm->Energy, workBuf);
	sprintf(workBuf, "%u", tmpShip.armourLeft);
	fl_set_object_label(fd_ShipDetailForm->Armor, workBuf);
	sprintf(workBuf, "%u", tmpShip.shields);
	fl_set_object_label(fd_ShipDetailForm->Shields, workBuf);
	sprintf(workBuf, "%u", tmpShip.shieldsKeep);
	fl_set_object_label(fd_ShipDetailForm->ShKeep, workBuf);
	sprintf(workBuf, "%u", tmpShip.airLeft);
	fl_set_object_label(fd_ShipDetailForm->Air, workBuf);
	sprintf(workBuf, "%u", tmpShip.efficiency);
	fl_set_object_label(fd_ShipDetailForm->Effic, workBuf);
	sprintf(workBuf, "%u", tmpShip.sh_tf);
	fl_set_object_label(fd_ShipDetailForm->TF, workBuf);
	sprintf(workBuf, "%u", tmpShip.hullTF);
	fl_set_object_label(fd_ShipDetailForm->HullTF, workBuf);
	sprintf(workBuf, "%u", tmpShip.engTF);
	fl_set_object_label(fd_ShipDetailForm->EngTF, workBuf);
	sprintf(workBuf, "%u", tmpShip.engEff);
	fl_set_object_label(fd_ShipDetailForm->EngEff, workBuf);
	if (tmpShip.plagueStage != 0)
	{
		fl_set_object_label(fd_ShipDetailForm->Plague, "YES");
	}
	else
	{
		fl_set_object_label(fd_ShipDetailForm->Plague, "NO");
	}
	sprintf(workBuf, "%u", tmpShip.num_civ);
	fl_set_object_label(fd_ShipDetailForm->Civ, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_sci);
	fl_set_object_label(fd_ShipDetailForm->Sci, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_mil);
	fl_set_object_label(fd_ShipDetailForm->Mil, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_ofc);
	fl_set_object_label(fd_ShipDetailForm->Ofc, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_torp);
	fl_set_object_label(fd_ShipDetailForm->Torp, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_ore);
	fl_set_object_label(fd_ShipDetailForm->Ore, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_gold);
	fl_set_object_label(fd_ShipDetailForm->Bars, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_airt);
	fl_set_object_label(fd_ShipDetailForm->AirTnk, workBuf);
	sprintf(workBuf, "%u", tmpShip.num_ftnk);
	fl_set_object_label(fd_ShipDetailForm->FuelTnk, workBuf);
	sprintf(workBuf, "%u", tmpShip.cargo);
	fl_set_object_label(fd_ShipDetailForm->Cargo, workBuf);
	strcpy(workBuf, ctime(&tmpShip.last_seen));
	workBuf[24]='\0'; /* strip off NL */
	fl_set_object_label(fd_ShipDetailForm->Seen, workBuf);
	sprintf(workBuf, "%u", LastShip);
	fl_set_object_label(fd_ShipDetailForm->ShNum, workBuf);
	sprintf(workBuf, "%u,%u", tmpShip.sh_row, tmpShip.sh_col);
	fl_set_object_label(fd_ShipDetailForm->RowCol, workBuf);
	if (tmpShip.owner != 0)
	{
		strcpy(workBuf, Player[tmpShip.owner].name);
	}
	else
	{
		strcpy(workBuf, "???");
	}
	fl_set_object_label(fd_ShipDetailForm->Owner, workBuf);
	if (tmpShip.flags & BF_ONPLAN)
	{
		sprintf(workBuf, "Ship is on planet %u", tmpShip.planet);
		fl_set_object_label(fd_ShipDetailForm->Where, workBuf);
	}
	else
	{
		fl_set_object_label(fd_ShipDetailForm->Where, "Ship is in space");
	}

	fl_unfreeze_form(fd_ShipDetailForm->ShipDetailForm);
}