Esempio n. 1
0
int main(int argc, string argv[])
{
  string prog, coords, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL, bp;
  int nbody;
  real tnow;
  vector cmpos, cmvel, cmacc;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  coords = getparam("coords");
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE, NULL)) {
    if (scanopt(coords, PosTag) && set_member(itags, PosTag)) {
      snapcmpos(cmpos, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Pos(bp), Pos(bp), cmpos);
      }
      eprintf("[%s: centroid position: %f,%f,%f]\n", getprog(),
	      cmpos[0], cmpos[1], cmpos[2]);
    }
    if (scanopt(coords, VelTag) && set_member(itags, VelTag)) {
      snapcmvel(cmvel, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Vel(bp), Vel(bp), cmvel);
      }
      eprintf("[%s: centroid velocity: %f,%f,%f]\n", getprog(),
	      cmvel[0], cmvel[1], cmvel[2]);
    }
    if (scanopt(coords, AccTag) && set_member(itags, AccTag)) {
      snapcmacc(cmacc, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Acc(bp), Acc(bp), cmacc);
      }
      eprintf("[%s: cen. acceleration: %f,%f,%f]\n", getprog(),
	      cmacc[0], cmacc[1], cmacc[2]);
    }
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getprog(), prog);
  return (0);
}
Esempio n. 2
0
local void hqmforces(bodyptr btab, int nbody, real M, real a, real b,
		     real tol)
{
  bodyptr bp;
  double r, mr3i, params[4], phi0, aR0, az0, abserr[3];
  static gsl_integration_workspace *wksp = NULL;
  gsl_function FPhi, F_aR, F_az;
  static double maxerr = 0.0;
  int stat[3];

  if (a == b) {					// spherical case is easy!
    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
      r = absv(Pos(bp));
      Phi(bp) = - M / (a + r);
      mr3i = M * rsqr(r / (a + r)) / rqbe(r);
      MULVS(Acc(bp), Pos(bp), - mr3i);
    }
  } else {					// flattened case is harder
    if (wksp == NULL) {				// on first call, initialze
      wksp = gsl_integration_workspace_alloc(1000);
      gsl_set_error_handler_off();		// handle errors below
    }
    FPhi.function = &intPhi;
    F_aR.function = &int_aR;
    F_az.function = &int_az;
    FPhi.params = F_aR.params = F_az.params = params;
    a2(params) = rsqr(a);
    b2(params) = rsqr(b);
    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
      R(params) = rsqrt(rsqr(Pos(bp)[0]) + rsqr(Pos(bp)[1]));
      z(params) = Pos(bp)[2];
      stat[0] = gsl_integration_qagiu(&FPhi, 0.0, tol, 0.0,
				      1000, wksp, &phi0, &abserr[0]);
      stat[1] = gsl_integration_qagiu(&F_aR, 0.0, tol, 0.0,
				      1000, wksp, &aR0, &abserr[1]);
      stat[2] = gsl_integration_qagiu(&F_az, 0.0, tol, 0.0,
				      1000, wksp, &az0, &abserr[2]);
      if (stat[0] || stat[1] || stat[2])	// any errors reported?
	for (int i = 0; i < 3; i++)
	  if (stat[i] != 0 && abserr[i] > maxerr) {
	    eprintf("[%s.hqmforces: warning: %s  abserr[%d] = %g]\n",
		    getprog(), gsl_strerror(stat[i]), i+1, abserr[i]);
	    maxerr = abserr[i];			// adjust reporting threshold
	  }
      Phi(bp) = - M * phi0;
      Acc(bp)[0] = - M * (Pos(bp)[0] / R(params)) * aR0;
      Acc(bp)[1] = - M * (Pos(bp)[1] / R(params)) * aR0;
      Acc(bp)[2] = - M * az0;
    }
  }
}
Esempio n. 3
0
void snaprect(bodyptr btab, int nbody)
{
  matrix qmat, tmpm;
  bodyptr bp;
  vector frame[3], tmpv;
  static vector oldframe[3] =
    { { 1.0, 0.0, 0.0, }, { 0.0, 1.0, 0.0, }, { 0.0, 0.0, 1.0, }, };
  int i;

  snapcenter(btab, nbody, WeightField.offset);
  CLRM(qmat);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    OUTVP(tmpm, Pos(bp), Pos(bp));
    MULMS(tmpm, tmpm, Weight(bp));
    ADDM(qmat, qmat, tmpm);
  }
  eigenvect(frame[0], frame[1], frame[2], qmat);
  if (dotvp(oldframe[0], frame[0]) < 0.0)
    MULVS(frame[0], frame[0], -1.0);
  if (dotvp(oldframe[2], frame[2]) < 0.0)
    MULVS(frame[2], frame[2], -1.0);
  CROSSVP(frame[1], frame[2], frame[0]);
  printvect("e_x:", frame[0]);
  printvect("e_y:", frame[1]);
  printvect("e_z:", frame[2]);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    if (PosField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Pos(bp), frame[i]);
      SETV(Pos(bp), tmpv);
    }
    if (VelField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Vel(bp), frame[i]);
      SETV(Vel(bp), tmpv);
    }
    if (AccField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(Acc(bp), frame[i]);
      SETV(Acc(bp), tmpv);
    }
    if (AuxVecField.offset != BadOffset) {
      for (i = 0; i < NDIM; i++)
	tmpv[i] = dotvp(AuxVec(bp), frame[i]);
      SETV(AuxVec(bp), tmpv);
    }
  }
  for (i = 0; i < NDIM; i++)
    SETV(oldframe[i], frame[i]);
}    
Esempio n. 4
0
void rotate(snapshot *snap, string *tags, string *vecs, char axis,
	    real thetax, real thetay, real thetaz)
{
  matrix rmat;
  bodyptr bp;

  switch (tolower(axis)) {
    case 'x':
      xmatrix(rmat, thetax);
      break;
    case 'y':
      ymatrix(rmat, thetay);
      break;
    case 'z':
      zmatrix(rmat, thetaz);
      break;
    default:
      error("%s: unknown axis %c\n", getargv0(), axis);
  }
  if (set_member(tags, PosTag) && set_member(vecs, PosTag))
    for_all_bodies(bp, *snap)
      rotatevec(Pos(bp), rmat);
  if (set_member(tags, VelTag) && set_member(vecs, VelTag))
    for_all_bodies(bp, *snap)
      rotatevec(Vel(bp), rmat);
  if (set_member(tags, AccTag) && set_member(vecs, AccTag))
    for_all_bodies(bp, *snap)
      rotatevec(Acc(bp), rmat);
  if (set_member(tags, AuxVecTag) && set_member(vecs, AuxVecTag))
    for_all_bodies(bp, *snap)
      rotatevec(AuxVec(bp), rmat);
}
Esempio n. 5
0
nemo_main()
{
    stream instr, quadstr, outstr;
    Body *btab = NULL, *bp;
    int nbody, bits;
    real eps_r, eps_t, tsnap = 0.0;

    if (!hasvalue("out"))
        warning("No output supplied (out=)");

    quadstr = stropen(getparam("quad"), "r");
    get_history(quadstr);
    instr = stropen(getparam("in"), "r");
    get_history(instr);
    get_quadfield(quadstr, &eps_r, &eps_t);
    get_snap(instr, &btab, &nbody, &tsnap, &bits);
    if (bits & PhaseSpaceBit == 0)
	error("not enuf info: bits = %o", bits);
    for (bp = btab; bp < btab+nbody; bp++) {
	CLRV(Acc(bp));
	Phi(bp) = 0.0;
    }
    quadinter(btab, nbody, eps_r, eps_t);
    if (hasvalue("out")) {
	outstr = stropen(getparam("out"), "w");
	put_history(outstr);
	bits = bits | PotentialBit | AccelerationBit;
	put_snap(outstr, &btab, &nbody, &tsnap, &bits);
    }
}
Esempio n. 6
0
local void sumforces(bodyptr btab, int nbody, bodyptr gtab, int ngrav,
		     real eps2)
{
  bodyptr bp, gp;
  double phi0, acc0[NDIM];
  vector pos0, dr;
  real dr2, dr2i, dr1i, mdr1i, mdr3i;

  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    phi0 = 0.0;
    CLRV(acc0);
    SETV(pos0, Pos(bp));
    for (gp = gtab; gp < NthBody(gtab, ngrav); gp = NextBody(gp)) {
      DOTPSUBV(dr2, dr, Pos(gp), pos0);
      dr2i = ((real) 1.0) / (dr2 + eps2);
      dr1i = rsqrt(dr2i);
      mdr1i = Mass(gp) * dr1i;
      mdr3i = mdr1i * dr2i;
      phi0 -= mdr1i;
      ADDMULVS(acc0, dr, mdr3i);
    }
    Phi(bp) = phi0;
    SETV(Acc(bp), acc0);
  }
}
Esempio n. 7
0
local void stepsystem(void) {
  bodyptr p1, p2, p;

  p1 = bodytab + MAX(nstatic, 0);		// set dynamic body range
  p2 = bodytab + nbody + MIN(nstatic, 0);
  for (p = p1; p < p2; p++) {			// loop over body range	
    ADDMULVS(Vel(p), Acc(p), 0.5 * dtime);	// advance v by 1/2 step
    ADDMULVS(Pos(p), Vel(p), dtime);		// advance r by 1 step
  }
  treeforce();
  for (p = p1; p < p2; p++) {			// loop over body range	
    ADDMULVS(Vel(p), Acc(p), 0.5 * dtime);	// advance v by 1/2 step
  }
  nstep++;					// count another time step
  tnow = tnow + dtime;				// finally, advance time
}
Esempio n. 8
0
local void sum1force(bodyptr btab, int nbody, int i0, real eps2)
{
    bodyptr bp0, bp;
    double phi0, acc0[NDIM];
    vector pos0, dr;
    real dr2, drab, mri, mr3i;
    int j;

    bp0 = NthBody(btab, i0);
    phi0 = 0.0;
    CLRV(acc0);
    SETV(pos0, Pos(bp0));
    for (j = 0; j < nbody; j++)
	if (j != i0) {
	    bp = NthBody(btab, j);
	    DOTPSUBV(dr2, dr, Pos(bp), pos0);
	    dr2 += eps2;
	    drab = rsqrt(dr2);
	    mri = Mass(bp) / drab;
	    phi0 -= mri;
	    mr3i = mri / dr2;
	    ADDMULVS(acc0, dr, mr3i);
	}
    Phi(bp0) = phi0;
    SETV(Acc(bp0), acc0);
}
Esempio n. 9
0
EXTERN_ENV
#define global extern

