//Received the money from another account
	void SavingAccount::TransferFrom(Account *accountFrom,	 	//Account sends
									 float	  amountTransfer,  	//Amount
									 Date	  transactionDate)	//Transaction Date
	{
		AddInterest(transactionDate);
		//Check whether the transaction is performed between 2 accounts or not
		if(GetAccountNumber() == accountFrom->GetAccountNumber())
		{
			cout << "Cannot perform the transaction! \n";
		}
		else
		{
			if(amountTransfer > accountFrom->GetAccountBalance())
			{
				cout << endl;
				cout << "*** TRANSFER FROM 2323 TO 1212 NOT ALLOWED! ***\n"
					 << "***        DUE TO INSUFFICIENT FUNDS        ***\n\n";
				accountFrom->SetAccountInfo(accountFrom->GetAccountBalance() - 20);
			}
			else
			{

				accountFrom->Withdraw(amountTransfer, transactionDate);
				Deposit(amountTransfer, transactionDate);
			}

			accountLastTransfer = accountFrom;
			lastTransaction		= "Transfer";
			amountLastTransaction = amountTransfer;
			dateLastTransaction  = transactionDate;
		}
	}
Example #2
0
 virtual void Travail ()
 { std::list<Protein> copy;
   { boost::mutex::scoped_lock lck (mutex);
     std::swap (copy, to_deposit);
   }
   for (Protein const& p : copy)
     Deposit (p, pool);
 }
void InventoryContainer::OnButtonEvent(std::string selection){
	if(selection == "Equip")
		Equip();
	else if(selection == "Drop")
		Drop();
	else if(selection == "Deposit")
		Deposit();
	else if(selection == "Barter")
		Barter();
};
 void Metabolize (const Protein &p)
 {   INFORM (p);
     INFORM ("image-request protein received, responding...");
     ImageData *tex = FetchImageData ("images/"
                                      + INT ((page++) % 6 + 1) + ".jpg");
     if (tex)
     {   Protein response = ProteinWithDescrip ("image-result");
         AppendIngest  (response, "image-texture", tex);
         Deposit (response, poolname);
     }
     else
         WARN ("Couldn't send response because we failed to load an image.");
 }
