//__ \subsection{eventAttacked(victim, attacker)} //__ An event that is run when an object belonging to the script's controlling player is //__ attacked. The attacker parameter may be either a structure or a droid. bool triggerEventAttacked(BASE_OBJECT *psVictim, BASE_OBJECT *psAttacker, int lastHit) { if (!psAttacker) { // do not fire off this event if there is no attacker -- nothing do respond to // (FIXME -- consider this carefully) return false; } // throttle the event for performance if (gameTime - lastHit < ATTACK_THROTTLE) { return false; } for (int i = 0; i < scripts.size(); ++i) { QScriptEngine *engine = scripts.at(i); int player = engine->globalObject().property("me").toInt32(); if (player == psVictim->player) { QScriptValueList args; args += convMax(psVictim, engine); args += convMax(psAttacker, engine); callFunction(engine, "eventAttacked", args); } } return true; }
//__ \subsection{eventObjectSeen(viewer, seen)} //__ An event that is run whenever an object goes from not seen to seen. //__ First parameter is \emph{game object} doing the seeing, the next the game //__ object being seen. bool triggerEventSeen(BASE_OBJECT *psViewer, BASE_OBJECT *psSeen) { for (int i = 0; i < scripts.size() && psSeen && psViewer; ++i) { QScriptEngine *engine = scripts.at(i); int me = engine->globalObject().property("me").toInt32(); if (me == psViewer->player) { QScriptValueList args; args += convMax(psViewer, engine); args += convMax(psSeen, engine); callFunction(engine, "eventObjectSeen", args); } } return true; }
//__ \subsection{eventGroupLoss(object, group id, new size)} //__ An event that is run whenever a group becomes empty. Input parameter //__ is the about to be killed object, the group's id, and the new group size. // Since groups are entities local to one context, we do not iterate over them here. bool triggerEventGroupLoss(BASE_OBJECT *psObj, int group, int size, QScriptEngine *engine) { QScriptValueList args; args += convMax(psObj, engine); args += QScriptValue(group); args += QScriptValue(size); callFunction(engine, "eventGroupLoss", args); return true; }
void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[] ) { int *ns, ms[3], nDims, d, m, r, s; float *A, *B, p; mxClassID id; char type[1024]; // error checking on arguments if(nrhs!=4) mexErrMsgTxt("Four inputs required."); if(nlhs > 1) mexErrMsgTxt("One output expected."); nDims = mxGetNumberOfDimensions(prhs[1]); id = mxGetClassID(prhs[1]); ns = (int*) mxGetDimensions(prhs[1]); d = (nDims == 3) ? ns[2] : 1; m = (ns[0] < ns[1]) ? ns[0] : ns[1]; if( (nDims!=2 && nDims!=3) || id!=mxSINGLE_CLASS || m<4 ) mexErrMsgTxt("A must be a 4x4 or bigger 2D or 3D float array."); // extract inputs if(mxGetString(prhs[0],type,1024)) mexErrMsgTxt("Failed to get type."); A = (float*) mxGetData(prhs[1]); p = (float) mxGetScalar(prhs[2]); r = (int) mxGetScalar(prhs[2]); s = (int) mxGetScalar(prhs[3]); if( s<1 ) mexErrMsgTxt("Invalid sampling value s"); if( r<0 ) mexErrMsgTxt("Invalid radius r"); // create output array (w/o initializing to 0) ms[0]=ns[0]/s; ms[1]=ns[1]/s; ms[2]=d; B = (float*) mxMalloc(ms[0]*ms[1]*d*sizeof(float)); plhs[0] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS, mxREAL); mxSetData(plhs[0], B); mxSetDimensions(plhs[0],(mwSize*)ms,nDims); // perform appropriate type of convolution if(!strcmp(type,"convBox")) { if(r>=m/2) mexErrMsgTxt("mask larger than image (r too large)"); convBox( A, B, ns[0], ns[1], d, r, s ); } else if(!strcmp(type,"convTri")) { if(r>=m/2) mexErrMsgTxt("mask larger than image (r too large)"); convTri( A, B, ns[0], ns[1], d, r, s ); } else if(!strcmp(type,"conv11")) { if( s>2 ) mexErrMsgTxt("conv11 can sample by at most s=2"); conv11( A, B, ns[0], ns[1], d, r, s ); } else if(!strcmp(type,"convTri1")) { if( s>2 ) mexErrMsgTxt("convTri1 can sample by at most s=2"); convTri1( A, B, ns[0], ns[1], d, p, s ); } else if(!strcmp(type,"convMax")) { if( s>1 ) mexErrMsgTxt("convMax cannot sample"); convMax( A, B, ns[0], ns[1], d, r ); } else { mexErrMsgTxt("Invalid type."); } }
//__ \subsection{eventDestroyed(object)} //__ An event that is run whenever an object is destroyed for the owning player. //__ Careful passing the parameter object around, since it is about to vanish! bool triggerEventDestroyed(BASE_OBJECT *psVictim) { for (int i = 0; i < scripts.size() && psVictim; ++i) { QScriptEngine *engine = scripts.at(i); int me = engine->globalObject().property("me").toInt32(); if (me == psVictim->player) { QScriptValueList args; args += convMax(psVictim, engine); callFunction(engine, "eventDestroyed", args); } } return true; }
//__ \subsection{eventObjectTransfer(object, from)} //__ An event that is run whenever an object is transferred between players, //__ for example due to a Nexus Link weapon. The event is called after the //__ object has been transferred, so the target player is in object.player. //__ The event is called for both players. bool triggerEventObjectTransfer(BASE_OBJECT *psObj, int from) { for (int i = 0; i < scripts.size() && psObj; ++i) { QScriptEngine *engine = scripts.at(i); int me = engine->globalObject().property("me").toInt32(); if (me == psObj->player || me == from) { QScriptValueList args; args += convMax(psObj, engine); args += QScriptValue(from); callFunction(engine, "eventObjectTransfer", args); } } return true; }
void scriptRemoveObject(const BASE_OBJECT *psObj) { for (QHash<int, bindNode>::iterator i = bindings.find(psObj->id); i != bindings.end(); i++) { int id = i.key(); bindNode node = i.value(); BASE_OBJECT *psObj = IdToPointer(id, node.player); if (psObj && !psObj->died) { QScriptValueList args; args += convMax(psObj, node.engine); callFunction(node.engine, node.funcName, args); } bindings.erase(i); } }