05.01.2015, 03:03
Idk if this code works (actually it should) because i wasnt able to test it, it removes the "arts" limit by using a vector and a map; try it out:
pawn Код:
struct a_vectors
{
std::map<int, int> arts_array;
};
std::vector<a_vectors*> vectors;
cell AMX_NATIVE_CALL DestroyArt(AMX* amx, cell* params)
{
for (auto& i : vectors.at(params[1])->arts_array)
{
if (i.second != -1)
{
g_Invoke->callNative(&PAWN::DestroyObject, i.second);
}
}
vectors.erase((vectors.begin() + params[1])-1);
return 1;
}
//CreateArt(path, sX, sY, sZ, aX, aY, aZ, dist, type)
cell AMX_NATIVE_CALL CreateArt(AMX* amx, cell* params)
{
int cre_f = 0;
PNG_Struct picture;
char *text = new char;
amx_StrParam(amx, params[1],text);
int open_result = picture.Init(text);
free(text);
if(open_result == 1)
{
logprintf("FAILED to create art: can't load PNG picture");
return -1;
}
if(open_result == -1)
{
logprintf("FAILED to create art: PNG isn't 24-bit type");
return -1;
}
float pos[3] = {amx_ctof(params[2]), amx_ctof(params[3]), amx_ctof(params[4])};
float ang[3] = {amx_ctof(params[5]), amx_ctof(params[6]), amx_ctof(params[7])};
double ra[3] = {atr(ang[0]), atr(ang[1]), atr(ang[2])};
float dist = amx_ctof(params[8]);
//just few simple formulas ^_^
double up[3] = {sin(ra[1])*cos(ra[2]) + sin(ra[0])*sin(ra[2])*cos(ra[1]), sin(ra[2])*sin(ra[1]) - sin(ra[0])*cos(ra[1])*cos(ra[2]), -cos(ra[0])*cos(ra[1])};
double right[3] = {-sin(ra[2])*cos(ra[0]), cos(ra[0])*cos(ra[2]), -sin(ra[0])};
float ws, hs; cell oid; cell type = params[9];
switch (type)
{
case 0: oid = 19464; ws = 5.875f; hs = 5.075f; break;
case 2: oid = 2814; ws = 0.51f; hs = 0.51f; break;
default: oid = 19372; ws = 3.18f; hs = 3.48f; break;
}
int blockx = (int)floor(float(picture.width()) / 15 + 0.999);
int blocky = (int)floor(float(picture.height()) / 15 + 0.999);
if(blockx*blocky > 1000)
{
logprintf("FAILED to create art: too large image");
return 10;
}
unsigned int *temp_block = (unsigned int*)malloc(15*15*sizeof(unsigned int));
a_vectors* vectores = new a_vectors();
for (int i = 0; i < blockx; i++)
{
for(int j = 0; j < blocky; j++)
{
memset(temp_block, 0, sizeof(unsigned int)*15*15);
CutBlock15(picture, temp_block, i, j);
int index= i+j*blockx;
float start[3] = { (i - blockx/2.0)*ws*right[0] + (j - blocky/2.0)*(hs)*up[0] + pos[0],
(i - blockx/2.0)*ws*right[1] + (j - blocky/2.0)*(hs)*up[1] + pos[1],
(i - blockx/2.0)*ws*right[2] + (j - blocky/2.0)*(hs)*up[2] + pos[2]};
int cur_w = CLIP(picture.width() - i*15,0,15);
int cur_h = CLIP(picture.height() - j*15,0,15);
char colors[4096] = {0};
BuildString(colors, temp_block, cur_w, cur_h);
cell cobid = 0;
//let's create an object! [format: oid, sX, sY, sZ, aX, aY, aZ, dist]
float add_rot = 0;
if (oid == 2814)
{
add_rot = -94.65;
cobid = g_Invoke->callNative(&PAWN::CreateObject, oid, start[0], start[1], start[2], ang[0], ang[1] + add_rot, 180 + ang[2], dist);
vectores->arts_array.emplace(1, cobid);
g_Invoke->callNative(&PAWN::SetObjectMaterialText, cobid, colors, 0, 140, "Webdings", 35, 0, 0, 0, 0);
g_Invoke->callNative(&PAWN::SetObjectMaterial, cobid, 1, -1, "none", "none", 1);
}
}
}
free(temp_block);
vectors.push_back(vectores);
delete vectores;
return vectors.size()-1;
}