JBoolean
JDirInfo::ForceUpdate()
{
	if (JDirectoryExists(*itsCWD))
		{
		Broadcast(ContentsWillBeUpdated());

		const JError err = BuildInfo();
		if (err.OK())
			{
			return kJTrue;
			}
		}

	if (itsSwitchIfInvalidFlag)
		{
		JString path;
		if (!JGetHomeDirectory(&path) || !OKToCreate(path))
			{
			path = JGetRootDirectory();
			}
		GoTo(path);
		}
	else
		{
		itsIsValidFlag    = kJFalse;
		itsIsWritableFlag = kJFalse;
		itsDirEntries->CleanOut();
		itsVisEntries->CleanOut();
		itsAlphaEntries->CleanOut();
		}

	return kJFalse;
}
JError
JDirInfo::GoTo
	(
	const JCharacter* origDirName
	)
{
	JString dirName;
	if (JStringEmpty(origDirName) ||
		!JConvertToAbsolutePath(origDirName, NULL, &dirName))
		{
		return JBadPath(origDirName);
		}

	if (JSameDirEntry(dirName, *itsCWD))
		{
		Update();
		return JNoError();
		}
	JAppendDirSeparator(&dirName);

	const JString origCWD = *itsCWD;

	*itsCWD = dirName;
	const JError err = BuildInfo();
	if (err.OK())
		{
		Broadcast(PathChanged());
		}
	else
		{
		*itsCWD = origCWD;
		}

	return err;
}
示例#3
0
void CBuilding::ForcedMove(const float3& newPos, int facing) {
	buildFacing = facing;
	pos = helper->Pos2BuildPos(BuildInfo(unitDef, newPos, buildFacing));
	speed = ZeroVector;
	heading = GetHeadingFromFacing(buildFacing);
	frontdir = GetVectorFromHeading(heading);
	CUnit::ForcedMove(pos);
	unitLoader.FlattenGround(this);
}
示例#4
0
void CBuilding::ForcedMove(const float3& newPos) {
	heading = GetHeadingFromFacing(buildFacing);
	frontdir = GetVectorFromHeading(heading);

	SetVelocity(ZeroVector);
	Move(CGameHelper::Pos2BuildPos(BuildInfo(unitDef, newPos, buildFacing), true), false);
	UpdateMidAndAimPos();

	CUnit::ForcedMove(pos);

	unitLoader->FlattenGround(this);
}
示例#5
0
void CBuilding::ForcedMove(const float3& newPos) {
	// heading might have changed if building was dropped from transport
	// (always needs to be axis-aligned because yardmaps are not rotated)
	heading = GetHeadingFromFacing(buildFacing);

	UpdateDirVectors(false);
	SetVelocity(ZeroVector);

	// update quadfield, etc.
	CUnit::ForcedMove(CGameHelper::Pos2BuildPos(BuildInfo(unitDef, newPos, buildFacing), true));

	unitLoader->FlattenGround(this);
}
示例#6
0
JDirInfo::JDirInfo
	(
	const JCharacter* dirName
	)
	:
	JContainer()
{
	AllocateCWD(dirName);

	itsIsValidFlag         = kJTrue;	// see assert() at end of this function
	itsSwitchIfInvalidFlag = kJFalse;
	itsIsWritableFlag      = kJFalse;
	itsModTime             = 0;
	itsStatusTime          = 0;

	itsShowFilesFlag   = kJTrue;		// remember to update ResetCSFFilters()
	itsShowDirsFlag    = kJTrue;
	itsShowHiddenFlag  = kJFalse;
	itsShowVCSDirsFlag = kJTrue;
	itsShowOthersFlag  = kJFalse;

	itsNameRegex           = NULL;
	itsOwnsNameRegexFlag   = kJFalse;
	itsInvertNameRegexFlag = kJFalse;
	itsFilterDirsFlag      = kJFalse;
	itsPermFilter          = NULL;
	itsContentRegex        = NULL;
	itsPG                  = NULL;

	itsDirEntries = new JPtrArray<JDirEntry>(JPtrArrayT::kDeleteAll);
	assert( itsDirEntries != NULL);
	itsDirEntries->SetCompareFunction(JDirEntry::CompareNames);
	itsDirEntries->SetSortOrder(JOrderedSetT::kSortAscending);

	itsVisEntries = new JPtrArray<JDirEntry>(JPtrArrayT::kForgetAll);
	assert( itsVisEntries != NULL);

	itsAlphaEntries = new JPtrArray<JDirEntry>(JPtrArrayT::kForgetAll);
	assert( itsAlphaEntries != NULL);
	itsAlphaEntries->SetCompareFunction(JDirEntry::CompareNames);
	itsAlphaEntries->SetSortOrder(JOrderedSetT::kSortAscending);

	InstallOrderedSet(itsVisEntries);

	const JError err = BuildInfo();
	assert_ok( err );
}
示例#7
0
nuiWidgetInfo::nuiWidgetInfo(nuiWidget* pTarget)
: nuiComposite(),
mWISink(this)
{
  mpTarget = NULL;
  mNeedUpdate = false;
  mpTimer = new nuiTimer(1.0/15.0);
  mWISink.Connect(mpTimer->Tick, &nuiWidgetInfo::OnTimerTick);
  mpTimer->Start(false);
  
  mpDummy = NULL;
  mpInfos = NULL;
  
  mpName = NULL;
  mpClass = NULL;
  mpCType = NULL;
#ifndef __GNUC__
  mpCRawType = NULL;
#endif
  mpIdealRect = NULL;
  mpUserRect = NULL;
  mpHasUserSize = NULL;
  mpHasUserPos = NULL;
  mpRect = NULL;
  mpNeedLayout = NULL;
  mpNeedRender = NULL;
  mpNeedSelfRedraw = NULL;
  mpNeedIdealRectCalc = NULL;
  mpGlobalRect = NULL;
  mpMatrix = NULL;
  mpPropertyGrid = NULL;
  mpAttributeGrid = NULL;
  mpProxy = NULL;
  mpPainterInspector = NULL;
  
  BuildInfo();
  
  SetTarget(pTarget);
}
JDirInfo::JDirInfo
	(
	const JDirInfo&		source,
	const JCharacter*	dirName
	)
	:
	JContainer(source)
{
	AllocateCWD(dirName);

	itsIsValidFlag         = kJTrue;			// see assert() at end of this function
	itsSwitchIfInvalidFlag = kJFalse;
	itsIsWritableFlag      = kJFalse;
	itsModTime             = 0;
	itsStatusTime          = 0;

	JDirInfoX(source);
	PrivateCopySettings(source);
	InstallOrderedSet(itsVisEntries);

	const JError err = BuildInfo();
	assert_ok( err );
}
示例#9
0
float3 CGameHelper::Pos2BuildPos(const float3& pos, const UnitDef* ud)
{
    return Pos2BuildPos(BuildInfo(ud,pos,0));
}
void CSpawnScript::Update()
{
	switch(gs->frameNum){
	case 0:
		LoadSpawns();

		const std::string startUnit0 = sideParser.GetStartUnit(0);

		if (startUnit0.length() == 0) {
			throw content_error ("Unable to load a startUnit for the first side");
		}

		MapParser mapParser(stupidGlobalMapname);
		if (!mapParser.IsValid()) {
			throw content_error("MapParser: " + mapParser.GetErrorLog());
		}
		float3 startPos0(1000.0f, 80.0f, 1000.0f);
		mapParser.GetStartPos(0, startPos0);

		// Set the TEAM0 startpos as spawnpos if we're supposed to be
		// autonomous, load the commander for the player if not.
		if (autonomous) {
			spawnPos.push_back(startPos0);
		} else {
			unitLoader.LoadUnit(startUnit0, startPos0, 0, false, 0, NULL);
		}

		// load the start positions for teams 1 - 3
		for (int teamID = 1; teamID <= 3; teamID++) {
			float3 sp(1000.0f, 80.0f, 1000.0f);
			mapParser.GetStartPos(teamID, sp);
			spawnPos.push_back(sp);
		}
	}

	if(!spawns.empty()){
		while(curSpawn->frame+frameOffset<gs->frameNum){
			int num = gs->randInt() % spawnPos.size();
			int team = autonomous ? (num & 1) : 1;
			float3 pos;
			float dist=200;
			CFeature* feature;
			do {
				pos=spawnPos[num]+gs->randVector()*dist;
				dist*=1.05f;
			} while (dist < 500 && uh->TestUnitBuildSquare(BuildInfo(curSpawn->name,pos,0),feature,team) != 2);

			// Ignore unit if it really doesn't fit.
			// (within 18 tries, 200*1.05f^18 < 500 < 200*1.05f^19)
			if (dist < 500) {
				CUnit* u = unitLoader.LoadUnit(curSpawn->name, pos, team, false, 0, NULL);

				Unit unit;
				unit.id=u->id;
				unit.target=-1;
				unit.team=team;
				myUnits.push_back(unit);
				if(myUnits.size()==1)
					curUnit=myUnits.begin();
			}

			++curSpawn;
			if(curSpawn==spawns.end()){
				curSpawn=spawns.begin();
				frameOffset+=spawns.back().frame;
			}
		}
	}

	if(!myUnits.empty() && !gs->Team(1 - curUnit->team)->units.empty()) {
		if(uh->units[curUnit->id]){
			if(curUnit->target<0 || uh->units[curUnit->target]==0){
				// We can't rely on the ordering of units in a std::set<CUnit*>,
				// because they're sorted on memory address. Hence we must first
				// build a set of IDs and then pick an unit from that.
				// This guarantees the script doesn't desync in multiplayer games.
				int num = gs->randInt() % gs->Team(1 - curUnit->team)->units.size();
				std::set<int> unitids;
				CUnitSet* tu = &gs->Team(1 - curUnit->team)->units;
				for (CUnitSet::iterator u = tu->begin(); u != tu->end(); ++u)
					unitids.insert((*u)->id);
				std::set<int>::iterator ui = unitids.begin();
				for(int a=0;a<num;++a)
					++ui;
				curUnit->target=(*ui);
				curUnit->lastTargetPos.x=-500;
			}
			float3 pos=uh->units[curUnit->target]->pos;
			if(pos.distance2D(curUnit->lastTargetPos)>100){
				curUnit->lastTargetPos=pos;
				Command c;
				c.id=CMD_PATROL;
				c.options=0;
				c.params.push_back(pos.x);
				c.params.push_back(pos.y);
				c.params.push_back(pos.z);
				uh->units[curUnit->id]->commandAI->GiveCommand(c);
			}
			curUnit++;
		} else {
			curUnit=myUnits.erase(curUnit);
		}
		if(curUnit==myUnits.end())
			curUnit=myUnits.begin();
	}
}
// Gradually calculate the extra texture based on updateTextureState:
//   updateTextureState < 50:   Calculate the texture color values and copy them in a buffer
//   updateTextureState >= 50:  Copy the buffer into a texture
//   updateTextureState = 57:   Reset to 0 and restart updating
bool CBaseGroundDrawer::UpdateExtraTexture()
{
	if(drawMode == drawNormal)
		return true;

	unsigned short* myLos=loshandler->losMap[gu->myAllyTeam];
	unsigned short* myAirLos=loshandler->airLosMap[gu->myAllyTeam];
	if(updateTextureState<50){
		int starty;
		int endy;
		if(highResInfoTexWanted){
			starty=updateTextureState*gs->mapy/50;
			endy=(updateTextureState+1)*gs->mapy/50;
		} else {
			starty=updateTextureState*gs->hmapy/50;
			endy=(updateTextureState+1)*gs->hmapy/50;
		}

		switch(drawMode) {
		case drawPath:{
			if(selectedUnits.selectedUnits.empty() || !(*selectedUnits.selectedUnits.begin())->unitDef->movedata)
				return true;

			MoveData *md=(*selectedUnits.selectedUnits.begin())->unitDef->movedata;

			for(int y=starty;y<endy;++y){
				for(int x=0;x<gs->hmapx;++x){
					int a=y*gs->pwr2mapx/2+x;

					float m;
					//todo: fix for new gui
					if(guihandler->inCommand>0 && guihandler->inCommand<guihandler->commands.size() && guihandler->commands[guihandler->inCommand].type==CMDTYPE_ICON_BUILDING){
						if(!loshandler->InLos(float3(x*16+8,0,y*16+8),gu->myAllyTeam)){
							m=0.25f;
						}else{
							UnitDef *unitdef = unitDefHandler->GetUnitByID(-guihandler->commands[guihandler->inCommand].id);

							CFeature* f;
							if(uh->TestUnitBuildSquare(BuildInfo(unitdef,float3(x*16+8,0,y*16+8),guihandler->buildFacing),f,gu->myAllyTeam))
								m=1;
							else
								m=0;
							if(f && m)
								m=0.5f;
						}

					} else {
						m=md->moveMath->SpeedMod(*md, x*2,y*2);
						if(gs->cheatEnabled && md->moveMath->IsBlocked2(*md, x*2+1, y*2+1) & (CMoveMath::BLOCK_STRUCTURE | CMoveMath::BLOCK_TERRAIN))
							m=0;
						m=min(1.0f,(float)sqrt(m));
					}
					infoTexMem[a*4+0]=255-int(m*255.0f);
					infoTexMem[a*4+1]=int(m*255.0f);
					infoTexMem[a*4+2]=0;
				}
			}
			break;}
		case drawMetal:
			for(int y=starty;y<endy;++y){
				for(int x=0;x<gs->hmapx;++x){
					int a=y*gs->pwr2mapx/2+x;
					if(myAirLos[((y*2)>>loshandler->airMipLevel)*loshandler->airSizeX+((x*2)>>loshandler->airMipLevel)]) {
						float extractDepth = extractDepthMap[y*gs->hmapx+x];
						infoTexMem[a*4]=(unsigned char)min(255.0f,(float)sqrt(sqrt(extractDepth))*900);
					} else
						infoTexMem[a*4]=0;
					infoTexMem[a*4+1]=(extraTexPal[extraTex[y*gs->hmapx+x]*3+1]);
					infoTexMem[a*4+2]=(extraTexPal[extraTex[y*gs->hmapx+x]*3+2]);
				}
			}
			break;
		case drawHeight:
			extraTexPal=readmap->heightLinePal;
			for(int y=starty;y<endy;++y){
				for(int x=0;x<gs->mapx;++x){
					int a=y*gs->pwr2mapx+x;
					float height=readmap->centerheightmap[y*gs->mapx+x];
					unsigned char value=(unsigned char)(height*8);
					infoTexMem[a*4]=64+(extraTexPal[value*3]>>1);
					infoTexMem[a*4+1]=64+(extraTexPal[value*3+1]>>1);
					infoTexMem[a*4+2]=64+(extraTexPal[value*3+2]>>1);
				}
			}
			break;
		case drawLos:
			for(int y=starty;y<endy;++y){
				for(int x=0;x<gs->hmapx;++x){
					int a=y*(gs->pwr2mapx>>1)+x;
					int inRadar=0;
					int inJam=0;
					if (drawRadarAndJammer){
						if(radarhandler->radarMaps[gu->myAllyTeam][y/(RADAR_SIZE/2)*radarhandler->xsize+x/(RADAR_SIZE/2)])
							inRadar=50;
						if(radarhandler->jammerMaps[gu->myAllyTeam][y/(RADAR_SIZE/2)*radarhandler->xsize+x/(RADAR_SIZE/2)])
							inJam=50;
					}
					if(myLos[((y*2)>>loshandler->losMipLevel)*loshandler->losSizeX+((x*2)>>loshandler->losMipLevel)]!=0){
						infoTexMem[a*4]=128+inJam;
						infoTexMem[a*4+1]=128+inRadar;
						infoTexMem[a*4+2]=128;
					} else if(myAirLos[((y*2)>>loshandler->airMipLevel)*loshandler->airSizeX+((x*2)>>loshandler->airMipLevel)]!=0){
						infoTexMem[a*4]=96+inJam;
						infoTexMem[a*4+1]=96+inRadar;
						infoTexMem[a*4+2]=96;
					} else {
						infoTexMem[a*4]=64+inJam;
						infoTexMem[a*4+1]=64+inRadar;
						infoTexMem[a*4+2]=64;
					}
				}