Example #5
0
Planet::Planet()
    : _segments(360)
{
    // Generate mountains
    for (int i = 0; i < 100; i++) {
        float height = random<float>(50.0f, 300.0f);
        float slope = random<float>(4.0f, 12.0f);
        float width = std::min(180.0f, height / slope);
        float longitude = random<float>(0.0, 360.0);
        for (size_t i = 0; i < width; i++) {
            float x = 0;
            if (i < width/2) {
                x = i * 2 / width;
            } else {
                x = (width - i) * 2 / width;
            }
            Segment& s = *_segments.locateLng(longitude + i);
            GeoPoint& ms = s.pts.back();
            ms.altitude += x * height;
        }
    }

    // Generate deposits
    std::unordered_set<Segment*> occupied;
    ui64 fails = 0;
    StratumId sid = 1;
    for (int i = 0; i < 50; ) {
        float lng = random<float>(0.0, 360.0);
        Segment& seg = *_segments.locateLng(lng);
        if (occupied.find(&seg) != occupied.end()) {
            if (++fails > 1000) {
                break;
            } else {
                continue;
            }
        } else {
            occupied.insert(&seg);
        }

        constexpr size_t ptsCount = 6;
        seg.split(ptsCount);

        Res res(i % 2 == 0? Res::Ore: Res::Oil);
        _deposits.push_back(Deposit());
        Deposit& dep = _deposits.back();
        dep.res = res;
        dep.resLeft = 2000;
        seg.deposits.push_back(&dep);

        if (res == Res::Ore) {
            for (size_t i = 0; i < ptsCount; i++) {
                float depth = 50;
                float z = sinf(M_PI * float(i) / (ptsCount - 1));
                GeoPoint& pt = seg.pts[i];
                pt.strata.push_back(Stratum());
                Stratum& st = pt.strata.back();
                st.id = sid;
                st.alt1 = pt.altitude - z * depth;
                st.alt2 = pt.altitude;
                st.col1 = st.col2 = gOreColor;
                st.deposit = &dep;
            }
        } if (res == Res::Oil) {
            for (size_t i = 0; i < ptsCount; i++) {
                float depth = 50;
                float altitude = std::min(seg.pts.back().altitude, seg.pts.front().altitude) - depth;
                float height = 30;
                float z = sinf(M_PI * float(i) / (ptsCount - 1));
                GeoPoint& pt = seg.pts[i];
                pt.strata.push_back(Stratum());
                Stratum& st = pt.strata.back();
                st.id = sid;
                st.alt1 = altitude - z * height/2;
                st.alt2 = altitude + z * height/2;
                st.col1 = st.col2 = gOilColor;
                st.deposit = &dep;
            }
        }

        i++;
        sid++;
    }
}
Example #6
0
void WorkersLoop(int startupflags)
{
  double theta;
  long daytime, newtinc;
  Entity et;
  Vector sunpos;
  VarDesc *v;
  int i, j, k;
  char varname[80];
  while (1)  {
    switch (GetCommand())  {
    case DO_TIME_STEP :
      if (plausible)  {
	daytime = ((int)(timeofday*3600.)+actime) % 86400;
	ActualiseValuesInTime(actime);	/* Actualise Border values */
	for (et = maxentity; et--; )
	  CalculateLayerAverage(g[et], pstat, avg+et*nz);
	SetAvgMountains();
	CalcMeanHydrostaticPressure();
	InterpolateToFaces();			/* Interpolate wind speeds from center to faces */
	InterpolateToCenter(-1., pressuretype == NONHYDROSTATIC);
	if (tstart == actime)  Continuity();
	CheckTimeStep(&tinc, &chemtinc, 0.8);
	if (pressuretype == NONHYDROSTATIC)
	  ApplyBuoyancy(tinc);			/* Calculate Buoyancy */
	if (pressuretype != NOPRESSURE)  {		/* Calc wind acceleration */
	  switch (pressuretype)  {			/* Calculate Pressure field */
	  case HYDROSTATIC    : CalcHydrostaticPressure(); break;
	  case NONHYDROSTATIC : SolveForPressure(tinc); break;
	  }
	  ApplyPressure(tinc);
	}
	Continuity();				/* Mass conservation */
	InterpolateToCenter(1., pressuretype == NONHYDROSTATIC);
	if (coriolistype != NOCORIOLIS)  ApplyCoriolis(tinc);
	if (filtertype != NO_FILTER)  {
	  SetBoundary(WWIND+1);   /* Set Boundary for Wind only */
	  switch (filtertype)  {
	  case PEPPER_FILTER :
	    for (i = nz; i--; )
	      for (et = HUMIDITY; et--; )
		ApplyFilter(g[et]+i*layer, pstat+i*layer, spatialfilter);
	    break;
	  case SHAPIRO_FILTER :
	    for (i = nz; i--; )
	      for (et = HUMIDITY; et--; )
		ShapiroFilter(g[et]+i*layer, pstat+i*layer, 3, spatialfilter);
	    break;
	  case DIFFUSION_FILTER :
	    for (i = nz; i--; )
	      for (et = HUMIDITY; et--; )
		ShapiroFilter(g[et]+i*layer, pstat+i*layer, 1, spatialfilter);
	    break;
	  }
	}
	SetBoundary(WWIND+1);
	CheckTimeStep(&newtinc, &chemtinc, 1.);
	if (newtinc < tinc)  {
	  tinc = newtinc;
	}
	chemtinc = (chemtime <= actime ? chemtinc : 0);
	if (advection || windadvection)
	  switch (advectiontype)  {
	  case MPDATA_A : Advect(tinc, chemtinc); break;
	  case PPM_A    : PPM_Transport(tinc, chemtinc, smiord); break;
	  }
	if (dampinglayer)  DampTop();
	if (groundinterface || shortwaveradiation)  {
	  GroundInterface(timeofday + (double)actime / 3600., dayofyear, tinc, &sunpos);
	  sunelevation = (sunpos.z > 0. ? 57.29578 * asin(sunpos.z) : 0.);
	}
	if (cloudwater)  CloudPhysics();
	if (turbtype == TTTT)  {
	  if (groundinterface)
	    CalcGroundTurbulence(tinc);
	  CalcTransilientTurbulence(tinc);
	}
	else if (turbtype == KEPS_T)  {
	  CalcKEpsilon(tinc);
	  if (groundinterface)
	    CalcGroundTurbulence(tinc);
	  CalcKTurb(tinc, chemtinc);
	}
	Emit(tinc);
	Deposit(tinc);
	if (!(radiationtype && shortwaveradiation) &&
	    // When using the two-stream module, ChemicalTimeStep
	    // mus be called from within ShortWaveRadiation!
	    nsubs && actime % tchem == 0)  ChemicalTimeStep(tchem, &sunpos);
	SetBoundary(chemtinc ? maxentity : SUBS);
    
	// Call ModuleManager
	McInterface::modmanager.DoCalc(actime+tinc);

	actime += tinc; chemtime += chemtinc;
	if (dumpnow || (dumptime && (actime % dumptime == 0)))  {
	  MakeAFullDump();
	  dumpnow = 0;
	}
      }  /* if (plausible) */
      SendStatus(plausible);
      break;
    case SENDGRIDVAL :
      pvm_upkint((int *)&et, 1, 1);
      pvm_upkint(&i, 1, 1);
      pvm_upkint(&j, 1, 1);
      pvm_upkint(&k, 1, 1);
      pvm_initsend(PvmDataRaw);
      pvm_pkdouble(g[et]+i*row+j+k*layer, 1, 1);
      pvm_send(myparent, VALUES);
      break;
    case SENDMESHVAL :
      pvm_upkstr(varname);
      v = GetNamedVar(varname);
      pvm_upkint(&i, 1, 1);
      pvm_upkint(&j, 1, 1);
      pvm_upkint(&k, 1, 1);
      pvm_initsend(PvmDataRaw);
      if (v->storetype == PROC_VAL)  {
	theta = v->v.proc(k, i, j, v);
	pvm_pkdouble(&theta, 1, 1);
      }
      else
	pvm_pkdouble(GetNamedVar(varname)->v.d+i*row+j+k*layer, 1, 1);
      pvm_send(myparent, VALUES);
      break;
    case SENDGRID :
      pvm_upkint((int *)&et, 1, 1);
      SendMeshToMaster(g[et], 0, ALL_DIM);
      break;
    case SENDMESH :
      pvm_upkstr(varname);
      v = GetNamedVar(varname);
      if (v->storetype == PROC_VAL)  {
	for (k = nz; k--; )
	  for (i = nx+1; i--; )
	    for (j = ny+1; j--; )
	      flux[0][i*row+j+k*layer] = v->v.proc(k, i, j, v);
	SendMeshToMaster(flux[0], 0, v->dims);
	memset(flux[0], 0, mesh * sizeof(double));
      }
      else
	SendMeshToMaster(v->v.d, 0, v->dims);
      break;
    case SENDGROUND :
      SendGroundToMaster();
      break;
    case EXIT :
      pvm_exit();
      exit (0);
    }
  }
}
Example #7
0
void SequentialLoop(int startupflags)
{
  int i;
  double theta;
  long daytime, newtinc;
  Entity et;
  Vector sunpos;
  while (plausible && actime < tend)  {
    daytime = ((int)(timeofday*3600.)+actime) % 86400;
    printf("Now at %li seconds = %02li:%02li:%02li  ",
           actime, daytime / 3600,
           (daytime % 3600)/60,
           daytime % 60);
    ActualiseValuesInTime(actime);	/* Actualise Border values */
    for (et = maxentity; et--; )
      CalculateLayerAverage(g[et], pstat, avg+et*nz);
    SetAvgMountains();
    CalcMeanHydrostaticPressure();
    InterpolateToFaces();			/* Interpolate wind speeds from center to faces */
    InterpolateToCenter(-1., pressuretype == NONHYDROSTATIC);
    if (tstart == actime)  Continuity();
    CheckTimeStep(&tinc, &chemtinc, 0.8);
    if (pressuretype == NONHYDROSTATIC)
      ApplyBuoyancy(tinc);			/* Calculate Buoyancy */
    if (pressuretype != NOPRESSURE)  {		/* Calc wind acceleration */
      switch (pressuretype)  {			/* Calculate Pressure field */
         case HYDROSTATIC    : CalcHydrostaticPressure(); break;
         case NONHYDROSTATIC : SolveForPressure(tinc); break;
      }
      ApplyPressure(tinc);
    }
    Continuity();				/* Mass conservation */
    InterpolateToCenter(1., pressuretype == NONHYDROSTATIC);
    if (coriolistype != NOCORIOLIS)  ApplyCoriolis(tinc);
    if (filtertype != NO_FILTER)  {
      SetBoundary(WWIND+1);
      switch (filtertype)  {
        case PEPPER_FILTER :
           for (i = nz; i--; )
             for (et = HUMIDITY; et--; )
               ApplyFilter(g[et]+i*layer, pstat+i*layer, spatialfilter);
           break;
        case SHAPIRO_FILTER :
           for (i = nz; i--; )  {
             for (et = HUMIDITY; et--; )
               ShapiroFilter(g[et]+i*layer, pstat+i*layer, 3, spatialfilter);
/*             if (turbtype == KEPS_T)  {
               ShapiroFilter(g[TKE]+i*layer, pstat+i*layer, 3, spatialfilter);
               ShapiroFilter(g[EPS]+i*layer, pstat+i*layer, 3, spatialfilter);
             } */
           }
           break;
        case DIFFUSION_FILTER :
           for (i = nz; i--; )
             for (et = HUMIDITY; et--; )
               ShapiroFilter(g[et]+i*layer, pstat+i*layer, 1, spatialfilter);
           break;
      }
    }
    SetBoundary(WWIND+1);
    CheckTimeStep(&newtinc, &chemtinc, 1.);
    if (newtinc < tinc)  {
      fprintf(stderr, "Warning: Time step had to be changed in the middle of iteration\n");
      tinc = newtinc;
    }
    chemtinc = (chemtime <= actime ? chemtinc : 0);
    if (nsubs)  printf("chemtinc = %3ld  ", chemtinc);
    if (advection || windadvection)
      switch (advectiontype)  {
        case MPDATA_A : Advect(tinc, chemtinc); break;
        case PPM_A    : PPM_Transport(tinc, chemtinc, smiord); break;
      }
    if (dampinglayer)  DampTop();
    if (groundinterface || shortwaveradiation)  {
      GroundInterface(timeofday + (double)actime / 3600., dayofyear,
		      tinc, &sunpos);
      sunelevation = (sunpos.z > 0. ? 57.29578 * asin(sunpos.z) : 0.);
    }
    if (cloudwater)  CloudPhysics();
    if (turbtype == TTTT)  {
      if (groundinterface)
        CalcGroundTurbulence(tinc);
      CalcTransilientTurbulence(tinc);
    }
    else if (turbtype == KEPS_T)  {
      CalcKEpsilon(tinc);
      if (groundinterface)
        CalcGroundTurbulence(tinc);
      CalcKTurb(tinc, chemtinc);
    }
    Emit(tinc);
    Deposit(tinc);
    if (!(radiationtype && shortwaveradiation) &&
	// When using the two-stream module, ChemicalTimeStep
	// must be called from within ShortWaveRadiation!
	nsubs && actime % tchem == 0)  ChemicalTimeStep(tchem, &sunpos);
    SetBoundary(chemtinc ? maxentity : SUBS);
    
    // Call ModuleManager
    McInterface::modmanager.DoCalc(actime+tinc);
/*    TestChemicals("Boundary");  */
    actime += tinc; chemtime += chemtinc;
    if (!(startupflags & NO_OUTPUT))  {
      WriteOutData(actime, FALSE);
      WriteToDomainFiles(actime);
    }
    if (dumpnow || (dumptime && (actime % dumptime == 0)))  {
      MakeAFullDump();
      dumpnow = 0;
    }
    if (mailtime)  {
      mailtime = 0;
      MailTheTime();
    }
    printf("Energy = %lf\n", CalcTopEnergy());
  }
}