예제 #1
0
static void inclinenumber (LexState *LS) {
	static const char *pragmas [] =
	{ "debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL };
	next(LS);  // skip '\n'
	++LS->linenumber;
	if (LS->current == '$') {  // is a pragma?
		char buff[PRAGMASIZE + 1];
		int32 ifnot = 0;
		int32 skip = LS->ifstate[LS->iflevel].skip;
		next(LS);  // skip $
		readname(LS, buff);
		switch (luaO_findstring(buff, pragmas)) {
		case 0:  // debug
			if (!skip)
				lua_debug = 1;
			break;
		case 1:  // nodebug
			if (!skip)
				lua_debug = 0;
			break;
		case 2:  // endinput
			if (!skip) {
				LS->current = EOZ;
				LS->iflevel = 0;  // to allow $endinput inside a $if
			}
			break;
		case 3:  // end
			if (LS->iflevel-- == 0)
				luaY_syntaxerror("unmatched $end", "$end");
			break;
		case 4:  // ifnot
			ifnot = 1;
			// go through
		case 5:  // if
			if (LS->iflevel == MAX_IFS - 1)
				luaY_syntaxerror("too many nested $ifs", "$if");
			readname(LS, buff);
			LS->iflevel++;
			LS->ifstate[LS->iflevel].elsepart = 0;
			LS->ifstate[LS->iflevel].condition = checkcond(buff) ? !ifnot : ifnot;
			LS->ifstate[LS->iflevel].skip = skip || !LS->ifstate[LS->iflevel].condition;
			break;
		case 6:  // else
			if (LS->ifstate[LS->iflevel].elsepart)
				luaY_syntaxerror("unmatched $else", "$else");
			LS->ifstate[LS->iflevel].elsepart = 1;
			LS->ifstate[LS->iflevel].skip = LS->ifstate[LS->iflevel - 1].skip || LS->ifstate[LS->iflevel].condition;
			break;
		default:
			luaY_syntaxerror("unknown pragma", buff);
		}
		skipspace(LS);
		if (LS->current == '\n')  // pragma must end with a '\n' ...
			inclinenumber(LS);
		else if (LS->current != EOZ)  // or eof
			luaY_syntaxerror("invalid pragma format", buff);
		ifskip(LS);
	}
}
예제 #2
0
파일: llex.c 프로젝트: calandoa/zite
static void inclinenumber (LexState *LS) {
  static char *pragmas [] =
    {"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
  next(LS);  /* skip '\n' */
  ++LS->linenumber;
  if (LS->current == '$') {  /* is a pragma? */
    char buff[PRAGMASIZE+1];
    int ifnot = 0;
    int skip = LS->ifstate[LS->iflevel].skip;
    next(LS);  /* skip $ */
    readname(LS, buff);
    switch (luaL_findstring(buff, pragmas)) {
      case 0:  /* debug */
        if (!skip) L->debug = 1;
        break;
      case 1:  /* nodebug */
        if (!skip) L->debug = 0;
        break;
      case 2:  /* endinput */
        if (!skip) {
          LS->current = EOZ;
          LS->iflevel = 0;  /* to allow $endinput inside a $if */
        }
        break;
      case 3:  /* end */
        if (LS->iflevel-- == 0)
          luaX_syntaxerror(LS, "unmatched $end", "$end");
        break;
      case 4:  /* ifnot */
        ifnot = 1;
        /* go through */
      case 5:  /* if */
        if (LS->iflevel == MAX_IFS-1)
          luaX_syntaxerror(LS, "too many nested $ifs", "$if");
        readname(LS, buff);
        LS->iflevel++;
        LS->ifstate[LS->iflevel].elsepart = 0;
        LS->ifstate[LS->iflevel].condition = checkcond(LS, buff) ? !ifnot : ifnot;
        LS->ifstate[LS->iflevel].skip = skip || !LS->ifstate[LS->iflevel].condition;
        break;
      case 6:  /* else */
        if (LS->ifstate[LS->iflevel].elsepart)
          luaX_syntaxerror(LS, "unmatched $else", "$else");
        LS->ifstate[LS->iflevel].elsepart = 1;
        LS->ifstate[LS->iflevel].skip = LS->ifstate[LS->iflevel-1].skip ||
                                      LS->ifstate[LS->iflevel].condition;
        break;
      default:
        luaX_syntaxerror(LS, "unknown pragma", buff);
    }
    skipspace(LS);
    if (LS->current == '\n')  /* pragma must end with a '\n' ... */
      inclinenumber(LS);
    else if (LS->current != EOZ)  /* or eof */
      luaX_syntaxerror(LS, "invalid pragma format", buff);
    ifskip(LS);
  }
}
예제 #3
0
void play()
{
    while (1) {
	Move.free = 1;
	Move.time = 0.0;
	Move.shldchg = 0;
	Move.newquad = 0;
	Move.resting = 0;
	skiptonl(0);
	const struct cvntab* r = getcodpar("\nCommand", Comtab);
	(*r->value)(r->value2);
	events(0);
	attack(0);
	checkcond();
    }
}
예제 #4
0
double
move(int ramflag, int course, double p_time, double speed)
{
	double			angle;
	double			x, y, dx, dy;
	int		ix, iy;
	double			bigger;
	int			n;
	int		i;
	double			dist;
	double			sectsize;
	double			xn;
	double			evtime;

	ix = iy = 0;
#ifdef xTRACE
	if (Trace)
		printf("move: ramflag %d course %d time %.2f speed %.2f\n",
			ramflag, course, p_time, speed);
#endif
	sectsize = NSECTS;
	/* initialize delta factors for move */
	angle = course * 0.0174532925;
	if (damaged(SINS))
		angle += Param.navigcrud[1] * (franf() - 0.5);
	else
		if (Ship.sinsbad)
			angle += Param.navigcrud[0] * (franf() - 0.5);
	dx = -cos(angle);
	dy = sin(angle);
	bigger = fabs(dx);
	dist = fabs(dy);
	if (dist > bigger)
		bigger = dist;
	dx /= bigger;
	dy /= bigger;

	/* check for long range tractor beams */
	/****  TEMPORARY CODE == DEBUGGING  ****/
	evtime = Now.eventptr[E_LRTB]->date - Now.date;
#ifdef xTRACE
	if (Trace)
		printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
			(void *)Now.eventptr[E_LRTB],
			Now.eventptr[E_LRTB]->evcode,
			Now.eventptr[E_LRTB]->date, evtime);
#endif
	if (p_time > evtime && Etc.nkling < 3) {
		/* then we got a LRTB */
		evtime += 0.005;
		p_time = evtime;
	} else
		evtime = -1.0e50;
	dist = p_time * speed;

	/* move within quadrant */
	Sect[Ship.sectx][Ship.secty] = EMPTY;
	x = Ship.sectx + 0.5;
	y = Ship.secty + 0.5;
	xn = NSECTS * dist * bigger;
	n = xn + 0.5;
#ifdef xTRACE
	if (Trace)
		printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
#endif
	Move.free = 0;

	for (i = 0; i < n; i++) {
		ix = (x += dx);
		iy = (y += dy);
#ifdef xTRACE
		if (Trace)
			printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y);
#endif
		if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) {
			/* enter new quadrant */
			dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn;
			dy = Ship.quady * NSECTS + Ship.secty + dy * xn;
			if (dx < 0.0)
				ix = -1;
			else
				ix = dx + 0.5;
			if (dy < 0.0)
				iy = -1;
			else
				iy = dy + 0.5;
#ifdef xTRACE
			if (Trace)
				printf("New quad: ix = %d, iy = %d\n", ix, iy);
#endif
			Ship.sectx = x;
			Ship.secty = y;
			compkldist(0);
			Move.newquad = 2;
			attack(0);
			checkcond();
			Ship.quadx = ix / NSECTS;
			Ship.quady = iy / NSECTS;
			Ship.sectx = ix % NSECTS;
			Ship.secty = iy % NSECTS;
			if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 ||
			    Ship.quady >= NQUADS) {
				if (!damaged(COMPUTER)) {
					dumpme(0);
				} else
					lose(L_NEGENB);
			}
			initquad(0);
			n = 0;
			break;
		}
		if (Sect[ix][iy] != EMPTY) {
			/* we just hit something */
			if (!damaged(COMPUTER) && ramflag <= 0) {
				ix = x - dx;
				iy = y - dy;
				printf("Computer reports navigation error; %s stopped at %d,%d\n",
					Ship.shipname, ix, iy);
				Ship.energy -= Param.stopengy * speed;
				break;
			}
			/* test for a black hole */
			if (Sect[ix][iy] == HOLE) {
				/* get dumped elsewhere in the galaxy */
				dumpme(1);
				initquad(0);
				n = 0;
				break;
			}
			ram(ix, iy);
			break;
		}
	}
	if (n > 0) {
		dx = Ship.sectx - ix;
		dy = Ship.secty - iy;
		dist = sqrt(dx * dx + dy * dy) / NSECTS;
		p_time = dist / speed;
		if (evtime > p_time)
			p_time = evtime;		/* spring the LRTB trap */
		Ship.sectx = ix;
		Ship.secty = iy;
	}
	Sect[Ship.sectx][Ship.secty] = Ship.ship;
	compkldist(0);
	return (p_time);
}