#include "stdinc.h"

/*
 * HACKGRAV: evaluate grav field at a given particle.
 */

void hackgrav(bodyptr p, long ProcessId)
{
   Local[ProcessId].pskip = p;
   SETV(Local[ProcessId].pos0, Pos(p));
   Local[ProcessId].phi0 = 0.0;
   CLRV(Local[ProcessId].acc0);
   Local[ProcessId].myn2bterm = 0;
   Local[ProcessId].mynbcterm = 0;
   Local[ProcessId].skipself = FALSE;
   hackwalk(ProcessId);
   Phi(p) = Local[ProcessId].phi0;
   SETV(Acc(p), Local[ProcessId].acc0);
#ifdef QUADPOLE
   Cost(p) = Local[ProcessId].myn2bterm + NDIM * Local[ProcessId].mynbcterm;
#else
   Cost(p) = Local[ProcessId].myn2bterm + Local[ProcessId].mynbcterm;
#endif
}
int main()
{
    Acc a(1);
    a(5);
    Acc(3);
    std::cout << a(2.3f);
    return 0;
}
Esempio n. 11
0
void nemo_main()
{
    stream instr, outstr;
    string times, ctypei, ctypeo;
    real   tsnap;
    int i, nbody, bits, mode;
    Body *btab = NULL, *bp;
    proc transform, trans2;

    times = getparam("times");
    ctypei = getparam("ctypei");
    ctypeo = getparam("ctypeo");
    if (streq(ctypei,"cart") && streq(ctypeo,"sph"))
        transform = cartesian_spherical;
    else if (streq(ctypei,"sph") && streq(ctypeo,"cart"))
        transform = spherical_cartesian;
    else if (streq(ctypei,"cart") && streq(ctypeo,"cyl"))
        transform = cartesian_cylindrical;
    else if (streq(ctypei,"cyl") && streq(ctypeo,"cart"))
        transform = cylindrical_cartesian;
    else
        error("Unimplemented ctype i/o : %s -> %s",ctypei,ctypeo);
    dprintf(0,"converting from %s to %s\n",ctypei,ctypeo);
    
    instr = stropen(getparam("in"), "r");   
    outstr = stropen(getparam("out"), "w");

    get_history(instr);
    put_history(outstr);		
    for (;;) {
    	get_history(instr);		/* skip over stuff we can forget */
        if (!get_tag_ok(instr, SnapShotTag))
		break;			/* done with work in loop */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) {
	    continue;       /* just skip it's probably a diagnostics */
        }

        if ((bits & TimeBit) == 0)
	    tsnap = 0.0;
        else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ))
            continue;
        dprintf (1,"Transforming snapshot at time= %f bits=0x%x\n",tsnap,bits);
