Esempio n. 1
0
/**
 * checks if the peasant can produce
 * produce the unit and returns 0 if succesful and 1 if not
 * checks if the peasant can produce
 */
static int produceUnit(int x1, int y1, int x2, int y2, enum unitType type) {
	// only on the neighbouring field
	if(!isNeighbour(x1, y1, x2, y2)) return 1;
	
	// is it inside the board
	if(!insideBoard(x1, y1, globalBoardSize)) return 1;
	if(!insideBoard(x2, y2, globalBoardSize)) return 1;
	
	// no unit or it is not a peasant on (x1, y1)
	UnitsList peasant = findUnit(x1, y1);
	if (peasant == NULL || peasant->type != PEASANT) return 1;
	
	// has the unit moved last two turns
	if (actualTurnNumber - peasant->lastMove < 3) return 1;
	
	UnitsList secondUnit = findUnit(x2, y2);
	
	// is there any other unit on (x2, y2)
	if(secondUnit != NULL) return 1;
	
	addUnit(x2, y2, type);
		
	// updates the last move of the peasant
	peasant->lastMove = actualTurnNumber;

	return 0;	
}
Esempio n. 2
0
/**
 * moves the unit and returns 0
 * returns 1 if not possible
 */
int move(int x1, int y1, int x2, int y2) {
	// moves only to the neighbouring
	if(!isNeighbour(x1, y1, x2, y2)) return 1;
	
	// inside board
	if(!insideBoard(x1, y1, globalBoardSize)) return 1;
	if(!insideBoard(x2, y2, globalBoardSize)) return 1;

	UnitsList unitFirst = findUnit(x1, y1);

	// first unit does not exist
	if (unitFirst == NULL) return 1;
	
	// has the unit moved already
	if (unitFirst->lastMove == actualTurnNumber) return 1;
	
	// does the player move his own unit
	if (unitFirst->player != actualPlayer) return 1;
	
	UnitsList unitSecond = findUnit(x2, y2);	
	
	// moving onto the own unit
	if(unitSecond != NULL && unitSecond->player == actualPlayer) return 1;

	// moving on the enemy unit or the empty field
	if (x1 <= 10 && y1 <= 10) {
		topleft[unitFirst->x][unitFirst->y] = '.';
	}
	unitFirst->x = x2;
	unitFirst->y = y2;
	unitFirst->lastMove = actualTurnNumber;
	
	// unit first is on the field for sure
	int winner = 1;
	
	// starts the fight if there is an enemy unit
	if (unitSecond != NULL) 
		winner = walka(unitFirst, unitSecond);
		
	if (x2 <= 10 && y2 <= 10) {
		if (winner == 0) topleft[x2][y2] = '.';
		else if (winner == 1)
			topleft[x2][y2] = mark(unitFirst->type, unitFirst->player);
		else 
			topleft[x2][y2] = mark(unitSecond->type, unitSecond->player);
	}
	
	return 0;
}
Esempio n. 3
0
QValueList<Problem> BackgroundParser::problems( const QString& fileName )
{
    Unit* u = 0;
    if( (u = findUnit(fileName)) == 0 ){
	m_fileList->remove( fileName );
	u = parseFile( fileName, false );
    }

    return u ? u->problems : QValueList<Problem>();
}
Esempio n. 4
0
RefJavaAST BackgroundParser::translationUnit( const QString& fileName )
{
    Unit* u = 0;
    if( (u = findUnit(fileName)) == 0 ){
	m_fileList->remove( fileName );
	u = parseFile( fileName, false );
    }

    return u->translationUnit;
}
Esempio n. 5
0
unit_t ProfilePlotView::unitForQuantity(quantity_t q) const
{
	QSettings s;
	s.beginGroup("Settings");
	QVariant uname = s.value(QString("Unit%1").arg(q));
	s.endGroup();

	try
	{
		if (! uname.isValid())
			return findUnit(q, 0);
		else
			return findUnit(q, (const char *)uname.toByteArray());
	}
	catch (std::runtime_error & e)
	{
	}

	return unit_t();
}
Esempio n. 6
0
ParsedFilePointer BackgroundParser::translationUnit( const QString& fileName )
{
	Unit * u = findUnit( fileName );
	if ( u == 0 )
	{
        return 0;
        /*m_fileList->remove
			( fileName );
        u = parseFile( fileName, false );*/
	}
	
	return u->translationUnit;
}
Esempio n. 7
0
QValueList<Problem> BackgroundParser::problems( const QString& fileName, bool readFromDisk, bool forceParse )
{
    Q_UNUSED(readFromDisk);
	Unit * u = findUnit( fileName );
	if ( u == 0 || forceParse )
	{
        /*   
		m_fileList->remove
			( fileName );
        u = parseFile( fileName, readFromDisk ); */
	}
	
	return u ? u->problems : QValueList<Problem>();
}
Esempio n. 8
0
void BackgroundParser::removeFile( const QString& fileName )
{
    QMutexLocker locker( &m_mutex );

    if( Unit* unit = findUnit(fileName) ){
        m_driver->remove( fileName );
        m_unitDict.remove( fileName );
        delete( unit );
	unit = 0;
    }

    if( m_fileList->isEmpty() )
        m_isEmpty.wakeAll();
}
Esempio n. 9
0
ULONG RBF_InterruptHandler(UBYTE * data, ULONG length, ULONG unitnum, APTR userdata)
{
  struct ParallelUnit * PU = NULL;
  ULONG index = 0;

  D(bug("!Received %d bytes on unit %d (%s)\n",length,unitnum,data));

  PU = findUnit(pubParallelBase, unitnum);
    
  if (NULL != PU)
  {
    if (0 != (PU->pu_Status & STATUS_READS_PENDING))
    {
      struct IOStdReq * ioreq;
      ioreq = (struct IOStdReq *)PU->pu_ActiveRead;

      if (NULL == ioreq)
      {
        ioreq = (struct IOStdReq *)GetMsg(&PU->pu_QReadCommandPort);
        PU->pu_ActiveRead = (struct Message *)ioreq;
        D(bug("Something is wrong!"));
      }
      
      while (NULL != ioreq)
      {
        /*
        ** Copy the remaining data into a request buffer.
        ** This loop woll possibly execute several times
        */
        UBYTE * destBuf;
        UWORD indexDestBuf;
        D(bug("Have a IORequest for Parallel device!\n"));
        
        destBuf = ioreq->io_Data;
        indexDestBuf = ioreq->io_Actual;
        /*
        ** I copy as many bytes as I can into this request
        */
        while (index < length)
        {
          destBuf[indexDestBuf] = data[index];
            
          index++;
          indexDestBuf++;

          D(bug("io_Length %d:  io_Actual: %d\n",ioreq->io_Length,indexDestBuf));

          if ((-1 == ioreq->io_Length && 0 == destBuf[indexDestBuf-1]) ||
              (indexDestBuf == ioreq->io_Length))
          {
            /*
            ** this request is done, I answer the message
            */
            ioreq->io_Actual = indexDestBuf;
            ReplyMsg((struct Message *)ioreq);
              
            /*
            ** Get the next request ...
            */
            ioreq = (struct IOStdReq *)GetMsg(&PU->pu_QReadCommandPort);
            PU->pu_ActiveRead = (struct Message *)ioreq;
            break;    
          }
        }
        
        if (index == length && NULL != ioreq)
        {
          ioreq->io_Actual = indexDestBuf;
          break;
        }
      }
      if (NULL == ioreq)
        PU->pu_Status &= ~STATUS_READS_PENDING;
      
    }
  } /* if (NULL != pu) */   
 
  /*
  ** Simply dropping the incoming data
  */
  
  return length;
}
Esempio n. 10
0
/*
 * The write buffer empty interrupt handler
 */
