Change alloca to malloc

This commit is contained in:
jsalmon3 2003-05-09 04:00:46 +00:00
parent d76b424a1c
commit 1fbc43cdb7
3 changed files with 19 additions and 6 deletions

View file

@ -372,7 +372,7 @@ local int AiFindHallPlace(const Unit * worker, const UnitType * type,
destx=x=worker->X;
desty=y=worker->Y;
size=TheMap.Width*TheMap.Height/4;
points=alloca(size*sizeof(*points));
points=malloc(size*sizeof(*points));
//
// Make movement matrix. FIXME: can create smaller matrix.
@ -453,6 +453,7 @@ local int AiFindHallPlace(const Unit * worker, const UnitType * type,
if( j==nunits ) {
if( AiFindBuildingPlace2(worker,type,x,y,dx,dy,0) ) {
free(morg);
free(points);
return 1;
}
}
@ -484,6 +485,7 @@ local int AiFindHallPlace(const Unit * worker, const UnitType * type,
}
free(morg);
free(points);
return 0;
}
@ -526,7 +528,7 @@ local int AiFindLumberMillPlace(const Unit * worker, const UnitType * type,
x=worker->X;
y=worker->Y;
size=TheMap.Width*TheMap.Height/4;
points=alloca(size*sizeof(*points));
points=malloc(size*sizeof(*points));
//
// Make movement matrix.
@ -564,6 +566,7 @@ local int AiFindLumberMillPlace(const Unit * worker, const UnitType * type,
if ( ForestOnMap(x,y) ) {
if( AiFindBuildingPlace2(worker,type,x,y,dx,dy,0) ) {
free(morg);
free(points);
return 1;
}
}
@ -595,6 +598,7 @@ local int AiFindLumberMillPlace(const Unit * worker, const UnitType * type,
}
free(morg);
free(points);
return 0;
}

View file

@ -244,7 +244,7 @@ local int AiFindTarget(const Unit* unit,unsigned char* matrix,
unsigned char* m;
size=TheMap.Width*TheMap.Height/2;
points=alloca(size*sizeof(*points));
points=malloc(size*sizeof(*points));
x=unit->X;
y=unit->Y;
@ -299,6 +299,7 @@ local int AiFindTarget(const Unit* unit,unsigned char* matrix,
*dx=x;
*dy=y;
*ds=state;
free(points);
return 1;
}
@ -358,6 +359,7 @@ local int AiFindTarget(const Unit* unit,unsigned char* matrix,
}
ep=wp;
}
free(points);
return 0;
}
@ -411,7 +413,7 @@ global int AiFindWall(AiForce* force)
x=unit->X;
y=unit->Y;
size=TheMap.Width*TheMap.Height/4;
points=alloca(size*sizeof(*points));
points=malloc(size*sizeof(*points));
destx=-1;
desty=-1;
@ -477,6 +479,7 @@ global int AiFindWall(AiForce* force)
}
ep=wp;
}
free(points);
if( destx!=-1 ) {
force->State=0;

View file

@ -764,7 +764,7 @@ local Unit* AiFindGoldMine(const Unit* unit)
destx=x=unit->X;
desty=y=unit->Y;
size=TheMap.Width*TheMap.Height/4;
points=alloca(size*sizeof(*points));
points=malloc(size*sizeof(*points));
//
// Find the nearest gold depot
@ -860,6 +860,7 @@ local Unit* AiFindGoldMine(const Unit* unit)
}
*m=22;
} else { // no goal take the first
free(points);
return mine;
}
}
@ -884,6 +885,7 @@ local Unit* AiFindGoldMine(const Unit* unit)
// Take best of this frame, if any.
//
if( bestd!=99999 ) {
free(points);
return bestmine;
}
@ -898,6 +900,7 @@ local Unit* AiFindGoldMine(const Unit* unit)
DebugLevel3Fn("no mine in sight-range\n");
free(points);
return NoUnitP;
}
@ -1066,7 +1069,7 @@ local int AiHarvest(Unit * unit)
x=unit->X;
y=unit->Y;
size=TheMap.Width*TheMap.Height/4;
points=alloca(size*sizeof(*points));
points=malloc(size*sizeof(*points));
//
// Find the nearest wood depot
@ -1123,6 +1126,7 @@ local int AiHarvest(Unit * unit)
DebugCheck(unit->Type!=UnitTypeHumanWorker
&& unit->Type!=UnitTypeOrcWorker);
CommandHarvest(unit,x,y,FlushCommands);
free(points);
return 1;
}
}
@ -1150,6 +1154,7 @@ local int AiHarvest(Unit * unit)
DebugCheck(unit->Type!=UnitTypeHumanWorker
&& unit->Type!=UnitTypeOrcWorker);
CommandHarvest(unit, bestx, besty,FlushCommands);
free(points);
return 1;
}
@ -1165,6 +1170,7 @@ local int AiHarvest(Unit * unit)
DebugLevel0Fn("no wood in range by %s(%d,%d)\n"
_C_ unit->Type->Ident _C_ unit->X _C_ unit->Y);
free(points);
return 0;
}