#if 0
        Qmass  = MassBit & bits;       
        Qphase = PhaseSpaceBit & bits;
        Qacc   = AccelerationBit & bits;
        Qaux   = AuxBit & bits;
        Qkey   = KeyBit & bits;
#endif

        for (bp = btab; bp < btab+nbody; bp++) {
            (transform)(Pos(bp),Vel(bp),Acc(bp));
        }
        put_snap(outstr, &btab, &nbody, &tsnap, &bits);
    }
}
Esempio n. 12
0
void PCommands::doCmdkick()
{
    bool SyntaxError = false;
    if(ArgC < 1)
    {
        SyntaxError = true;
    }

    if(SyntaxError == true)
    {
        Chat->send(source, CHAT_DIRECT, "Usage", "@kick <charID or nickname>");
        return;
    }

    if(IsArgNumeric(1) == true)
    {
        target = GetClientByID(GetArgInt(1));
    }
    else
    {
        char tmp_destNick[50];
        GetArgText(1, tmp_destNick, 50);
        target = GetClientByNick(tmp_destNick);
    }

    if(target == NULL) // If victim isnt found, return error
    {
        Chat->send(source, CHAT_DIRECT, "System", "No such player");
        return;
    }

    // Make sure only people with a higher level than victim can kick victim
    if(source->GetAccountLevel() <= target->GetAccountLevel())
    {
        char tmpMsg[200];
        snprintf(tmpMsg, 199, "Cant kick %s, target level is higher or equal to yours!", Chars->GetChar(target->GetCharID())->GetName().c_str());
        tmpMsg[199] = '\0';
        Chat->send(source, CHAT_DIRECT, "System", tmpMsg);
        return;
    }

// *************** Checks done, proceed with command
    int final_bantime = std::time(NULL) + 60;               // Ban 60 seconds (Anti-Rejoin)
    PAccount Acc(target->GetAccountID());
    Acc.SetBannedUntilTime(final_bantime);
    Acc.Save();

    target->InitCharVanish();
    GameServer->ClientDisconnected(target);                 // Kick

    Console->Print("%s %s (Lv %d) kicked %s (Lv %d)", Console->ColorText(YELLOW, BLACK, "[GameCommand]"), Chars->GetChar(source->GetCharID())->GetName().c_str(), source->GetAccountLevel(), Chars->GetChar(target->GetCharID())->GetName().c_str(), target->GetAccountLevel());
    char successmsg[100];
    snprintf(successmsg, 99, "Kicked %s", Chars->GetChar(target->GetCharID())->GetName().c_str());
    successmsg[99] = '\0';
    Chat->send(source, CHAT_DIRECT, "System", successmsg);
}
Esempio n. 13
0
local void gspforces(bodyptr btab, int nbody, gsprof *gravgsp)
{
  bodyptr bp;
  real r, mr3i;

  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    r = absv(Pos(bp));
    Phi(bp) = phi_gsp(gravgsp, r);
    mr3i = mass_gsp(gravgsp, r) / rqbe(r);
    MULVS(Acc(bp), Pos(bp), -mr3i);
  }
}
Esempio n. 14
0
void snapcmacc(vector cmacc, bodyptr btab, int nbody, int woff)
{
  double wtot, cmtmp[NDIM];
  bodyptr bp;

  wtot = 0.0;
  CLRV(cmtmp);
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    wtot = wtot + Weight(bp, woff);
    ADDMULVS(cmtmp, Acc(bp), Weight(bp, woff));
  }
  DIVVS(cmacc, cmtmp, wtot);
}
Esempio n. 15
0
void  Impostor::AddSample( vcg::Point3f  p,   vcg::Point3f   n, vcg::Color4b c){
	if(box.IsIn(p)){
                const int ii = std::min<int>( int((p[0]-box.min[0])/cellsize),Gridsize()-1);
		const int jj = std::min<int>( int((p[1]-box.min[1])/cellsize),Gridsize()-1);
		const int kk = std::min<int>( int((p[2]-box.min[2])/cellsize),Gridsize()-1);

		if(n_samples.IsOn(ii,jj,kk)){
						assert(n_samples.At(ii,jj,kk) != 0);
						centroids.At(ii,jj,kk) = Acc(centroids.At(ii,jj,kk),F2C(p,ii,jj,kk),n_samples.At(ii,jj,kk));
						normals.At(ii,jj,kk)   = Acc(normals.At(ii,jj,kk),F2C_01(n),n_samples.At(ii,jj,kk));
                        colors.At(ii,jj,kk)   = Acc_0_255(colors.At(ii,jj,kk),F2C(c),n_samples.At(ii,jj,kk));
                        ++n_samples.At(ii,jj,kk);
                }
		else{
                        n_samples.At(ii,jj,kk)  = 1;
						centroids.At(ii,jj,kk)  =  F2C(p,ii,jj,kk);
                        normals.At(ii,jj,kk)    =  F2C_01(n);
                        colors.At(ii,jj,kk)     =  F2C(c);

                }

	}
}
Esempio n. 16
0
int main (void)
{
	InitUart();	//Init uart
	initInput(); //Init interrupt to start button, stop button and speed sensor	
	initMotorPWM(); //Init Fast PWM on Timer 0 (Pin PE1)
	initSpeedTimer(); //Init Timer 1 (16bit normal mode)
	initCurrentADC(); //Init ADC on PC5
	
	
	//Init speed array
	for (int i = 0; i<(SPEED_ARRAY_SIZE); i++)
	{
		speedArray[i]=65535;
	}
	
	while (1)
	{
		//Switch to stop state if something is rotten
		Protection(&Sm_State, &speed);
		
		switch (Sm_State)
		{
			case STATE_STOP:
			Stop(&motor);
			break;
				
			case STATE_RAMP_INIT:
			RampInit(&Sm_State, &motor);
			break;
				
			case STATE_RAMP_SEARCH:
			RampSearch(&Sm_State, &motor, &speed, &lastSpeed);
			break;
				
			case STATE_ACC:
			Acc(&Sm_State,&motor, speedArray);
			break;
				
			case STATE_COAST:
			Coast(&Sm_State, &motor, &speed);
			break;
				
			default:
			Sm_State = STATE_STOP;
			break;
		}
		
	}

}
Esempio n. 17
0
local void diagnostics()
{
    bodyptr p;
    real velsq, phi0;
    vector tmpv;
    matrix tmpt;
    int ndim=NDIM;

    mtot = 0.0;					/* zero total mass          */
    etot[1] = etot[2] = 0.0;			/* zero total KE and PE     */
    CLRM(keten);				/* zero ke tensor           */
    CLRM(peten);				/* zero pe tensor           */
    CLRM(amten);				/* zero am tensor           */
    CLRV(cmphase[0]);				/* zero c. of m. position   */
    CLRV(cmphase[1]);				/* zero c. of m. velocity   */
    for (p = bodytab; p < bodytab+nbody; p++) {	/* loop over all particles  */
	mtot += Mass(p);                        /*   sum particle masses    */
	DOTVP(velsq, Vel(p), Vel(p));		/*   square vel vector      */
	if (extpot) {                           /* external potential corr. */
            (*extpot)(&ndim,Pos(p),tmpv,&phi0,&tnow);
	    phi0 = Phi(p) + phi0;               /* extre correction         */
        } else
       	    phi0 = Phi(p);                      
	etot[1] += 0.5 * Mass(p) * velsq;	/*   sum current KE         */
	etot[2] += 0.5 * Mass(p) * phi0;	/*   and current PE         */
	MULVS(tmpv, Vel(p), 0.5 * Mass(p));	/*   sum 0.5 m v_i v_j      */
	OUTVP(tmpt, tmpv, Vel(p));
	ADDM(keten, keten, tmpt);
	MULVS(tmpv, Pos(p), Mass(p));		/*   sum m r_i a_j          */
	OUTVP(tmpt, tmpv, Acc(p));
	ADDM(peten, peten, tmpt);
	OUTVP(tmpt, tmpv, Vel(p));		/*   sum m r_i v_j          */
	ADDM(amten, amten, tmpt);
	MULVS(tmpv, Pos(p), Mass(p));		/*   sum cm position        */
	ADDV(cmphase[0], cmphase[0], tmpv);
	MULVS(tmpv, Vel(p), Mass(p));		/*   sum cm momentum        */
	ADDV(cmphase[1], cmphase[1], tmpv);
    }
    etot[0] = etot[1] + etot[2];                /* sum KE and PE            */
    TRANM(tmpt, amten);				/* anti-sym. AM tensor      */
    SUBM(amten, amten, tmpt);
    DIVVS(cmphase[0], cmphase[0], mtot);        /* normalize cm coords      */
    DIVVS(cmphase[1], cmphase[1], mtot);
}
Esempio n. 18
0
void hackgrav(bodyptr p, bool intree)
{
    pskip = p;					/* exclude p from f.c.      */
    SETV(pos0, PosB(p));				/* set field point          */
    phi0 = 0.0;					/* init total potential     */
    CLRV(acc0);					/* and total acceleration   */
    n2bterm = nbcterm = 0;			/* count body & cell terms  */
    skipself = FALSE;				/* watch for tree-incest    */
    treescan((nodeptr) &root->cellnode);			/* scan tree from root	    */
    if (intree && ! skipself) {			/* did tree-incest occur?   */
	if (! scanopt(options, "allow-incest"))	/*   treat as catastrophic? */
	    error("hackgrav: tree-incest detected\n");
	if (! treeincest)			/*   for the first time?    */
	    eprintf("\n[hackgrav: tree-incest detected]\n");
	treeincest = TRUE;			/*   don't repeat warning   */
    }
    Phi(p) = phi0;				/* store total potential    */
    SETV(Acc(p), acc0);				/* and acceleration         */
}
Esempio n. 19
0
local void gravsum(bodyptr p0, cellptr cptr, cellptr bptr)
{
  vector pos0, acc0;
  real phi0;
 
  SETV(pos0, Pos(p0));                          // copy position of body
  phi0 = 0.0;                                   // init total potential
  CLRV(acc0);                                   // and total acceleration
  if (usequad)                                  // if using quad moments
    sumcell(interact, cptr, pos0, &phi0, acc0); // sum cell forces w quads
  else                                          // not using quad moments
    sumnode(interact, cptr, pos0, &phi0, acc0); // sum cell forces wo quads
  sumnode(bptr, interact + actmax, pos0, &phi0, acc0);
                                                // sum forces from bodies
  Phi(p0) = phi0;                               // store total potential
  SETV(Acc(p0), acc0);                          // and total acceleration
  nfcalc++;                                     // update counters
  nbbcalc += interact + actmax - bptr;
  nbccalc += cptr - interact;
}
Esempio n. 20
0
local void diagnostics(void) {
    bodyptr p1, p2, p;
    real mp, velsq;
    vector tmpv;
    matrix tmpt;

    mtot = 0.0;					// zero total mass
    etot[1] = etot[2] = 0.0;			// zero total KE and PE
    CLRM(keten);					// zero ke tensor
    CLRM(peten);					// zero pe tensor
    CLRV(amvec);					// zero am vector
    CLRV(cmpos);					// zero c. of m. position
    CLRV(cmvel);					// zero c. of m. velocity
    p1 = bodytab + MAX(nstatic, 0);		// set dynamic body range
    p2 = bodytab + nbody + MIN(nstatic, 0);
    for (p = p1; p < p2; p++) {			// loop over body range
        mp = (testcalc ? 1.0 / (nbody - ABS(nstatic)) : Mass(p));
        // use eq. mass in testcalc
        mtot += mp;					// sum particle masses
        DOTVP(velsq, Vel(p), Vel(p));		// square vel vector
        etot[1] += 0.5 * mp * velsq;		// sum current KE
        etot[2] += (testcalc ? 1.0 : 0.5) * mp * Phi(p);
        // and PE, weighted right
        MULVS(tmpv, Vel(p), 0.5 * mp);		// sum 0.5 m v_i v_j
        OUTVP(tmpt, tmpv, Vel(p));
        ADDM(keten, keten, tmpt);
        MULVS(tmpv, Pos(p), mp);			// sum m r_i a_j
        OUTVP(tmpt, tmpv, Acc(p));
        ADDM(peten, peten, tmpt);
        CROSSVP(tmpv, Vel(p), Pos(p));		// sum angular momentum
        MULVS(tmpv, tmpv, mp);
        ADDV(amvec, amvec, tmpv);
        MULVS(tmpv, Pos(p), mp);			// sum cm position
        ADDV(cmpos, cmpos, tmpv);
        MULVS(tmpv, Vel(p), mp);			// sum cm momentum
        ADDV(cmvel, cmvel, tmpv);
    }
    etot[0] = etot[1] + etot[2];			// sum KE and PE
    DIVVS(cmpos, cmpos, mtot);        		// normalize cm coords
    DIVVS(cmvel, cmvel, mtot);
}
Esempio n. 21
0
local void diagnostics()
{
    int i;
    Body *p;
    real velsq;
    vector tmpv;
    matrix tmpt;

    mtot = 0.0;					/* zero total mass          */
    etot[1] = etot[2] = 0.0;			/* zero total KE and PE     */
    CLRM(keten);				/* zero KE tensor           */
    CLRM(peten);				/* zero PE tensor           */
    CLRM(amten);				/* zero AM tensor           */
    CLRV(cmphase[0]);				/* zero c. of m. position   */
    CLRV(cmphase[1]);				/* zero c. of m. velocity   */
    for (p = bodytab; p < bodytab+nbody; p++) {	/* loop over all bodies     */
	mtot += Mass(p);                        /*   sum body masses        */
	DOTVP(velsq, Vel(p), Vel(p));		/*   square vel vector      */
	etot[1] += 0.5 * Mass(p) * velsq;	/*   sum current KE         */
	etot[2] += 0.5 * Mass(p) * Phi(p);	/*   and current PE         */
	MULVS(tmpv, Vel(p), 0.5 * Mass(p));	/*   sum 0.5 m v_i v_j      */
	OUTVP(tmpt, tmpv, Vel(p));
	ADDM(keten, keten, tmpt);
	MULVS(tmpv, Pos(p), Mass(p));		/*   sum m r_i a_j          */
	OUTVP(tmpt, tmpv, Acc(p));
	ADDM(peten, peten, tmpt);
	OUTVP(tmpt, tmpv, Vel(p));		/*   sum m r_i v_j          */
	ADDM(amten, amten, tmpt);
	MULVS(tmpv, Pos(p), Mass(p));		/*   sum cm position        */
	ADDV(cmphase[0], cmphase[0], tmpv);
	MULVS(tmpv, Vel(p), Mass(p));		/*   sum cm momentum        */
	ADDV(cmphase[1], cmphase[1], tmpv);
    }
    etot[0] = etot[1] + etot[2];                /* sum KE and PE            */
    TRANM(tmpt, amten);				/* antisymmetrize AM tensor */
    SUBM(amten, amten, tmpt);
    DIVVS(cmphase[0], cmphase[0], mtot);        /* normalize cm coords      */
    DIVVS(cmphase[1], cmphase[1], mtot);
}
Esempio n. 22
0
local void gravsum(bodyptr p0, cellptr cptr, cellptr bptr)
{
    vector pos0, acc0;
    real phi0;
 
    SETV(pos0, Pos(p0));                        /* copy position of body    */
    phi0 = 0.0;                                 /* init total potential     */
    CLRV(acc0);                                 /* and total acceleration   */
    if (usequad)                                /* if using quad moments    */
        sumcell(interact, cptr, pos0, &phi0, acc0);
                                                /* sum cell forces w quads  */
    else                                        /* not using quad moments   */
        sumnode(interact, cptr, pos0, &phi0, acc0);
                                                /* sum cell forces wo quads */
    sumnode(bptr, interact + actlen, pos0, &phi0, acc0);
                                                /* sum forces from bodies   */
    Phi(p0) = phi0;                             /* store total potential    */
    SETV(Acc(p0), acc0);                        /* and total acceleration   */
    nfcalc++;                                   /* update counters          */
    nbbcalc += interact + actlen - bptr;
    nbccalc += cptr - interact;
}
Esempio n. 23
0
//  treeforce: supervise force calculation.
//  _______________________________________
local void treeforce(void) {
  bodyptr p1, p2, p;
  real r, mr3i;

  p1 = bodytab + MAX(nstatic, 0);		// set dynamic body range
  p2 = bodytab + nbody + MIN(nstatic, 0);
  for (p = bodytab; p < bodytab+nbody; p++)	// loop over all bodies
    Update(p) = (testcalc ? p1 <= p && p < p2 : TRUE);
						// flag bodies to update
  maketree(bodytab, nbody);			// construct tree structure
  gravcalc();					// compute current forces
  forcereport();				// print force statistics
#if defined(EXTGRAV)
  for (p = bodytab; p < bodytab+nbody; p++)	// loop over all bodies
    if (Update(p) && gravgsp != NULL) {		// update in extern field?
      r = absv(Pos(p));				// get distance from origin
      mr3i = - mass_gsp(gravgsp, r) / (r*r*r);
      ADDMULVS(Acc(p), Pos(p), mr3i);		// add extern acc and phi
      Phi(p) += phi_gsp(gravgsp, r);
    }
#endif
}
Esempio n. 24
0
void force_calc(void)
{
    real *pp, *ap;
    double cpubase;
    string *rminxstr;
    int i;
    bodyptr bp;

    tol = getdparam("tol");
    eps = getdparam("eps");
    rsize = getdparam("rsize");
    rminxstr = burststring(getparam("rmin"), ", ");
    if (xstrlen(rminxstr, sizeof(string)) < NDIM) {
	SETVS(rmin, - rsize / 2.0);
    } else
	for (i = 0; i < NDIM; i++)
	    rmin[i] = atof(rminxstr[i]);
    dprintf(0,"initial rsize: %8f    rmin: %8f  %8f  %8f\n",
	   rsize, rmin[0], rmin[1], rmin[2]);
    fcells = getdparam("fcells");
    phidata = pp = (real *) allocate(ntest * sizeof(real));
    accdata = ap = (real *) allocate(ntest * NDIM * sizeof(real));
    cpubase = cputime();
    maketree(massdata, nmass);
    cputree = cputime() - cpubase;
    dprintf(0,"  final rsize: %8f    rmin: %8f  %8f  %8f\n",
	   rsize, rmin[0], rmin[1], rmin[2]);
    cpubase = cputime();
    n2btot = nbctot = 0;
    for (bp = testdata; bp < testdata+ntest; bp++) {
	hackgrav(bp);
	*pp++ = Phi(bp);
	SETV(ap, Acc(bp));
	ap += NDIM;
	n2btot += n2bterm;
	nbctot += nbcterm;
    }
    cpufcal = cputime() - cpubase;
}
Esempio n. 25
0
//---------------------------------------------------------
//   Acc
//---------------------------------------------------------

