⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ship.cc

📁 国外一套很好的游戏代码,款经典的小游戏 希望大家提出宝贵意见 让我们一起进步
💻 CC
📖 第 1 页 / 共 3 页
字号:
				if(slots[j].item)				{					esel=j;					break;				}			}		}		if(opr==4)		{			if(esel>=0 && esel<32 && slots[esel].item)			{				if(slots[esel].item->typ==equip::TRANSPORTER)				{					sprintf(txt,"Cannot jettison transporters");				}				else				{					sprintf(txt,"%s jettisoned",slots[esel].item->nam);					slots[esel].item=NULL;					slots[esel].rdy=0;					slots[esel].cap=0;					resequip();				}			}		}		break;		case CMOD_HAIL:		if(crip)		{			if(opr==-1)			{				txt+=sprintf(txt,"Hailing ship\n\n");				txt+=sprintf(txt,"Vessel is disabled\n\n[1] Attempt to recover it");			}			if(opr==1)			{				mshp->transport(this);				enem=NULL;				plnt=NULL;				frnd=mshp;				for(int i=0;i<ISIZE;i++)					if(ships[i] && ships[i]->enem==this)						ships[i]->enem=NULL;				txt+=sprintf(txt,"Vessel successfully acquired");				mshp->ply->transfer(this);			}		}		else		{			if(frnd==mshp)			{				if(opr==-1)				{					txt+=sprintf(txt,"Hailing ship\n\n");					txt+=sprintf(txt,"Vessel is under your command\n\n[1] Transfer to this vessel");				}				if(opr==1)				{					try					{						mshp->transport(this);							mshp->ply->transfer(this);						txt+=sprintf(txt,"Transfer of command successful");					}					catch(error it)					{						try						{							transport(mshp);							mshp->ply->transfer(this);						}						catch(error iti)						{							throw it;						}					}				}			}			else			{				txt+=sprintf(txt,"Hailing ship\n\n");				txt+=sprintf(txt,"No reply");			}		}		break;				case CMOD_WHOIS:		if(ply)		{			txt+=sprintf(txt,"Player: %s\n",ply->nam);			txt+=sprintf(txt,"Alliance: %s\n",all->nam);			return spr;		}		else			txt+=sprintf(txt,"Target not player controlled\n");		break;	}	return -1;}int ship::freemass(){	int out; //Outputted free space	out=mss;	for(int i=0;i<32;i++)	{		if(slots[i].item)			out-=slots[i].item->mss;	}	return out;}void ship::cloak(){	if(clk && clk->rdy!=0)	{		clk->rdy=0;		server::registernoise(this,clk->item->snd);	}}void ship::uncloak(){	if(clk && clk->rdy!=-1)	{		clk->rdy=-1;		if(clk->cap>0)			clk->cap=-clk->cap;		server::registernoise(this,clk->item->snd);	}}void ship::shieldsup(){	if(shd)		shd->rdy=0;}void ship::shieldsdown(){	if(shd)		shd->rdy=-1;}void ship::netout(int typ,unsigned char* buf){	buf[0]=typ;	buf+=1;	calc::inttodat(ship2pres(self),buf);	buf+=2;	switch(typ)	{		case SERV_SELF:		if(mss>0)			calc::inttodat((100*hul)/mhul,buf);		else			calc::inttodat(0,buf);		buf+=2;		if(pow && pow->cap>0)			calc::inttodat((100*pow->cap)/(pow->item->cap),buf);		else			calc::inttodat(0,buf);		buf+=2;		if(shd && shd->cap>0)			calc::inttodat((100*shd->cap)/(shd->item->cap),buf);		else			calc::inttodat(0,buf);		buf+=2;		if(ful && ful->cap>0)			calc::inttodat((100*ful->cap)/(ful->item->cap),buf);		else			calc::inttodat(0,buf);		buf+=2;		if(sens)			calc::longtodat(sens->item->rng,buf);		else			calc::longtodat(0,buf);		buf+=4;		calc::longtodat(LIMIT,buf);		buf+=4;		if(plnt)		{			calc::inttodat(planet2pres(plnt->self),buf);		}		else		{			if(enem)				calc::inttodat(ship2pres(enem->self),buf);			else				calc::inttodat(-1,buf);		}		buf+=2;		calc::inttodat(-1,buf);		buf+=2;		calc::inttodat(-1,buf);		break;		case SERV_NEW:		*buf=PT_SHIP;		buf+=1;		calc::inttodat(spr,buf);		buf+=2;		calc::inttodat(-1,buf);		buf+=2;		break;		case SERV_NAME:		sprintf((char*)buf,"%s",cls);		buf+=64;		sprintf((char*)buf,"%s",all->nam);		buf+=64;		break;		case SERV_UPD:		calc::longtodat(loc.x,buf);		buf+=4;		calc::longtodat(loc.y,buf);		buf+=4;		calc::longtodat(mov.xx,buf);		buf+=4;		calc::longtodat(mov.yy,buf);		buf+=4;		calc::inttodat(vel.ang,buf);		buf+=2;		*buf=0;		buf+=1;		if(clk && clk->item->cap)		{			if(clk->cap>=0)				*buf=100-((100*clk->cap)/clk->item->cap);			else				*buf=100+((100*clk->cap)/clk->item->cap);		}		else			*buf=100;		buf+=1;		break;		default:		break;	}}bool ship::colldetect(cord frgl,vect frgv){	int rot; //Target rotation	double x1,y1,x2,y2,xx,yy; //Target bounding box	rot=(int)(((vel.ang+5)/10))%36;	xx=(frgv.xx-mov.xx)/2;	yy=(frgv.yy-mov.yy)/2;	if(xx<0)		xx=-xx;	if(yy<0)		yy=-yy;	x1=loc.x-(w[rot]*3)/2-xx;	y1=loc.y-(h[rot]*3)/2-yy;	x2=loc.x+(w[rot]*3)/2+xx;	y2=loc.y+(h[rot]*3)/2+yy;	if(frgl.x>x1 && frgl.x<x2 && frgl.y>y1 && frgl.y<y2)		return true;	else		return false;}void ship::hit(int mag,cord frgl,vect frgv,ship* src){	cord tmpc;	vect tmpv; //Temporary for working out detonations	int rot; //Target rotation	int ndeb; //Number of debris bits	uncloak();	rot=(int)(((vel.ang+5)/10))%36;	if(shd)		shd->cap-=mag;	server::registershake(this,mag/100);	if(src && enem!=src && !(all->opposes(src->all)) && src->ply)		src->lynch();	if(shd && shd->cap>0)	{		try		{			new frag(frgl,frag::DEBRIS,shd->item->spr,-1,NULL,this,mov,calc::rnd(36),0,0,2);		}		catch(error it)		{		}	}	else	{		if(shd)			shd->cap=0;		frgl.x=(frgl.x+2*loc.x)/3;		frgl.y=(frgl.y+2*loc.y)/3;		for(int i=0;i<5;i++)		{			tmpv=mov;			frgl.x+=calc::rnd(2)-calc::rnd(2);			frgl.y+=calc::rnd(2)-calc::rnd(2);			tmpv.xx+=calc::rnd(2)-calc::rnd(2);			tmpv.yy+=calc::rnd(2)-calc::rnd(2);			try			{				new frag(frgl,frag::DEBRIS,frag::FIRE,-1,NULL,this,tmpv,calc::rnd(36),0,0,calc::rnd(5)+5);			}			catch(error it)			{			}		}		server::registernoise(this,fsnd);	}	if(shd && shd->cap!=-10)		hul-=(mag*4)/(shd->cap+10);	else		hul-=(mag*4)/10;	if(hul<=0)	{		hul=0;		ndeb=mss/8+4;		if(ndeb>70)			ndeb=70;		for(int i=0;i<ndeb;i++)		{				if(i==0 || calc::rnd(5)==0)			{				tmpc=loc;				tmpc.x+=calc::rnd(2*w[rot])-calc::rnd(2*w[rot]);				tmpc.y+=calc::rnd(2*h[rot])-calc::rnd(2*h[rot]);			}			tmpv=mov;			try			{				if(calc::rnd(10)<3)				{					new frag(tmpc,frag::DEBRIS,frag::FIRE,-1,NULL,this,tmpv,calc::rnd(36),0,0,calc::rnd(20)+5);				}				else				{					tmpv.xx+=calc::rnd(2)-calc::rnd(2);					tmpv.yy+=calc::rnd(2)-calc::rnd(2);					new frag(tmpc,frag::DEBRIS,fspr,-1,NULL,this,tmpv,calc::rnd(36),0,0,calc::rnd(20)+5);				}			}			catch(error it)			{			}		}		if(src && src->ply && src->all->opposes(all))		{			server::hail(NULL,src->ply,"Target destroyed; bounty paid");			src->ply->credit(mss/2);		}		server::registernoise(this,dsnd);		if(ply)			server::bulletin("%s has been destroyed",ply->nam);		delete this;	}	else	{		if(hul<mhul/2 && src && src->ply && !ply && !crip)		{			server::hail(NULL,src->ply,"Target crippled");			crip=true;		}	}}void ship::assign(player* ply){	this->ply=ply;	enem=NULL;	frnd=NULL;	crip=false;	aity=AI_NULL;	resequip();}long ship::purchase(int prch,short ripo,bool buy){	long cost; //Value to output	cost=0;	if(prch==PRCH_FUEL)	{		if(ful)		{			if((ful->cap)<(ful->item->cap))				cost=ripo/4;			if(buy)			{				ful->cap=ful->item->cap;				ply->debit(cost);			}		}	}	if(prch==PRCH_ARMS)	{		for(int i=0;i<32;i++)		{			if(slots[i].item && slots[i].item->typ==equip::LAUNCHER)			{				if(slots[i].cap<slots[i].item->cap)				{					cost=(slots[i].item->cost*ripo)/1000;					if(buy)					{						ply->debit(cost);						slots[i].cap=slots[i].item->cap;					}					break;				}			}		}	}	if(prch==PRCH_HULL)	{		cost=((mhul-hul)*ripo)/100;		if(buy)		{			ply->debit(cost);			hul=mhul;		}	}	return cost;}long ship::purchase(equip* prch,int ripo,bool buy){	long cost; //Value to output	if(!prch)		return 0;	cost=(prch->cost*ripo)/100;	if(buy && !(prch->mss>freemass()))	{		for(int i=0;i<32;i++)		{			if(!slots[i].item)			{				if((slots[i].pos.rad>=0 && (prch->typ==equip::PHASER || prch->typ==equip::LAUNCHER)) || (slots[i].pos.rad==-1 && prch->typ!=equip::PHASER && prch->typ!=equip::LAUNCHER))				{					ply->debit(cost);					slots[i].item=prch;					slots[i].cap=prch->cap;					slots[i].rdy=prch->rdy;					resequip();					break;				}			}		}	}	return cost;}void ship::transport(planet* to){	vect vto;	pol pto; //Vectors to the target	vto.xx=to->loc.x-loc.x;	vto.yy=to->loc.y-loc.y;	pto=vto.topol();	if(shd && shd->cap>0)		throw error("Cannot transport with shields up");	if(!pow)		throw error("Not enough power to transport");	if(clk && clk->cap!=0)		throw error("Cannot transport while cloaked");	for(int i=0;i<32;i++)	{		if(slots[i].item && slots[i].item->typ==equip::TRANSPORTER && slots[i].rdy==0 && pow->cap>=slots[i].item->pow && slots[i].item->rng>=pto.rad)		{			pow->cap-=slots[i].item->pow;			slots[i].rdy=slots[i].item->rdy;			server::registersound(this,slots[i].item->snd);			return;		}	}	throw error("No available transporters ready or powered");}void ship::transport(ship* to){	vect vto;	pol pto; //Vectors to the target	vto.xx=to->loc.x-loc.x;	vto.yy=to->loc.y-loc.y;	pto=vto.topol();	if(shd && shd->cap>0)		throw error("Cannot transport with shields up");	if(!pow)		throw error("Not enough power to transport");	if(clk && clk->cap!=0)		throw error("Cannot transport while cloaked");	if(to->shd && to->shd->cap>0)		throw error("Cannot transport through destination's shields");	if(to->clk && to->clk->cap!=0)		throw error("Cannot transport through destination's cloak");	for(int i=0;i<32;i++)	{		if(slots[i].item && slots[i].item->typ==equip::TRANSPORTER && slots[i].rdy==0 && pow->cap>=slots[i].item->pow && slots[i].item->rng>=pto.rad)		{			pow->cap-=slots[i].item->pow;			slots[i].rdy=slots[i].item->rdy;			server::registersound(this,slots[i].item->snd);			return;		}	}	throw error("No available transporters ready or powered");}void ship::save(){	char atsc[33]; //Attribute scratchpad	database::putvalue("Class",cls);	database::putvalue("Type",typ);	database::putvalue("ShipSprite",spr);	database::putvalue("Width",w[0]);	database::putvalue("Height",h[0]);	if(fspr)		database::putvalue("FragSprite",fspr);	if(fsnd)		database::putvalue("FragSound",fsnd);	if(dsnd)		database::putvalue("DeathSound",dsnd);	if(all)		database::putvalue("Team",all->self);	database::putvalue("AIType",aity);	database::putvalue("XLoc",loc.x);	database::putvalue("YLoc",loc.y);	database::putvalue("Heading",vel.ang);	database::putvalue("Speed",vel.rad);	database::putvalue("TurnRate",trn);	database::putvalue("SublightLimit",mip);	database::putvalue("SublightAcceleration",aip*10);	database::putvalue("WarpLimit",mwp);	database::putvalue("WarpAcceleration",awp);	database::putvalue("Mass",mss);	database::putvalue("HullStrength",hul);	database::putvalue("HullStrengthLimit",mhul);	if(frnd)		database::putvalue("FriendTarget",frnd->self);	if(enem)		database::putvalue("EnemyTarget",enem->self);	if(plnt)		database::putvalue("PlanetTarget",plnt->self);	database::putvalue("MassLock",mlck);	database::putvalue("Crippled",crip);	for(int i=0;i<32;i++)	{		if(slots[i].item || slots[i].pos.rad!=-1)		{			sprintf(atsc,"Slot%hdAngle",i);			database::putvalue(atsc,slots[i].pos.ang);			sprintf(atsc,"Slot%hdRadius",i);			database::putvalue(atsc,slots[i].pos.rad);			sprintf(atsc,"Slot%hdFace",i);			database::putvalue(atsc,slots[i].face);			sprintf(atsc,"Slot%hdItem",i);			if(slots[i].item)				database::putvalue(atsc,slots[i].item->self);			else				database::putvalue(atsc,-1);			sprintf(atsc,"Slot%hdReadiness",i);			database::putvalue(atsc,slots[i].rdy);			sprintf(atsc,"Slot%hdCapacity",i);			database::putvalue(atsc,slots[i].cap);		}	}}void ship::load(){	char atsc[33]; //Attribute scratchpad	pol bpol;	vect vct1,vct2; //Temporaries for calculating the bounding box	database::getvalue("Class",cls);	typ=database::getvalue("Type");	spr=database::getvalue("ShipSprite");	w[0]=database::getvalue("Width");	h[0]=database::getvalue("Height");	for(int i=1;i<36;i++)	{		bpol.ang=i*10;		bpol.rad=h[0];		vct1=bpol.tovect();		bpol.ang=(i*10+90)%360;		bpol.rad=w[0];		vct2=bpol.tovect();		if(vct1.xx<0)			vct1.xx=-vct1.xx;		if(vct2.xx<0)			vct2.xx=-vct2.xx;		if(vct1.yy<0)			vct1.yy=-vct1.yy;		if(vct2.yy<0)			vct2.yy=-vct2.yy;		if(vct1.xx>vct2.xx)			w[i]=(int)vct1.xx;		else			w[i]=(int)vct2.xx;		if(vct1.yy>vct2.yy)			h[i]=(int)vct1.yy;		else			h[i]=(int)vct2.yy;	}	fspr=database::getvalue("FragSprite");	fsnd=database::getvalue("FragSound");	dsnd=database::getvalue("DeathSound");	all=alliance::get(database::getvalue("Team"));	aity=database::getvalue("AIType");	loc.x=database::getvalue("XLoc");	loc.y=database::getvalue("YLoc");	vel.ang=database::getvalue("Heading");	vel.rad=database::getvalue("Speed");	trn=database::getvalue("TurnRate");	mip=database::getvalue("SublightLimit");	aip=(double)database::getvalue("SublightAcceleration")/10;	mwp=database::getvalue("WarpLimit");	awp=database::getvalue("WarpAcceleration");	mss=database::getvalue("Mass");	hul=database::getvalue("HullStrength");	mhul=database::getvalue("HullStrengthLimit");		mlck=database::getvalue("MassLock");	crip=database::getvalue("Crippled");	esel=-1;	for(int i=0;i<32;i++)	{		sprintf(atsc,"Slot%hdAngle",i);		slots[i].pos.ang=database::getvalue(atsc);		sprintf(atsc,"Slot%hdRadius",i);		slots[i].pos.rad=database::getvalue(atsc);		sprintf(atsc,"Slot%hdFace",i);		slots[i].face=database::getvalue(atsc);		if(slots[i].face==-1)			slots[i].face=slots[i].pos.ang;		sprintf(atsc,"Slot%hdItem",i);		slots[i].item=equip::get(database::getvalue(atsc));		sprintf(atsc,"Slot%hdReadiness",i);		slots[i].rdy=database::getvalue(atsc);		sprintf(atsc,"Slot%hdCapacity",i);		slots[i].cap=database::getvalue(atsc);		if(slots[i].cap==-1 && slots[i].item)			slots[i].cap=slots[i].item->cap;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -