Vec2i PlacePlayer( Map *map, const PlayerData *p, const Vec2i firstPos, const bool pumpEvents) { NetMsgActorAdd aa = NetMsgActorAdd_init_default; aa.Id = ActorsGetFreeIndex(); aa.Health = p->Char.maxHealth; aa.PlayerId = p->playerIndex; if (IsPVP(gCampaign.Entry.Mode)) { // In a PVP mode, always place players apart aa.FullPos = PlaceActor(&gMap); } else if (gMission.missionData->Type == MAPTYPE_STATIC && !Vec2iIsZero(gMission.missionData->u.Static.Start)) { // place players near the start point Vec2i startPoint = Vec2iReal2Full(Vec2iCenterOfTile( gMission.missionData->u.Static.Start)); aa.FullPos = PlaceActorNear(map, startPoint, true); } else if (gConfig.Interface.Splitscreen == SPLITSCREEN_NEVER && !Vec2iIsZero(firstPos)) { // If never split screen, try to place players near the first player aa.FullPos = PlaceActorNear(map, firstPos, true); } else { aa.FullPos = PlaceActor(map); } GameEvent e = GameEventNew(GAME_EVENT_ACTOR_ADD); e.u.ActorAdd = aa; GameEventsEnqueue(&gGameEvents, e); if (pumpEvents) { // Process the events that actually place the players HandleGameEvents(&gGameEvents, NULL, NULL, NULL, &gEventHandlers); } return Vec2iNew(aa.FullPos.x, aa.FullPos.y); }
bool CreateInitialPile() { /* Initial conditions are required for most experiments. The initial conditions file should contain a rectangular matrix consisting of columns for x,y,z,vx,vy,vz and one row per actor. The number of rows in the ic file will supersede the rubble_size line in the ini file and RUBBLE_SIZE will be replaced. The initial conditions file should be in the run directory and has the run base name with an extension .ic. */ // peek into the ic file to find header lines. char icfile[255]; sprintf(icfile,"%s\\%s\\%s.ic",_getcwd(NULL,0),gRunBaseName,gRunBaseName); ifstream fp(icfile); if (fp.fail()){cout<<"ERROR:could not open initial conditions file\a"<<endl; return false;} char line[255]; unsigned int headlines=0; while (fp.good()){ fp.getline(line,255); headlines++; if (strcmp(line,"---END HEADER---")==0) break; } if (fp.eof()) headlines=0; // explicit header/data separator not found. assume no header. fp.close(); // read initial conditions into a temporary holder. expected size is nb_grains-by-6. vector<vector<float>*>* ics=RSReadMatrixFromFile(icfile,headlines); if (ics==NULL){cout<<"ERROR:failed to read initial conditions"<<endl; return false;} if ((ics->at(0)->size())!=6){cout<<"ERROR:wrong number of initial conditions per actor"<<endl; return false;} RUBBLE_SIZE=ics->size(); // replacing number possibly specified in ini file. // place an actor with appropriate initial conditions for (int k=0; k<RUBBLE_SIZE; k++){ NxVec3 pos(ics->at(k)->at(0),ics->at(k)->at(1),ics->at(k)->at(2)); NxVec3 vel(ics->at(k)->at(3),ics->at(k)->at(4),ics->at(k)->at(5)); bool success=PlaceActor(pos,vel,k); if (!success){cout<<"ERROR:actor placement failed, possibly bad IC\a"<<endl; return false;} } // all actors placed. get rid of temp holder and return. delete ics; return true; }