NamedScript void UpdateShopAutoList() { ArrayCreate(&Player.AutoSellList, "Auto-Sell", 128, sizeof(ItemInfoPtr)); ArrayCreate(&Player.AutoStoreList, "Auto-Store", 128, sizeof(ItemInfoPtr)); for (int i = 0; i < ItemCategories; i++) { for (int j = 0; j < ItemMax[i]; j++) { if (Player.AutoSellList.Position == Player.AutoSellList.Size) ArrayResize(&Player.AutoSellList); if (Player.AutoStoreList.Position == Player.AutoStoreList.Size) ArrayResize(&Player.AutoStoreList); if (Player.ItemAutoMode[i][j] == AT_SELL) { ItemInfoPtr Item = &ItemData[i][j]; LogMessage(StrParam("Sell List Position: %i Sell List Size: %i", Player.AutoSellList.Position, Player.AutoSellList.Size), LOG_DEBUG); LogMessage(StrParam("Adding %S to auto-sell @ %p", ItemData[i][j].Name, Item), LOG_DEBUG); ((ItemInfoPtr *)Player.AutoSellList.Data)[Player.AutoSellList.Position++] = Item; } else if (Player.ItemAutoMode[i][j] == AT_STORE) { ItemInfoPtr Item = &ItemData[i][j]; LogMessage(StrParam("Store List Position: %i Store List Size: %i", Player.AutoStoreList.Position, Player.AutoStoreList.Size), LOG_DEBUG); LogMessage(StrParam("Adding %S to auto-store @ %p", ItemData[i][j].Name, Item), LOG_DEBUG); ((ItemInfoPtr *)Player.AutoStoreList.Data)[Player.AutoStoreList.Position++] = Item; } // LogMessage(StrParam("Completed Item #%i, %S", j, ItemData[i][j].Name), LOG_DEBUG); } } LogMessage("Completed AutoUpdateShopList", LOG_DEBUG); }
//NOTE: Test me. void AnimalArrayInsert(struct Array* _Array, struct Animal* _Animal) { const struct Population* _PopType = _Animal->PopType; struct Animal* _TempAn = NULL; int _FoundType = 0; if(_Array->Size >= _Array->TblSize) ArrayResize(_Array); if(_Array->Size == 0) { _Array->Table[0] = _Animal; ++_Array->Size; return; } for(int i = 0; i < _Array->Size; ++i) { _TempAn = (struct Animal*) _Array->Table[i]; if(_TempAn->PopType == _PopType) { _FoundType = 1; } else if(_FoundType == 1) { _Array->Table[i] = _Animal; _Animal = _TempAn; _FoundType = 2; } } if(_FoundType == 1) { _Array->Table[_Array->Size++] = _Animal; } else if(_FoundType == 2) { ++_Array->Size; } }
void ArraySet_S(struct Array* Array, void* Data, uint32_t Idx) { while(Array->Size >= Idx) { ArrayResize(Array); } if(Array->Table[Idx] != NULL) ++Array->Size; Array->Table[Idx] = Data; }
//----------------------------------------------------------------------------------------------- void calc_alpha_volatility (double Input_Array[], int param_counted_bars) { // Calculate alpha index of vols[] // using least squares algorithm. // Adapted by E Farrell 2013 // source supplied by J Blackledge 2012 // initialize R & T ArrayResize(T,Lookback); ArrayResize(R,Lookback); // set up the T array for(int t = 1; t <= Lookback; t++) T[t-1] = MathLog(t); for(int i = phase_lookback; i >= 0; i--) { // Create autocorrelation array for R, // based on "Input_Array" BuildRArray (Lookback, i, Input_Array); // Calculate alpha index // of volatility levy_vol[i] = -GetHurstExponent(Lookback, T, R); if (DEBUG == 1) { // Output array values to Expert Log //Print("\t levy_vol[\t", DoubleToStr(i,0), "\t] \t", DoubleToStr(levy_vol[i],6)); file_result = FileWrite (file_handle, "levy_vol", i, levy_vol[i]); } } }
void calc_regression (double y[], int n) { // initialise array // to hold x values double x[]; ArrayResize (x, n); int i; double SUMx, SUMy, SUMxy, SUMxx; double slope, y_intercept; SUMx = 0; SUMy = 0; SUMxy = 0; SUMxx = 0; for (i=0; i < n; i++) { x[i] = i; SUMx = SUMx + x[i]; SUMy = SUMy + y[i]; SUMxy = SUMxy + x[i]*y[i]; SUMxx = SUMxx + x[i]*x[i]; } // formula for regression line slope = (SUMx*SUMy - n*SUMxy) / (SUMx*SUMx - n*SUMxx); y_intercept = (SUMy - slope*SUMx) / n; // create the regression line // using the formula from above for (i=0; i < n; i++) { least_squares_line[i] = slope*x[i] + y_intercept; } }
void ArrayInsert_S(struct Array* Array, void* Data) { if(Array->Size >= Array->TblSize) { ArrayResize(Array); } Array->Table[Array->Size++] = Data; }