struct Acc {
      const char* tag;        // for use in xml file
      const char* name;       // translated name
      int offset;             // semitone offset
      int centOffset;
      int sym;
      Acc(const char* t, const char* n, int o, int o2, int s)
         : tag(t), name(n), offset(o), centOffset(o2), sym(s) {}
      };

Acc accList[] = {
      Acc("none",                QT_TRANSLATE_NOOP("accidental", "none"),                0, 0, -1),
      Acc("sharp",               QT_TRANSLATE_NOOP("accidental", "sharp"),               1, 0, sharpSym),
      Acc("flat",                QT_TRANSLATE_NOOP("accidental", "flat"),               -1, 0, flatSym),
      Acc("double sharp",        QT_TRANSLATE_NOOP("accidental", "double sharp"),        2, 0, sharpsharpSym),
      Acc("double flat",         QT_TRANSLATE_NOOP("accidental", "double flat"),        -2, 0, flatflatSym),
      Acc("natural",             QT_TRANSLATE_NOOP("accidental", "natural"),             0, 0, naturalSym),

      Acc("flat-slash",          QT_TRANSLATE_NOOP("accidental", "flat-slash"),          0, 0, flatslashSym),
      Acc("flat-slash2",         QT_TRANSLATE_NOOP("accidental", "flat-slash2"),         0, 0, flatslash2Sym),
      Acc("mirrored-flat2",      QT_TRANSLATE_NOOP("accidental", "mirrored-flat2"),      0, 0, mirroredflat2Sym),
      Acc("mirrored-flat",       QT_TRANSLATE_NOOP("accidental", "mirrored-flat"),       0, 0, mirroredflatSym),
      Acc("mirrored-flat-slash", QT_TRANSLATE_NOOP("accidental", "mirrored-flat-slash"), 0, 0, mirroredflatslashSym),
      Acc("flat-flat-slash",     QT_TRANSLATE_NOOP("accidental", "flat-flat-slash"),     0, 0, flatflatslashSym),

      Acc("sharp-slash",         QT_TRANSLATE_NOOP("accidental", "sharp-slash"),         0, 0, sharpslashSym),
      Acc("sharp-slash2",        QT_TRANSLATE_NOOP("accidental", "sharp-slash2"),        0, 0, sharpslash2Sym),
Esempio n. 26
0
void print_data(bodyptr btab, int nbody, real tnow, string *fields,
		string ifmt, string rfmt)
{
    bodyptr bp;

    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	if (set_member(fields, TimeTag))
	    printf(rfmt, tnow);
	if (set_member(fields, MassTag))
	    printf(rfmt, Mass(bp));
	if (set_member(fields, PosTag)) {
	    printf(rfmt, Pos(bp)[0]);
	    printf(rfmt, Pos(bp)[1]);
	    printf(rfmt, Pos(bp)[2]);
	}
	if (set_member(fields, VelTag)) {
	    printf(rfmt, Vel(bp)[0]);
	    printf(rfmt, Vel(bp)[1]);
	    printf(rfmt, Vel(bp)[2]);
	}
	if (set_member(fields, AccTag)) {
	    printf(rfmt, Acc(bp)[0]);
	    printf(rfmt, Acc(bp)[1]);
	    printf(rfmt, Acc(bp)[2]);
	}
	if (set_member(fields, PhiTag))
	    printf(rfmt, Phi(bp));
	if (set_member(fields, SmoothTag))
	    printf(rfmt, Smooth(bp));
	if (set_member(fields, RhoTag))
	    printf(rfmt, Rho(bp));
	if (set_member(fields, EntFuncTag))
	    printf(rfmt, EntFunc(bp));
	if (set_member(fields, UinternTag))
	    printf(rfmt, Uintern(bp));
	if (set_member(fields, UdotIntTag))
	    printf(rfmt, UdotInt(bp));
        if (set_member(fields, UdotRadTag))
	    printf(rfmt, UdotRad(bp));
        if (set_member(fields, UdotVisTag))
	    printf(rfmt, UdotVis(bp));
	if (set_member(fields, TauTag))
	    printf(rfmt, Tau(bp));
	if (set_member(fields, BirthTag))
	    printf(rfmt, Birth(bp));
	if (set_member(fields, DeathTag))
	    printf(rfmt, Death(bp));
	if (set_member(fields, TypeTag))
	  printf(ifmt, (int) Type(bp));
	if (set_member(fields, KeyTag))
	    printf(ifmt, Key(bp));
	if (set_member(fields, AuxTag))
	    printf(rfmt, Aux(bp));
	if (set_member(fields, AuxVecTag)) {
	    printf(rfmt, AuxVec(bp)[0]);
	    printf(rfmt, AuxVec(bp)[1]);
	    printf(rfmt, AuxVec(bp)[2]);
	}
	printf("\n");
    }
}
Esempio n. 27
0
int main(int argc, string argv[])
{
  stream istr, ostr, gstr;
  real tnow, tgrav, eps2, tstop, dtime, tout, Mhqm, ahqm, bhqm, tol;
  real decrit, epot0, demin, demax, derms, de2avg, enow, denow;
  int nbody, ngrav;
  bodyptr btab = NULL, gtab = NULL, bp;
  string bdtags[MaxBodyFields], grtags[MaxBodyFields], *optags;
  gsprof *gravgsp = NULL;
  bool decrit_inc = FALSE;

  initparam(argv, defv);
  new_field(&EinitPBF, RealType, EinitTag);	// define initial energy field
  layout_body(bodytags, Precision, NDIM);	// layout necessary fields
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  if (! get_snap(istr, &btab, &nbody, &tnow, bdtags, TRUE))
    error("%s: can't read input snapshot\n", getprog());
  if (! (set_member(bdtags, PosTag) && set_member(bdtags, VelTag)))
    error("%s: required data missing from input snapshot\n", getprog());
#if defined(NBDGRAV)
  gstr = stropen(getparam("grav"), "r");
  get_history(gstr);
  if (! get_snap(gstr, &gtab, &ngrav, &tgrav, grtags, FALSE))
    error("%s: can't read gravity snapshot\n", getprog());
  if (! (set_member(grtags, MassTag) && set_member(grtags, PosTag)))
    error("%s: required data missing from gravity snapshot\n", getprog());
  eps2 = rsqr(getdparam("eps"));
#elif defined(GSPGRAV)
  gstr = stropen(getparam("grav"), "r");
  get_history(gstr);
  gravgsp = get_gsprof(gstr);			// read GSP for grav. field
#elif defined(HQMGRAV)
  Mhqm = getdparam("M");
  ahqm = getdparam("a");
  bhqm = getdparam("b");
  tol = getdparam("tol");
#endif
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  tstop = getdparam("tstop");
  dtime = getdparam("dtime");
  decrit = getdparam("decrit");
  optags = burststring(getparam("outputs"), ",");
#if defined(NBDGRAV)
  sumforces(btab, nbody, gtab, ngrav, eps2);	// prime the pump...
#elif defined(GSPGRAV)
  gspforces(btab, nbody, gravgsp);
#elif defined(HQMGRAV)
  hqmforces(btab, nbody, Mhqm, ahqm, bhqm, tol);
#endif

  epot0 = 0.0;					// use as energy scale
  for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
    epot0 += Phi(bp) / nbody;			// compute avg. potential
    Einit(bp) = Phi(bp) + dotvp(Vel(bp), Vel(bp)) / 2;
  }
  eprintf("[%s: initial average potential = %g]\n", getprog(), epot0);
  put_snap(ostr, &btab, &nbody, &tnow, optags);
  fflush(NULL);
  tout = tnow + getdparam("dtout");
  demin = demax = derms = 0.0;			// track maximum errors
  while (tnow < tstop) {			// enter main loop
    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
      ADDMULVS(Vel(bp), Acc(bp), 0.5 * dtime);	// step velocities by dt/2
      ADDMULVS(Pos(bp), Vel(bp), dtime);	// step positions by dt
    }
    tnow = tnow + dtime;			// step time to new value