ULONG WBE_InterruptHandler( ULONG unitnum, APTR userdata)
{
	ULONG total = 0;
	struct ParallelUnit * PU;

	PU = findUnit(pubParallelBase, unitnum);

	if (NULL != PU) {
		/*
		 * First get any active write 
		 */
		struct IOExtPar * ioparreq = (struct IOExtPar *)PU->pu_ActiveWrite;
		
		while (1) {
			/*
			 * Try to transmit the active write request
			 */
			if (NULL != ioparreq) {
				ULONG writtenbytes;
				writtenbytes = HIDD_ParallelUnit_Write(PU->pu_Unit,
				                                      &((char *)ioparreq->IOPar.io_Data)[PU->pu_NextToWrite],
				                                      PU->pu_WriteLength);
				/*
				 * Check whether this was written completely.
				 */
				total += writtenbytes;
				if (writtenbytes >= PU->pu_WriteLength) {
					/* This one is done */
					ReplyMsg(&ioparreq->IOPar.io_Message);
				} else {
					/*
					 * Not completed, yet.
					 */
					PU->pu_WriteLength -= writtenbytes;
					PU->pu_NextToWrite += writtenbytes;
					/*
					 * Get out of the loop
					 */
					break;
				}
			}
			/* 
			 * Get the next request from the queue.
			 */
			ioparreq = (struct IOExtPar *)GetMsg(&PU->pu_QWriteCommandPort);
			PU->pu_ActiveWrite = (struct Message *)ioparreq;
			if (NULL == ioparreq) {
				/*
				 * No more request left. Done.
				 */
				PU->pu_Status &= ~STATUS_WRITES_PENDING;
				break;
			}
			
			/*
			 * There is a new request.
			 */
			PU->pu_NextToWrite = 0;
			if (-1 == ioparreq->IOPar.io_Length) {
				PU->pu_WriteLength = strlen(ioparreq->IOPar.io_Data);
			} else {
				PU->pu_WriteLength = ioparreq->IOPar.io_Length;
			}
			/*
			 * And repeat the loop with this request
			 */
		}
	}
	return total;
}
Esempio n. 11
0
// find the first unit of type belonging to player Id.
int cUnitUtils::findUnit(int type, int iPlayerId) {
	return findUnit(type, iPlayerId, -1);
}
Esempio n. 12
0
		void *memReAllocate(const sChar *file, const sU32 line, const allocType type, const sU32 size, void *addr)
		{
		  allocUnit *au;
		  sU32      hashIndex, oldSize, newRealSize;
		  void      *oldAddr, *newRealAddr;

		  FRASSERT(size<MAXALLOC);

		  if (!addr)
		    return memAllocate(file, line, type, size);

		  au=findUnit(addr);
		  if (!au)
		  {
				fr::debugOut("%s : trying to realloc nonallocated memory\n", formatOwner(file, line));
		    sourceFile="include_debug_h_everywhere_please.cpp";
		    sourceLine=303;
		    return 0;
		  }

		  if (type!=au->type)
				fr::debugOut("%s : allocation and reallocation types mismatch (%s vs %s)\n", formatOwner(file, line), atypes[au->type], atypes[type]);

		  oldSize=au->size;
		  oldAddr=au->addr;
		  newRealSize=calcRealSize(size);
		  newRealAddr=realloc(au->realAddr, newRealSize);

		  stats.curAlloc-=au->size;
		  stats.curRealAlloc-=au->realSize;

		  au->realSize=newRealSize;
		  au->realAddr=newRealAddr;
		  au->size=calcSize(newRealSize);
		  au->addr=calcAddr(newRealAddr);
		  au->type=type;
		  au->line=line;
		  if (file)
		    strncpy(au->file, file, 63);
		  else
		    strcpy(au->file, "???");

		  hashIndex=0xffffffff;
		  if (oldAddr!=au->addr)
		  {
		    hashIndex=((sU32) oldAddr>>4) & ALLOCHASHMASK;

		    if (allocHash[hashIndex]==au)
		      allocHash[hashIndex]=au->next;
		    else
		    {
		      if (au->prev) au->prev->next=au->next;
		      if (au->next) au->next->prev=au->prev;
		    }

		    hashIndex=((sU32) au->addr>>4) & ALLOCHASHMASK;
		    if (allocHash[hashIndex])
		      allocHash[hashIndex]->prev=au;

		    au->next=allocHash[hashIndex];
		    au->prev=0;
		    allocHash[hashIndex]=au;
		  }