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

📄 action.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 3 页
字号:
	ptorps = pships->torp_info + i;	if (ptorps->torp_dir != -1)	/* if torp active */	    universe[ptorps->tquadr][ptorps->tquadc].		sectors[ptorps->tsectr][ptorps->tsectc].image = ' ';	};    pships->ship_ch = ' ';  /* last, to avoid timing problems */    /* force fleet display to be re-displayed */    for (ch = 'A'; ch <= 'Z'; ch ++)	ships[ch-A].dis_fleet = true;#   ifdef DRONE    for (i = 0; i < NUMDRONES; i++)	if (drones[i].d_after == sch)	    {	    pdrones = drones + i;	    exit_a_ship (pdrones->d_char, true);	    pdrones->d_char = ' ';	    pdrones->d_after = ' ';	    pdrones->d_busy = false;	    }#   endif DRONE    /*     * If using shared memory, and this is the last user exiting,     * remove the shared memory segment and return immediately.     */    num_users--;#   ifdef SHMEM    if (num_users <= 0 && !drone)	if (shmctl(shmid, IPC_RMID) < 0)	    printf("shmctl call to remove shared seg failed\n");#   endif SHMEM    };damage (ship_ch, damage_amt)    char ship_ch;    int damage_amt;    /* Randomly picks a device to be damaged.  The length of time the device       is damaged is: DAMAGE_CONST seconds per 100 units of energy that       penetrated the shields (damage_amt).       Params:	ship_ch - The ship that is damaged.	damage_amt - amount of energy that penetrated the shields.    */        {    register int damage_time;    /* # of seconds that device is out for */    register struct ship *pships;    long int holdran;	/* random # for device damaged */    holdran = get_rand();    damage_time = DAMAGE_CONST * (damage_amt / 100);    pships = ships + (ship_ch - A);    switch (holdran)	{	case 0:	    pships->shield_time += damage_time;	    pships->dis_shields = false;	    break;	case 1:	    pships->torp_time += damage_time;	    pships->dis_torpedos = false;	    break;	case 2:	    pships->phasers += damage_time;	    break;	case 3:	    pships->warp_drive += damage_time;	    break;	case 4:	    pships->impulse += damage_time;	    break;	case 5:	    pships->life_supp_time += damage_time;	    switch (pships->life_support)		{		case GREEN:		    pships->life_support = YELLOW;		    break;		case YELLOW:		    pships->life_support = RED;		    break;		case RED:		    /* force death of ship */		    pships->energy = -1000;		    pships->shields = 0;		    break;		};	    /* sensors doubled up with life support */	    pships->sensors += damage_time;	    break;	case 6:	    pships->sr_scan += damage_time;	    break;	case 7:	    pships->lr_scan += damage_time;	    break;	case 8:	    pships->radio   += damage_time;	    break;	case 9:	    pships->cloaking  += damage_time;	    pships->cloak = false;	    break;	};  /* switch */    }; /* PROC damage */ship_action (ship_ch)    char ship_ch;    /* Perform all ship actions:	    change_speed	    move_torps	    move_ship	    dock_ship       Param: ship_ch - The calling ship, the one to move.    */    {    register struct ship *pships;    pships = ships + (ship_ch - A);    if (pships->cloak)	{	if (pships->energy > CLOAK_COST)	    pships->energy -= CLOAK_COST;	else pships->cloak = false;	}    if (pships->warp_speed != pships->warp_set)	 change_speed(ship_ch);    else if (((pships->energy + pships->shields) < ENERGY_MAX) && (pships->warp_drive == 0))	     {	     pships->energy = pships->energy + CONSTSP_SAVE;	     pships->dis_energy = true;	     if ((pships->energy + pships->shields) > ENERGY_MAX)		  /* don't allow > 50,000 */		  pships->energy = pships->energy - 			((pships->energy + pships->shields) - ENERGY_MAX);	     };    if (pships->torp_active)	 move_torps(ship_ch);    if (pships->warp_speed > 0)	if (pships->warp_speed < 1)	    if (pships->warp_speed <= 0.3)	        if (pships->sub_light >= 4)		    {		    move_ship(ship_ch);		    pships->sub_light = 1;		    }		else pships->sub_light++;	    else 		if (pships->warp_speed <= 0.6)		    if (pships->sub_light >= 3)			{			move_ship(ship_ch);			pships->sub_light = 1;			}		    else pships->sub_light++;		else		    /* speed is 0.7 to 0.9 */		    if (pships->sub_light >= 2)		         {		         move_ship(ship_ch);		         pships->sub_light = 1;		         }		    else 		        /* incr counter/timer */		        pships->sub_light++;	 /* warp speed >= 1, so just move ship */	 else move_ship(ship_ch);    if (pships->dock && (pships->warp_speed == 0))	 dock_ship(ship_ch);    };  /* proc ship_action */change_speed(ship_ch)    char ship_ch;	/* Increase or decrease the ship's speed by 0.5 warp.  This gives an	   acceleration (or deceleration) rate of 0.5 warp per second.	*/	{	register struct ship *pships;	pships = ships + (ship_ch - A);	if (pships->energy >= CHSPEED_COST)	    {	    pships->energy = pships->energy - CHSPEED_COST;	    pships->dis_energy = true;	    if (pships->warp_speed > pships->warp_set)		 /* decrease speed */		 {		 pships->dis_warp_speed = true;		 if (pships->warp_speed >= (pships->warp_set + SPEED_CHAMT))		      pships->warp_speed = pships->warp_speed - SPEED_CHAMT;		 else pships->warp_speed = pships->warp_set;		 }	    else if (pships->warp_speed < pships->warp_set)		     /* increase speed */		     {		     pships->dis_warp_speed = true;		     if (pships->warp_speed <= (pships->warp_set - SPEED_CHAMT))			  pships->warp_speed = pships->warp_speed + SPEED_CHAMT;		     else pships->warp_speed = pships->warp_set;		     };	    }	else {	     strcpy (pships->msg_buf,"Not enough energy");	     pships->dis_msg = true;	     };        };  /* proc change_speed */move_torps(ship_ch)    char ship_ch;	/* move the ship's torpedos within the global data base (in universe &	   in ships).	*/	{	register struct ship *pships;	register struct torpedo_record *ptorps;	register int i,j;	/* loop index */	register int csr;	/* current sector row */	register int csc;	/* current sector col */	int cqr;		/* current quad row */	int cqc;		/* current quad col */	int hurt;	/* energy units that penetrated a ship's shields */	int nsectors; 	/* # of sectors to move the ship */	boolean expire;	/* set true if (torp hits a ship, BASE or STAR.)	    			Based on this flag, torp_dir is set to -1.	    			This flag is used to avoid a race condition	    			  with scanf_input firing torpedos */	char uchar;	/* current universe.image char */	 pships = ships + (ship_ch - A);	 pships->torp_active = false;	/* assume none active */	 /* loop thru all posible torpedos for this ship */	 for (j = 0; j < TORP_MAX; j ++)	    {	    ptorps = pships->torp_info + j;	    if (ptorps->torp_dir != - 1)		 {	/* torp active here */		 pships->torp_active = true;		 expire = false;		 /* must blank torpedo from old position if it was not just fired */			 if (ptorps->torp_dist != 0)		    universe[ptorps->tquadr][ptorps->tquadc].			sectors [ptorps->tsectr][ptorps->tsectc].image =' ';		 cqr = ptorps->tquadr;		 cqc = ptorps->tquadc;		 csr = ptorps->tsectr;		 csc = ptorps->tsectc;		 nsectors = ptorps->torp_speed;		 /* loop to move torp until all sectors traversed or 		    torp hits something solid */		 i = 1;		 for (; (i <= nsectors) && (ptorps->torp_dist < TORP_TRAVEL) ;)		    {		    switch (ptorps->torp_dir)		    {		    case 1:		       csr = csr + 1;		       csc = csc - 1;		       break;		    case 2:			csr = csr + 1;			break;		    case 3:		       csr = csr + 1;		       csc = csc + 1;			break;		    case 4:			csc = csc - 1;			break;		    case 6: csc = csc + 1;			break;		    case 7:		        csr = csr - 1;		        csc = csc - 1;			break;		    case 8:			csr = csr - 1;			break;		    case 9:		        csr = csr - 1;		        csc = csc + 1;			break;		    default:  ;	/* do nothing */		    };  /* switch */		    /* check for entering adjacent quadrant */		    if (csr < 0)			{	/* goto bottom edge of above quad */			csr = NUMSECTORS -1;			cqr--;			pships->dis_quad = true;			if (cqr < 0)			     cqr = NUMQUADS -1;			};		    if (csc < 0)			{	/* goto right edge of prev quad */			csc = NUMSECTORS -1;			cqc = cqc - 1;			pships->dis_quad = true;			if (cqc < 0)			     cqc = NUMQUADS -1;			};		    if (csr > NUMSECTORS -1)			{	/* goto top edge of quad below */			csr = 0;			cqr = cqr + 1;			pships->dis_quad = true;			if (cqr > NUMQUADS -1)			     cqr = 0;			};		    if (csc > NUMSECTORS -1)			{	/* goto left edge of next quad */			csc = 0;			cqc = cqc + 1;			pships->dis_quad = true;			if (cqc > NUMQUADS -1)			     cqc = 0;			};		    /* check for anything in the path of movement */		    uchar = universe [cqr][cqc].sectors [csr][csc].image;		    switch (uchar)		    {		    case ' ':			  i = i + 1;			  ptorps->torp_dist++;			  break;		    case TORP: 		/* pass thru */			  i++;			  ptorps->torp_dist++;			  break;		    case BASE:		    case STAR: 	/* torp absorbed */			  i = nsectors + 1;  /* force end of while loop */			  expire = true;			  break;		    case ION:  		/* clear_screen path */			  i++;			  ptorps->torp_dist++;			  universe [cqr][cqc].sectors [csr][csc].image=' ';			  break;		    default:			  i = nsectors + 1;			  expire = true;			  if (uchar >= 'A' && uchar <= 'Z')			       {	/* hit a ship! */			       pships = ships + uchar - A;			       pships->dis_shields = true;			       pships->glow = 1;			       pships->cloak = false;			       strcpy(pships->msg_buf,				   "Ship hit by Photon Torpedo");			       pships->dis_msg = true;			       if (pships->shields >= TORP_COST)				    pships->shields = pships->shields-TORP_COST;			       else {				    hurt = TORP_COST - pships->shields;				    pships->energy = pships->energy - hurt;				    pships->shields = 0;				    pships->dis_energy = true;				    damage (uchar, hurt);				    /* give the guy a kill! */				    if (pships->energy <= 0)				       {				       universe[pships->q_row][pships->q_col].sectors					    [pships->s_row][pships->s_col].image = '-';				       pships = ships + (ship_ch - A);				       pships->kills++;				       sprintf (pships->msg_buf, "The %s is destroyed",ships[uchar-A].name);				       pships->dis_msg = true;				       }				    }			       }			    break;		}  /* switch */		}  /* while i <= nsectors */	    /* update torpedos posit in universe and in ships record */	    pships = ships + (ship_ch - A);	    if (! expire && (ptorps->torp_dist < TORP_TRAVEL))		 {		 universe[cqr][cqc].sectors [csr][csc].image = TORP;		 ptorps->tquadr = cqr;		 ptorps->tquadc = cqc;		 ptorps->tsectr = csr;		 ptorps->tsectc = csc;		 }	    else ptorps->torp_dir = -1;	/* set torp record free */	    };  /* torp active */	};  /* for j = 0; j < TORP_MAX */	};  /* proc move_torps */move_ship(ship_ch)    char ship_ch;	/* move the ship's position within the global data base (in universe &	   in ships).	   Param: ship_ch - The calling ship, the one to move.	*/		{	register struct ship *pships;	register int cqr;		/* current quad row */	register int cqc;		/* current quad col */	register int csr;		/* current sector row */	register int csc;		/* current sector col */	register int i;	/* loop index */	int holdqr;	/* hold prev posit in case ship hits base or ship */	int holdqc;	int holdsr;	int holdsc;	int hurt;	/* energy units that penetrated a ship's shields */	int nsectors; 	/* # of sectors to move the ship */	char uchar;	/* universe char at current coordinates */	 pships = ships + (ship_ch - A);	 /* must blank ship first, in case ship hit something & didn't move */		 if (! pships->ship_invis)	      universe[pships->q_row][pships->q_col].sectors		    [pships->s_row][pships->s_col].image = ' ';	 else pships->ship_invis = false;

⌨️ 快捷键说明

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