Projectile::Projectile(const char *pname, INIFile *weapini)
{
    char *iname = weapini->readString(pname, "image");
    SHPImage* temp;
    imagenum = 0;
    rotates = false;
    rotationimgs = 0;
    if( iname != NULL ) {
        imagenum = pc::imagepool->size()<<16;
        try {
            temp = new SHPImage(iname, mapscaleq);
        } catch (ImageNotFound&) {
            throw 0;
        }
        //  printf("Projectile %s has %s which has %i\n",pname,iname,temp->getNumImg());
        pc::imagepool->push_back(temp);
        delete[] iname;

        if (weapini->readInt(pname,"rotates",0) != 0) {
            rotationimgs = temp->getNumImg();
            rotates = true;
        }
    }
    AA = false;
    AG = true;
    high = false;
    inacurate = false;
}
Beispiel #2
0
Projectile::Projectile(string pname, ProjectileDataList* data, vector<SHPImage*>* imagePool)
{
	// Get the Data of this projectile
	ProjectileData* lProjectileData = data->getData(pname);
		
	// Assign the Data
	this->lnkProjectileData = lProjectileData;
	
	
	// Get image name
	string lImage = this->lnkProjectileData->getImage();
	
	// Load the image in the pool 
	if (lImage!= "none"){
		
		SHPImage* temp = 0;
		imagenum = 0;
		
		imagenum = imagePool->size()<<16;
		try
		{
			lImage += ".shp";
			temp = new SHPImage(lImage.c_str(), -1);
		}
		catch (ImageNotFound&)
		{
			logger->error("Image %s not found during loading of %s projectile\n", lImage.c_str(), pname.c_str());
		}
		// stack the image
		imagePool->push_back(temp);
		
		
		
		if (this->lnkProjectileData->getRotates()!= 0)
		{
			if (temp != 0)
			{
				rotationimgs = temp->getNumImg();
			}
			else
			{
				rotationimgs = 0;
			}
		}

	}
}
Warhead::Warhead(const char *whname, INIFile *weapini)
{
    char *tmpname;
    SHPImage* temp;

    spread = weapini->readInt(whname, "spread", 0);
    tmpname = weapini->readString(whname, "explosionimage");
    explosionimage = 0;
    if( tmpname != NULL ) {
        explosionimage = pc::imagepool->size()<<16;
        try {
            temp = new SHPImage(tmpname, mapscaleq);
        } catch (ImageNotFound&) {
            throw 0;
        }
        pc::imagepool->push_back(temp);
        delete[] tmpname;
    }
    explosionanimsteps = temp->getNumImg();
    explosionsound = weapini->readString(whname, "explosionsound");
    infantrydeath = 0;
    walls = (weapini->readInt(whname, "walls",0) != 0);
    trees = false;
    //blastradius = 0;
    tmpname = weapini->readString(whname, "versus");
    versus[0] = 100;
    versus[1] = 100;
    versus[2] = 100;
    versus[3] = 100;
    versus[4] = 100;
    if (tmpname != NULL) {
        sscanf(tmpname,"%u,%u,%u,%u,%u",&versus[0],&versus[1],
               &versus[2],&versus[3],&versus[4]);
    }
    delete[] tmpname;
    //for (int i=0;i<5;++i)
    //    fprintf(stderr,"%s\t%i\t%i\n",whname,i,versus[i]);
}
Beispiel #4
0
SDL_Surface *DropDownListBox::ReadShpImage (char *Name, int ImageNumb, Uint8 palnum)
{
	SDL_Surface	*image;
	SDL_Surface *shadow;
	SHPImage	*TempPic;

	try {
		TempPic = new SHPImage(Name, -1);
	} catch (ImageNotFound&) {
		printf ("%s line %i: Image not found\n", __FILE__, __LINE__);
		return NULL;
	}

	TempPic->getImage(ImageNumb, &image, &shadow, palnum);

	delete TempPic;

	SDL_FreeSurface(shadow);

	SDL_SetColorKey(image,SDL_SRCCOLORKEY, 0xffffff);

	return image;
}
Weapon::Weapon(const char* wname) : name(wname)
{
    char *pname, *whname, *faname, *faimage;
    map<string, Projectile*>::iterator projentry;
    map<string, Warhead*>::iterator wheadentry;
    INIFile *weapini = p::weappool->getWeaponsINI();
    SHPImage* fireanimtemp;
    Uint8 additional, i;
    string projname, warheadname;
    string weapname = (string)wname;
    string::iterator p = weapname.begin();
    while (p!=weapname.end())
        *p++ = toupper(*p);

    pname = weapini->readString(wname, "projectile");
    if( pname == NULL ) {
        logger->warning("Unable to find projectile for weapon \"%s\" in inifile..\n", wname);
        throw 0;
    }
    projname = (string)pname;
    p = projname.begin();
    while (p!=projname.end())
        *p++ = toupper(*p);

    projentry = p::weappool->projectilepool.find(projname);
    if( projentry == p::weappool->projectilepool.end() ) {
        try {
            projectile = new Projectile(pname, weapini);
        } catch(int) {
            logger->warning("Unable to find projectile \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", pname, wname);
            delete[] pname;
            throw 0;
        }
        p::weappool->projectilepool[projname] = projectile;
    } else {
        projectile = projentry->second;
    }
    delete[] pname;

    whname = weapini->readString(wname, "warhead");
    if( whname == NULL ) {
        logger->warning("Unable to find warhead for weapon \"%s\" in inifile..\n", wname);
        throw 0;
    }
    warheadname = (string)whname;
    transform(warheadname.begin(),warheadname.end(), warheadname.begin(), toupper);
    wheadentry = p::weappool->warheadpool.find(warheadname);
    if( wheadentry == p::weappool->warheadpool.end() ) {
        try {
            whead = new Warhead(whname, weapini);
        } catch (int) {
            logger->warning("Unable to find Warhead \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", whname, wname);
            delete[] whname;
            throw 0;
        }
        p::weappool->warheadpool[warheadname] = whead;
    } else {
        whead = wheadentry->second;
    }
    delete[] whname;

    speed      = weapini->readInt(wname, "speed", 100);
    range      = weapini->readInt(wname, "range", 1);
    reloadtime = weapini->readInt(wname, "reloadtime", 5);
    damage     = weapini->readInt(wname, "damage", 10);
    burst      = weapini->readInt(wname, "burst", 1);
    heatseek   = (weapini->readInt(wname, "heatseek", 0) != 0);
    fireimage  = pc::imagepool->size()<<16;
    // pc::imagepool->push_back(new SHPImage("minigun.shp", mapscaleq));
    firesound  = weapini->readString(wname, "firesound");
    chargesound = weapini->readString(wname, "chargesound");
    fuel       = weapini->readInt(wname, "fuel", 0);
    seekfuel   = weapini->readInt(wname, "seekfuel", 0);

    faname = weapini->readString(wname, "fireimage", "none");
    if (strcasecmp(faname,"none") == 0) {
        delete[] faname;
        numfireimages = 0;
        numfiredirections = 1;
        fireimage = 0;
    } else {
        additional = (Uint8)weapini->readInt(faname,"additional",0);
        faimage = weapini->readString(faname, "image", "minigun.shp");
        try {
            fireanimtemp = new SHPImage(faimage, mapscaleq);
        } catch (ImageNotFound&) {
            throw 0;
        }
        delete[] faimage;
        faimage = NULL;
        numfireimages = fireanimtemp->getNumImg();
        numfiredirections = weapini->readInt(faname, "directions", 1);
        if (numfiredirections == 0) {
            numfiredirections = 1;
        }
        fireimages = new Uint32[numfiredirections];
        fireimages[0] = fireimage;
        pc::imagepool->push_back(fireanimtemp);
        if (additional != 0) {
            char* tmpname = new char[12];
            for (i=2;i<=additional;++i) {
                sprintf(tmpname,"image%i",i);
                faimage = weapini->readString(faname, tmpname, "");
                if (strcasecmp(faimage,"") != 0) {
                    try {
                        fireanimtemp = new SHPImage(faimage, mapscaleq);
                    } catch (ImageNotFound&) {
                        throw 0;
                    }
                    fireimages[i-1]=(pc::imagepool->size()<<16);
                    numfireimages += fireanimtemp->getNumImg();
                    pc::imagepool->push_back(fireanimtemp);
                } else {
                    fireimages[i] = 0;
                    logger->warning("%s was empty in [%s]\n",tmpname,faname);
                }
                delete[] faimage;
                faimage = NULL;
            }
            delete[] tmpname;
        } else if (numfiredirections != 1) {
            for (i=1;i<numfiredirections;++i) {
                fireimages[i] = fireimage+i*(numfireimages/numfiredirections);
            }
        }
        delete[] faname;
    }
}
Beispiel #6
0
UnitType::UnitType(const string& typeName, INIFile* unitini) :
    UnitOrStructureType(),
    shpnums(0),
    c4(false)
{
    string tname = typeName;
    SHPImage* shpimage = 0;

    string shpname;

    Uint32 shpnum;
    Uint32 tmpspeed;


    // Ensure that there is a section in the ini file
    if (unitini->isSection(typeName) == false)
    {
        // Log it
        Logger::getInstance()->Error("%s line %i: Unknown type: " + typeName);

        shpnums = 0;
        shptnum = 0;
        return;
    }

    // Set the internal name
    this->setName(typeName);



    string tmp = unitini->readString(tname, "prerequisites", "");
    Split(prereqs, tmp, ',');

    unittype = unitini->readInt(tname, "unittype", 0);
    if (0 == unittype)
    {
        Logger::getInstance()->Warning("No unit type specified for '" + tname + "'");
    }

    numlayers = unitini->readInt(tname, "layers", 1);

    shpnums = new Uint32[numlayers];
    shptnum = new Uint16[numlayers];

    // get string with this name
    shpname = string(typeName);
    shpname += ".shp";
    // @todo TRY THIS !!!
    try
    {
        shpimage = new SHPImage(shpname.c_str(), -1);
    } catch (ImageNotFound&) {
        Logger::getInstance()->Error("Image not found: '" + shpname + "'");
        numlayers = 0;
        return;
    }
    shpnum = static_cast<Uint32>(pc::imagepool->size());
    pc::imagepool->push_back(shpimage);
    shpnum <<= 16;

    for(unsigned int i = 0; i < numlayers; i++)
    {
        // get layer offsets from inifile
        //shpnums[i] = pc::imagepool->size();
        shpnums[i] = shpnum;
        shptnum[i] = shpimage->getNumImg();
        shpnum += 32;
    }
    // @todo REFACTOR TO IT !!!
     /*
    // Load the SHPimage
    Uint32 numSHP = pc::imgcache->loadImage(shpname.c_str());
    for (i = 0; i < numlayers; i++)
    {
        // get layer offsets from inifile
        shpnums[i] = numSHP;
        shptnum[i] = pc::imgcache->getImage(numSHP).NumbImages;
        shpnum += 32;
    }
*/
    is_infantry = false;

    //buildlevel = unitini->readInt(tname, "buildlevel", 99);
    techLevel = unitini->readInt(tname, "TechLevel", -1);

    tmp = unitini->readString(tname, "owners");
    Split(owners, tmp, ',');

    if (unittype == 1)
    {
        is_infantry = true;
    }

    tmpspeed = unitini->readInt(tname, "speed");
    if (is_infantry)
    {
        if (tmpspeed == 0x7fffffff)
        {
            speed = 4; // default for infantry is slower
            movemod = 1;
        }
        else
        {
            speed = (tmpspeed>4) ? 2 : (7-tmpspeed);
            movemod = (tmpspeed>4) ? (tmpspeed-4) : 1;
        }
    }
    else
    {
        if (tmpspeed == 0x7fffffff)
        {
            speed = 2;
            movemod = 1;
        }
        else
        {
            speed = (tmpspeed>4) ? 2 : (7-tmpspeed);
            movemod = (tmpspeed>4) ? (tmpspeed-4) : 1;
        }
    }


    string talkmode;
    if (is_infantry)
    {
        talkmode = unitini->readString(tname, "talkback", "Generic");
        sight = unitini->readInt(tname, "sight", 3);
    }
    else
    {
        talkmode = unitini->readString(tname, "talkback", "Generic-Vehicle");
        sight = unitini->readInt(tname, "sight", 5);
    }
    talkback = p::uspool->getTalkback(talkmode.c_str());
    
    maxhealth = unitini->readInt(tname, "health", 50);

    setCost(unitini->readInt(tname, "cost", 0));
    if (0 == getCost())
    {
        Logger::getInstance()->Error(tname + "' has no cost, setting to 1");
        setCost(1);
    }

    // Set the turn speed
    try
    {
        tmpspeed = unitini->readInt(tname, "turnspeed");

        // ok
        turnspeed = (tmpspeed>4)?2:(7-tmpspeed);
        turnmod = (tmpspeed>4)?(tmpspeed-4):1;
    }
    catch(...)
    {
        turnspeed = 2;
        turnmod = 1;
    }

    if (is_infantry)
    {
        //      size = 1;
        offset = 0;
    }
    else
    {
        //size = shpimage->getWidth();
        offset = (shpimage->getWidth()-24)>>1;
    }

    
    doubleowned = (unitini->readYesNo(tname, "DoubleOwned", 0) == 1);
    

    // Read primary weapon
    string priStr = unitini->readString(tname, "Primary", "");
    if (priStr == "")
    {
        this->setPrimaryWeapon(0);
    }
    else
    {
        this->setPrimaryWeapon(p::weappool->getWeapon(priStr.c_str()));
    }
        
    //
    string secStr = unitini->readString(tname, "Secondary", "");
    if (secStr == "")
    {
        this->setSecondaryWeapon(0);
    }
    else
    {
        this->setSecondaryWeapon(p::weappool->getWeapon(secStr.c_str()));
    }
    
    
    string deploytarget = unitini->readString(tname, "deploysto", "");
    if (deploytarget.size() > 0)
    {
        deployable = true;
        deploytype = p::uspool->getStructureTypeByName(deploytarget.c_str());
    }
    else
    {
        deployable = false;
        deploytype = 0;
    }
    pipcolour = unitini->readInt(tname, "pipcolour", 0);

    // Read the armor
    string charArmor = unitini->readString(tname, "Armour", "");
    if (charArmor == "")
        armour = AC_none;
    else
    {
        if (string(charArmor) == "none")
            armour = AC_none;
        else if (string(charArmor) == "wood")
            armour = AC_wood;
        else if (string(charArmor) == "light")
            armour = AC_light;
        else if (string(charArmor) == "heavy")
            armour = AC_heavy;
        else if (string(charArmor) == "concrete")
            armour = AC_concrete;
    }
    
    
    valid = true;

#ifdef LOOPEND_TURN
    animinfo.loopend = unitini->readInt(typeName, "loopend", 31);
    animinfo.loopend2 = unitini->readInt(typeName, "loopend2", 0);

    animinfo.animspeed = unitini->readInt(typeName, "animspeed", 3);
    animinfo.animspeed = abs(animinfo.animspeed);
    animinfo.animspeed = (animinfo.animspeed>1 ? animinfo.animspeed : 2);
    animinfo.animdelay = unitini->readInt(typeName, "delay", 0);

    animinfo.animtype = unitini->readInt(typeName, "animtype", 0);
    animinfo.sectype = unitini->readInt(typeName, "sectype", 0);

    animinfo.dmgoff = unitini->readInt(typeName, "dmgoff", ((shptnum[0]-1)>>1));
#endif

    // Read the C4 caract
    this->c4 = (unitini->readYesNo(typeName, "C4", 0) == 1);

    // Read the Infiltrate caracteristic
    this->infiltrate = (unitini->readYesNo(typeName, "Infiltrate", 0) == 1);
}