#if defined(NBDGRAV)
    if (! getbparam("frozen"))
      if (! get_snap(gstr, &gtab, &ngrav, &tgrav, grtags, TRUE))
	error("%s: can't read gravity snapshot\n", getprog());
    sumforces(btab, nbody, gtab, ngrav, eps2);	// get new accelerations
#elif defined(GSPGRAV)
    gspforces(btab, nbody, gravgsp);
#elif defined(HQMGRAV)
    hqmforces(btab, nbody, Mhqm, ahqm, bhqm, tol);
#endif
    de2avg = 0.0;
    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
      ADDMULVS(Vel(bp), Acc(bp), 0.5 * dtime);	// step velocities by dt/2
      enow = 0.5 * dotvp(Vel(bp), Vel(bp)) + Phi(bp);
      denow = (enow - Einit(bp)) / ABS(epot0);	// compute rel. energy change
      demin = MIN(demin, denow);
      demax = MAX(demax, denow);
      de2avg += rsqr(denow) / nbody;
    }
    derms = MAX(derms, rsqrt(de2avg));
    if (demin < -decrit || demax > decrit) {
      eprintf("[%s: warning: energy error exceeds %.4e at time = %-12.8f\n"
	      " min,max,rms = %.6g,%.6g,%.6g  threshold now %.4e]\n",
	      getprog(), decrit, tnow,
	      demin, demax, rsqrt(de2avg), decrit * rsqrt(2.0));
      decrit = decrit * rsqrt(2.0);
      decrit_inc = TRUE;
    }
    if (tout <= tnow) {
      put_snap(ostr, &btab, &nbody, &tnow, optags);
      tout = tout + getdparam("dtout");
    }
    fflush(NULL);
  }
  eprintf(decrit_inc ?
	  "[%s: WARNING: energy error: min,max,rms = %.6g,%.6g,%.6g]\n" :
	  "[%s: energy error: min,max,rms = %.6g,%.6g,%.6g]\n",
	  getprog(), demin, demax, derms);
  return (0);
}
Esempio n. 28
0
bool PGameServer::HandleCharList( PClient *Client, PGameState *State, const u8 *Packet, int PacketSize )
{
  static u8 Answer[10] = {0xfe, 0x07, 0x00, 0x83, 0x86, 0, 0, 0, 0, 0};
  ConnectionTCP *Socket = Client->getTCPConn();

  if ( PacketSize > 9 && *( u16* )&Packet[3] == 0x8284 )
  {
    u8 Mode = Packet[9];

    switch ( Mode )
    {
      case 6: // request list
        return ( HandleRequestChars( Client, State, Packet ) );

      case 5: // validate name
      {
        if ( PacketSize < 31 )
          return ( false );

        // check for valid name string
        bool ValidString = false;

        for ( int i = 30; i < PacketSize; i++ )
          if ( Packet[i] == 0 )
          {
            ValidString = true;
            break;
          }

        const char *Name = ( char* ) & Packet[30];
        if ( ValidString )
        {
          ValidString = PChar::IsCharnameWellFormed( Name );
        }

        if ( ValidString )
        {
          if ( Chars->CharExist( std::string( Name ) ) )
          {
            ValidString = false;
          }
        }

        if ( ValidString )
          Answer[5] = 1; // ok
        else
          Answer[5] = 2; // 2..6 => 'char name already in use!'

        // Answer[5] = 0; // => 'unknown error'
        Socket->write( Answer, 10 );
        return ( true );
      }

      case 3: // delete char
      {
        PAccount Acc( Client->GetAccountID() );
        u8 Num = Packet[PacketSize-1];

        if ( Acc.GetID() )
        {
          u32 CharID = Acc.GetCharIdBySlot( Num );

          // Also check that char is out of game
          if (( CharID != 0 ) && ( Chars->GetChar( CharID ) == NULL ) )
          {
            char query[100];
            snprintf( query, 100, "DELETE FROM characters WHERE c_id = %d LIMIT 1", CharID );
            if ( MySQL->GameQuery( query ) )
              Console->Print( RED, BLACK, "[Notice] Char %d not deleted!", CharID );
            else
            {
              Console->Print( GREEN, BLACK, "[Info] Char %d deleted!", CharID );

              snprintf( query, 100, "DELETE FROM buddy_list WHERE bud_charid = %d", CharID );
              if ( MySQL->GameQuery( query ) )
                Console->Print( YELLOW, BLACK, "[Notice] Char %d's buddy list not removed!", CharID );

              snprintf( query, 100, "DELETE FROM genrep WHERE g_charid = %d", CharID );
              if ( MySQL->GameQuery( query ) )
                Console->Print( YELLOW, BLACK, "[Notice] Char %d's genrep list not removed!", CharID );

              snprintf( query, 100, "DELETE FROM inventory WHERE inv_charid = %d", CharID );
              if ( MySQL->GameQuery( query ) )
                Console->Print( YELLOW, BLACK, "[Notice] Char %d's inventory not removed!", CharID );

              Appartements->DeleteCharAppartements( CharID );
            }
          }
          else
            return false;
        }
        return ( true );
      }

      case 7: // create char
      {
        if ( PacketSize < 64 )
          return ( false );

        u32 Slot = * ( u32* ) & Packet[30];
        //u32 nClass =* (u32*)&Packet[34]; // Not used - indirectly redundant with Profession
        u32 Profession = * ( u32* ) & Packet[38];
        u32 Gender = * ( u32* ) & Packet[42];
        u32 Head = * ( u32* ) & Packet[46];
        u32 Torso = * ( u32* ) & Packet[50];
        u32 Legs = * ( u32* ) & Packet[54];
        u32 Faction = * ( u32* ) & Packet[58];
        u8 NameLen = Packet[62];
        u8 NZSNb = Packet[63];

        char TempName[256];
        std::strncpy( TempName, ( const char* )&Packet[64], NameLen );
        TempName[NameLen] = 0;

        Answer[5] = 2; // return error if char creation fails

        if ( PChar::IsCharnameWellFormed( TempName ) )
        {
          // check for already used char name - should not happen though
          if ( ! Chars->CharExist( std::string( TempName ) ) )
          {
            PAccount Acc( Client->GetAccountID() );
            PChar* nChar = new PChar();

            if ( nChar->CreateNewChar( Acc.GetID(), TempName, Gender, Profession, Faction,
                                       Head, Torso, Legs, NZSNb, ( const char* )&Packet[64+NameLen], Slot ) )
            {
              Answer[5] = 1; // return success
            }
            delete nChar;
          }
        }

        Socket->write( Answer, 10 );
        return ( true );
      }
    }
  }
  else
  {
    Console->Print( RED, BLACK, "[Notice] Gameserver protocol error (GS_CHARLIST): invalid packet [%04x]", *( u16* )&Packet[3] );

    return ( false );
  }

  return true;
}
Esempio n. 29
0
plotsnap()
{
    real t, *mp, *psp, *pp, *ap, *acp;
    int vismax, visnow, i, vis, icol;
    real psz, col, x, y, z;
    Body b;
    bool Qall = FALSE;

    t = (timeptr != NULL ? *timeptr : 0.0);	/* get current time value   */
    CLRV(Acc(&b));				/* zero unsupported fields  */
    Key(&b) = 0;
    visnow = vismax = 0;
    do {					/* loop painting layers     */
	visnow++;				/*   make next layer visib. */
	mp  = massptr;				/*   (re)set data pointers  */
	psp = phaseptr;
	pp  = phiptr;
	ap  = auxptr;
	acp = accptr;
	npnt = 0;
	for (i = 0; i < nbody; i++) {		/*   loop over all bodies   */
	    Mass(&b) = (mp != NULL ? *mp++ : 0.0);
						/*     set mass if supplied */
	    SETV(Pos(&b), psp);			/*     always set position  */
	    psp += NDIM;			/*     and advance p.s. ptr */
	    SETV(Vel(&b), psp);			/*     always set velocity  */
	    psp += NDIM;			/*     and advance ptr      */
	    Phi(&b) = (pp != NULL ? *pp++ : 0.0);	
	    Aux(&b) = (ap != NULL ? *ap++ : 0.0);
	    if (acp) {				
	    	SETV(Acc(&b),acp);		/*     set accel's          */	
	    	acp += NDIM;			/*     and advance ptr      */
	    }
	    					/*     set phi,aux if given */
	    vis = (*vfunc)(&b, t, i);		/*     evaluate visibility  */
	    vismax = MAX(vismax, vis);		/*     remember how hi to go*/
	    if (vis == visnow) {		/*     if body is visible   */
	        x = (*xfunc)(&b, t, i);	        /*     evaluate x,y,z coords*/
		y = (*yfunc)(&b, t, i);
		z = (*zfunc)(&b, t, i);

		psz = (*pfunc)(&b, t, i);
#define MAXCOLOR 16
#ifdef COLOR
		col = (*cfunc)(&b, t, i);
		col = (col - crange[0])/(crange[1] - crange[0]);
		icol = 1 + (MAXCOLOR - 2) * MAX(0.0, MIN(1.0, col));
		s2sci(icol);
#endif
		xpnt[npnt] = x;
		ypnt[npnt] = y;
		zpnt[npnt] = z;
		if (!Qall) {
		  s2pt1(xpnt[npnt],ypnt[npnt],zpnt[npnt], visnow);
		}
		npnt++;
	    }
	} /* i<nbody */
	if (Qall)
	  s2pt(npnt, xpnt, ypnt, zpnt, visnow);
    } while (visnow < vismax);			/* until final layer done   */
}
Esempio n. 30
0
void PCommands::doCmdban()
{
    bool SyntaxError = false;
    if(ArgC < 2)
    {
        SyntaxError = true;
    }

    if(SyntaxError == true)
    {
        Chat->send(source, CHAT_DIRECT, "Usage", "@ban <charID or nickname> <xS(econds)>/<xM(inutes)>/<xH(ours)>/<xD(ays)>");
        return;
    }

    if(IsArgNumeric(1) == true)
    {
        target = GetClientByID(GetArgInt(1));
    }
    else
    {
        char tmp_destNick[50];
        GetArgText(1, tmp_destNick, 50);
        target = GetClientByNick(tmp_destNick);
    }

    if(target == NULL) // If victim isnt found, return error
    {
        Chat->send(source, CHAT_DIRECT, "System", "No such player");
        return;
    }
    if(source->GetAccountLevel() <= target->GetAccountLevel())
    {
        char tmpMsg[200];
        snprintf(tmpMsg, 199, "Cant ban %s, target level is higher or equal to yours!", Chars->GetChar(target->GetCharID())->GetName().c_str());
        tmpMsg[199] = '\0';
        Chat->send(source, CHAT_DIRECT, "System", tmpMsg);
        return;
    }
    char tmpTimeVal[10];
    GetArgText(2, tmpTimeVal, 10);

    int loop_i = 0;
    char tmp_atoi[10];

    while(isdigit(tmpTimeVal[loop_i]) != 0 && loop_i < 10)
    {
        tmp_atoi[loop_i] = tmpTimeVal[loop_i];
        loop_i++;
    }
    char timefactor[1];
    timefactor[0] = tmpTimeVal[loop_i];
    int timevalue = atoi(tmp_atoi);
    int time_to_ban = 0;

    if(strcasecmp(timefactor, "s") == 0 )
    {
        time_to_ban = timevalue;
    }
    else if(strcasecmp(timefactor, "m") == 0 )
    {
        time_to_ban = timevalue * 60;
    }
    else if(strcasecmp(timefactor, "h") == 0 )
    {
        time_to_ban = timevalue * 60 * 60;
    }
    else if(strcasecmp(timefactor, "d") == 0 )
    {
        time_to_ban = timevalue * 60 * 60 * 24;
    }
    else
    {
        Chat->send(source, CHAT_DIRECT, "Usage", "@ban <charID or nickname> <xS(econds)>/<xM(inutes)>/<xH(ours)>/<xD(ays)>");
        return;
    }
    
    int final_bantime = std::time(NULL) + time_to_ban;
    PAccount Acc(target->GetAccountID());
    Acc.SetBannedUntilTime(final_bantime);
    Acc.Save();

    target->InitCharVanish();

    GameServer->ClientDisconnected(target);  // Now kick the player (Hes banned :) )

    char tmpMsg_success[81];
    snprintf(tmpMsg_success, 80, "Successfully banned %s", target->GetChar()->GetName().c_str());
    tmpMsg_success[80] = '\0';
    Chat->send(source, CHAT_DIRECT, "System", tmpMsg_success);
    return;
}