Exemple #1
0
bool C4MaterialMap::mrfPoof(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
{
	if (pReaction->fUserDefined) if (!mrfUserCheck(pReaction, iX, iY, iLSPosX, iLSPosY, fXDir, fYDir, iPxsMat, iLsMat, evEvent, pfPosChanged)) return false;
	switch (evEvent)
	{
	case meeMassMove: // MassMover-movement
	case meePXSPos: // PXS check before movement: Kill both landscape and PXS mat
		::Landscape.ExtractMaterial(iLSPosX,iLSPosY,false);
		if (!Random(3)) Smoke(iX,iY,3);
		if (!Random(3)) StartSoundEffectAt("Liquids::Pshshsh", iX, iY);
		return true;

	case meePXSMove: // PXS movement
		// incindiary/extinguisher/corrosives are always same density proc; so do insertion check first
		if (!pReaction->fUserDefined)
			if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged))
				// either splash or slide prevented interaction
				return false;
		// Always kill both landscape and PXS mat
		::Landscape.ExtractMaterial(iLSPosX,iLSPosY,false);
		if (!Random(3)) Smoke(iX,iY,3);
		if (!Random(3)) StartSoundEffectAt("Liquids::Pshshsh", iX, iY);
		return true;
	}
	// not handled
	return false;
}
protected func SmokeTrail() {
  Smoke(0, 0, 2);
  Smoke(0, -5, Random(3));
  var i = Random(20);
  while (i--) {
    var c = (20+Random(41))/2;
    CreateParticle("PxSpark", Random(11)-5, Random(11)-5, 0, 0, c,
      RGBa(255, Random(100), c*4, 128));
  }
  CreateParticle("PxSpark", 0, 0, 0, 0, 20,
    RGBa(255, 155, 0, 128));
  //Bitte hier Schaden für Wipfe setzen
  //*99/100 = Grenzwertig stark, *98/100=Meistens 0 Schaden
  SetYDir(GetYDir(this, 1000)*982/1000, this, 1000);
}
Exemple #3
0
bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged)
{
	// always manipulating pos/speed here
	if (pfPosChanged) *pfPosChanged = true;

	// Move up by up to 3px to account for moving SolidMasks, other material insertions, etc.
	int32_t mdens = std::min(::MaterialMap.Map[iPxsMat].Density, C4M_Solid);
	int32_t max_upwards = 3;
	bool was_pushed_upwards = false;
	while (max_upwards-- && (::Landscape.GetDensity(iX, iY) >= mdens))
	{
		--iY;
		was_pushed_upwards = true;
	}

	// Rough contact? May splash
	if (fYDir > itofix(1))
		if (::MaterialMap.Map[iPxsMat].SplashRate && !Random(::MaterialMap.Map[iPxsMat].SplashRate))
		{
			fYDir = -fYDir/8;
			fXDir = fXDir/8 + C4REAL100(Random(200) - 100);
			if (fYDir) return false;
		}

	// Contact: Stop
	fYDir = -GravAccel;

	// Incendiary mats smoke on contact even before doing their slide
	if (::MaterialMap.Map[iPxsMat].Incendiary)
		if (!Random(25))
		{
			Smoke(iX, iY, 4 + Random(3));
		}

	// Move by mat path/slide
	int32_t iSlideX = iX, iSlideY = iY;
	
	if (::Landscape.FindMatSlide(iSlideX,iSlideY,Sign(GravAccel),mdens,::MaterialMap.Map[iPxsMat].MaxSlide))
	{
		// Sliding on equal material: Move directly to optimize insertion of rain onto lakes
		// Also move directly when shifted upwards to ensure movement on permamently moving SolidMask
		if (iPxsMat == iLsMat || was_pushed_upwards)
			{ iX = iSlideX; iY = iSlideY; fXDir = 0; return false; }
		// Otherwise, just move using xdir/ydir for nice visuals when rain is moving over landscape
		// Accelerate into the direction
		fXDir = (fXDir * 10 + Sign(iSlideX - iX)) / 11 + C4REAL10(Random(5)-2);
		// Slide target in range? Move there directly.
		if (Abs(iX - iSlideX) <= Abs(fixtoi(fXDir)))
		{
			iX = iSlideX;
			iY = iSlideY;
			if (fYDir <= 0) fXDir = 0;
		}
		// Continue existance
		return false;
	}
	// insertion OK
	return true;
}
Exemple #4
0
bool C4MaterialMap::mrfCorrode(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
{
	if (pReaction->fUserDefined) if (!mrfUserCheck(pReaction, iX, iY, iLSPosX, iLSPosY, fXDir, fYDir, iPxsMat, iLsMat, evEvent, pfPosChanged)) return false;
	switch (evEvent)
	{
	case meePXSPos: // PXS check before movement
		// No corrosion - it would make acid incredibly effective
		break;
	case meeMassMove: // MassMover-movement
	{
		// evaluate corrosion percentage
		bool fDoCorrode; int d100 = Random(100);
		if (pReaction->fUserDefined)
			fDoCorrode = (d100 < pReaction->iCorrosionRate);
		else
			fDoCorrode = (d100 < ::MaterialMap.Map[iPxsMat].Corrosive) && (d100 < ::MaterialMap.Map[iLsMat].Corrode);
		if (fDoCorrode)
		{
			ClearBackPix(iLSPosX,iLSPosY);
			//::Landscape.CheckInstabilityRange(iLSPosX,iLSPosY); - more correct, but makes acid too effective as well
			if (!Random(5))
			{
				Smoke(iX, iY, 3 + Random(3));
			}
			if (!Random(20)) StartSoundEffectAt("Liquids::Corrode", iX, iY);
			return true;
		}
	}
	break;

	case meePXSMove: // PXS movement
	{
		// corrodes to corrosives are always same density proc; so do insertion check first
		if (!pReaction->fUserDefined)
			if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged))
				// either splash or slide prevented interaction
				return false;
		// evaluate corrosion percentage
		bool fDoCorrode; int d100 = Random(100);
		if (pReaction->fUserDefined)
			fDoCorrode = (d100 < pReaction->iCorrosionRate);
		else
			fDoCorrode = (d100 < ::MaterialMap.Map[iPxsMat].Corrosive) && (d100 < ::MaterialMap.Map[iLsMat].Corrode);
		if (fDoCorrode)
		{
			ClearBackPix(iLSPosX,iLSPosY);
			::Landscape.CheckInstabilityRange(iLSPosX,iLSPosY);
			if (!Random(5))
			{
				Smoke(iX,iY,3+Random(3));
			}
			if (!Random(20)) StartSoundEffectAt("Liquids::Corrode", iX, iY);
			return true;
		}
		// Else: dead. Insert material here
		::Landscape.InsertMaterial(iPxsMat,&iX,&iY);
		return true;
	}
	}
	// not handled
	return false;
}
Exemple #5
0
func Rauch(int iLevel)
{
	Lev = iLevel;
	//if(!Lev) return();
	Smoke(RandomX(-iLevel,iLevel),RandomX(-iLevel,iLevel),RandomX(20,50));
}
Exemple #6
0
int main (){
	// Count variable, processes, and endTime. Initialise random number generator
	int i;
	pid_t pid, pid1, pid2;
	time_t endTime;
	srand(time(NULL));
	
	// Iniatilise semaphore and open processes
	sem_init(&mutx, 0, 1);
	fd = shm_open("/region", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
	agents = mmap(NULL, sizeof(buffers), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

	for(i = 0; i < BUFFER_SIZE; i++)
	{
		agents->paper_buffer[i] = 1;
		agents->tobac_buffer[i] = 1;
		agents->match_buffer[i] = 1;
	}
	agents->paper_in = 0;
	agents->tobac_in = 0;
	agents->match_in = 0;
	agents->paper_out = 0;
	agents->tobac_out = 0;
	agents->match_out = 0;
	agents->paper_total = 0;
	agents->tobac_total = 0;
	agents->match_total = 0;
	agents->paper_status = 0;
	agents->tobac_status = 0;
	agents->match_status = 0;

	// Fork processes from parent
	pid = fork();
	if( pid > 0 ) {
		pid1 = fork();
		if( pid1 > 0 ) {
			// Paper Process
			Smoke(0);
			exit(0);
		}
		else if( pid1 == 0 ){
			// Tobacco Process
			Smoke(1);
			exit(0);
		} 
		else{
			printf("ERROR") ;
			exit(1);
		}
		wait(NULL);
	}
	else if( pid == 0 ){
		pid2 = fork();
		if( pid2 > 0 ) {
			// Matches Process
			Smoke(2);
			exit(0);
		}
		else if( pid2 == 0 ){
			// Agent Process
			int count = 0;
			endTime = time(NULL) + 25; 
			do 
			{
				AgentDisplay();
				if(count == 1) {
					Agent();
				}
				count = ( count + 1 ) % 3;
				sleep(1);
			} while(endTime > time(NULL));
			sem_wait(&mutx);
			
			// Switch to exit mode(-1) on the buffer
			for(i = 0; i < BUFFER_SIZE; i++)
			{
				agents->paper_buffer[i] = -1;
				agents->tobac_buffer[i] = -1;
				agents->match_buffer[i] = -1;
			}
			sem_post(&mutx);

			endTime = time(NULL) + 5; 
			do 
			{
				AgentDisplay();
				sleep(1);
			} while(endTime > time(NULL));
			exit(1);
		} 
		else{
			printf("ERROR") ;
			exit(1);
		}
		wait(NULL);  
		return;
	} 
	else{
		printf("ERROR") ;
		exit(1);
	} 
	return 0;
}
Exemple #7
0
protected func FlyProcess() {
	Smoke(0, 0, 7 + Random(5));
	if (Stuck() || (GetActTime() > 150))
		return(Hit());
}